Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
robisim74 committed Sep 2, 2016
1 parent 678ba0d commit 9e38a0d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 52 deletions.
42 changes: 28 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Because it is only a branch of Angular 2, the goal is the complete integration w

Get the changelog by [releases](https://github.com/robisim74/angular2localization/releases).

Angular version: 2.0.0-rc.5.
Angular version: 2.0.0-rc.6.

## Angular 2 i18n solutions
| **Angular 2 (work-in)** _Native_ | **ng2-translate** _External library_ | **angular2localization** _External library_
Expand All @@ -19,9 +19,9 @@ _Messages_ | Html attribute, Message ID, ? | impure pipe | pure pipe
_File formats_ | XLIFF, XMB/XTB, ? | static JSON | static JSON and via Web API
_New bootstrap (when language changes)_ | yes | no | no
_Getting the translation in component class_ | ? | yes | yes
_Default locale_ | ? | no | yes
_Numbers_ | pure pipe via Intl (only for en-US) | - | pure pipe via Intl
_Dates_ | pure pipe via Intl (only for en-US) | - | pure pipe via Intl
_Default locale_ | yes | no | yes
_Numbers_ | pure pipe via Intl | - | pure pipe via Intl
_Dates_ | pure pipe via Intl | - | pure pipe via Intl
_Validation_ | - | - | numbers validation

## Installing
Expand All @@ -33,15 +33,29 @@ npm install --save angular2localization
## Loading
### Using SystemJS configuration
```JavaScript
var map = {
...
'angular2localization': 'node_modules'
};

var packages = {
...
'angular2localization/angular2localization': { main: '/bundles/angular2localization.umd.min.js', defaultExtension: 'js' }
};
System.config({
paths: {
'npm:': 'node_modules/'
},
map: {
app: 'app',
// angular bundles
...
// other libraries
'rxjs': 'npm:rxjs',
'angular2localization': 'npm:angular2localization/bundles/angular2localization.umd.min.js'
},
packages: {
app: {
format: 'cjs',
main: './main.js',
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
}
}
});
```
#### Angular-CLI
See [Angular-CLI settings](https://github.com/robisim74/angular2localization/blob/master/doc/spec.md#Appendix%20A).
Expand All @@ -51,7 +65,7 @@ See [Angular-CLI settings](https://github.com/robisim74/angular2localization/blo
### Via webpack
Import the library in your `vendor` file after Angular 2 imports:
```TypeScript
import 'angular2localization/angular2localization';
import 'angular2localization';
```

### Plain JavaScript
Expand Down
51 changes: 13 additions & 38 deletions doc/spec.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Angular 2 Localization library specification
Library version: 0.9.0
Library version: 0.10.0

## Table of contents
* [1 The library structure](#1)
Expand Down Expand Up @@ -83,7 +83,7 @@ For example, to get the translation, add in the template:
```
and include in the component:
```TypeScript
import { LocalizationService } from 'angular2localization/angular2localization';
import { LocalizationService } from 'angular2localization';
...
export class AppComponent {

Expand Down Expand Up @@ -137,7 +137,7 @@ For example, to get the local date, add in the template:
```
and include in the component:
```TypeScript
import { LocaleService } from 'angular2localization/angular2localization';
import { LocaleService } from 'angular2localization';
...
export class AppComponent {

Expand Down Expand Up @@ -201,7 +201,7 @@ get currency(): string {
### <a name="2.3"/>2.3 Quick use
If you want, you can avoid including `get lang()`, `get defaultLocale()` or `get currency()` by extending the `Locale` superclass in the components:
```TypeScript
import { Locale, LocaleService, LocalizationService } from 'angular2localization/angular2localization';
import { Locale, LocaleService, LocalizationService } from 'angular2localization';
...
export class AppComponent extends Locale {

Expand Down Expand Up @@ -247,7 +247,7 @@ If you need to get the translation in component class, [LocalizationService](#7.
* `translateAsync(key: string): Observable<string>;`

But if you need to get the translation when the selected language changes, you must subscribe to the following event:
* `translationChanged: EventEmitter<boolean>;`
* `translationChanged: EventEmitter<any>;`

For example:
```TypeScript
Expand Down Expand Up @@ -280,7 +280,7 @@ Import the modules you need in `AppModule`:
```TypeScript
import { HttpModule } from '@angular/http';
// Angular 2 Localization.
import { LocaleModule, LocalizationModule } from 'angular2localization/angular2localization';
import { LocaleModule, LocalizationModule } from 'angular2localization';

@NgModule({
imports: [
Expand All @@ -298,7 +298,7 @@ export class AppModule { }
### <a name="3.1"/>3.1 First scenario: you need to localize dates and numbers, but no messages
Add in the bootstrap component `AppComponent` in order to access the data of location from anywhere in the application:
```TypeScript
import { LocaleService } from 'angular2localization/angular2localization';
import { LocaleService } from 'angular2localization';
...
export class AppComponent {

Expand All @@ -318,7 +318,7 @@ export class AppComponent {
### <a name="3.2"/>3.2 Second scenario: you only need to translate messages
Add in the bootstrap component `AppComponent` in order to access the data of location from anywhere in the application:
```TypeScript
import { LocaleService, LocalizationService } from 'angular2localization/angular2localization';
import { LocaleService, LocalizationService } from 'angular2localization';
...
export class AppComponent {

Expand Down Expand Up @@ -472,7 +472,7 @@ For example, if you have a feature module:
imports: [
...
LocaleModule, // LocaleService is singleton.
LocalizationModule.forRoot() // New instance of LocalizationService.
LocalizationModule.forChild() // New instance of LocalizationService.
],
declarations: [ListComponent]
})
Expand Down Expand Up @@ -588,9 +588,9 @@ import { Component } from '@angular/core';
// FormBuilder with formControl.
import { FormBuilder, FormGroup, AbstractControl } from '@angular/forms';
// Services.
import { Locale, LocaleService, LocalizationService, LocaleParser } from 'angular2localization/angular2localization';
import { Locale, LocaleService, LocalizationService, LocaleParser } from 'angular2localization';
// Directives for FormBuilder with formControl.
import { validateLocaleNumber } from 'angular2localization/angular2localization';
import { validateLocaleNumber } from 'angular2localization';

@Component({
templateUrl: './app/validation.component.html'
Expand Down Expand Up @@ -666,7 +666,7 @@ Method | Function
### <a name="7.2"/>7.2 LocalizationService
Property | Value
---------- | -----
`translationChanged: EventEmitter<boolean>;` | Output for event translation changed
`translationChanged: EventEmitter<any>;` | Output for event translation changed
`languageCode: string;` | The language code for the service
`loadingMode: LoadingMode;` | The loading mode for the service
`serviceState: ServiceState;` | The service state
Expand Down Expand Up @@ -706,31 +706,6 @@ npm install --save angular2localization
### angular-cli@webpack
No need to set up anything, just import in your code.
### angular-cli
Add the library to `angular-cli-build.js` file to `vendorNpmFiles` array:
```JavaScript
module.exports = function(defaults) {
return new Angular2App(defaults, {
vendorNpmFiles: [
...
'angular2localization/**/*.+(js|js.map)'
]
});
};
```
Then configure SystemJS mappings to know where to look for the library: move to `src` folder and add to `system.config.js` file:
```JavaScript
/** Map relative paths to URLs. */
const map: any = {
'angular2localization': 'vendor/angular2localization'
};

/** User packages configuration. */
const packages: any = {
'angular2localization': { format: 'cjs', defaultExtension: 'js' }
};
```
## <a name="Appendix B"/>Appendix B - Using Ionic 2 up to 2.0.0-beta.11 & Angular 2.0.0-rc.4
Install the library:
```Shell
Expand All @@ -741,7 +716,7 @@ Initialize the services of the library in `app.ts` files, when the platform is r
...
import { HTTP_PROVIDERS } from '@angular/http';

import { LocaleService, LocalizationService } from 'angular2localization/angular2localization';
import { LocaleService, LocalizationService } from 'angular2localization';

@Component({
...
Expand Down

0 comments on commit 9e38a0d

Please sign in to comment.