Skip to content

Commit 20a9edf

Browse files
committed
Update version & documentation
1 parent 7eea4f1 commit 20a9edf

File tree

2 files changed

+40
-75
lines changed

2 files changed

+40
-75
lines changed

doc/spec.md

Lines changed: 39 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Angular 2 Localization library specification
2-
Library version: 1.1.0
2+
Library version: 1.1.1
33

44
## Table of contents
55
* [1 The library structure](#1)
@@ -12,10 +12,9 @@ Library version: 1.1.0
1212
* [2.2.2 Decimals](#2.2.2)
1313
* [2.2.3 Percentages](#2.2.3)
1414
* [2.2.4 Currencies](#2.2.4)
15-
* [2.3 Quick use](#2.3)
16-
* [2.4 List](#2.4)
17-
* [2.4.1 Sorting & search](#2.4.1)
18-
* [2.5 Getting the translation in component class](#2.5)
15+
* [2.3 List](#2.3)
16+
* [2.3.1 Sorting & search](#2.3.1)
17+
* [2.4 Getting the translation in component class](#2.4)
1918
* [3 Scenarios](#3)
2019
* [3.1 First scenario: you need to localize dates and numbers, but no messages](#3.1)
2120
* [3.2 Second scenario: you only need to translate messages](#3.2)
@@ -25,8 +24,8 @@ Library version: 1.1.0
2524
* [3.2.4 Special characters](#3.2.4)
2625
* [3.2.5 Changing language](#3.2.5)
2726
* [3.3 Third scenario: you need to translate messages, dates and numbers](#3.3)
28-
* [3.3.1 Using locale as language](#3.3.1)
29-
* [3.3.2 Changing locale and currency](#3.3.2)
27+
* [3.3.1 Changing locale and currency](#3.3.1)
28+
* [3.3.2 Option: using locale as language](#3.3.2)
3029
* [4 Default locale](#4)
3130
* [4.1 Storage](#4.1)
3231
* [5 Lazy routing](#5)
@@ -56,7 +55,7 @@ Module | Class | Type | Contract
5655
`LocaleModule` | `LocaleNumberValidator` | Directive | Validates a number by default locale
5756
`LocalizationModule` | `LocalizationService` | Service | Gets the translation data and performs operations
5857
`LocalizationModule` | `TranslatePipe` | Pipe | Translates messages
59-
| `Locale` | Service | Provides the methods for localization
58+
| `Locale` | Service | Provides the updates for localization
6059
| `LocaleParser` | Service | Parses a string and returns a number by default locale
6160
| `IntlSupport` | Service | Provides the methods to check if Intl is supported
6261

@@ -91,22 +90,16 @@ If you want to use parameters:
9190
```
9291
Then include in the component:
9392
```TypeScript
94-
import { LocalizationService } from 'angular2localization';
93+
import { Locale, LocalizationService } from 'angular2localization';
9594
...
96-
export class AppComponent {
95+
export class HomeComponent extends Locale {
9796

9897
constructor(public localization: LocalizationService) {
98+
super(null, localization);
9999
...
100100
}
101101

102-
// Gets the language code for the LocalizationService.
103-
get lang(): string {
104-
105-
return this.localization.languageCode;
106-
107-
}
108-
109-
}
102+
}
110103
```
111104

112105
#### <a name="2.1.1"/>2.1.1 Gender
@@ -145,22 +138,16 @@ For example, to get the local date, add in the template:
145138
```
146139
and include in the component:
147140
```TypeScript
148-
import { LocaleService } from 'angular2localization';
141+
import { Locale, LocaleService, LocalizationService } from 'angular2localization';
149142
...
150-
export class AppComponent {
143+
export class HomeComponent extends Locale {
151144

152-
constructor(public locale: LocaleService) {
145+
constructor(public locale: LocaleService, public localization: LocalizationService) {
146+
super(locale, localization);
153147
...
154148
}
155149

156-
// Gets the default locale.
157-
get defaultLocale(): string {
158-
159-
return this.locale.getDefaultLocale();
160-
161-
}
162-
163-
}
150+
}
164151
```
165152

166153
#### <a name="2.2.2"/>2.2.2 Decimals
@@ -174,7 +161,7 @@ For example, to get the local decimal, add in the template:
174161
```Html
175162
{{ pi | localeDecimal:defaultLocale:'1.5-5' }}
176163
```
177-
and include `get defaultLocale()` in the component.
164+
and extend `Locale` class in the component.
178165

179166
#### <a name="2.2.3"/>2.2.3 Percentages
180167
```
@@ -184,7 +171,7 @@ For example, to get the local percentage, add in the template:
184171
```Html
185172
{{ a | localePercent:defaultLocale:'1.1-1' }}
186173
```
187-
and include `get defaultLocale()` in the component.
174+
and extend `Locale` class in the component.
188175

189176
#### <a name="2.2.4"/>2.2.4 Currencies
190177
```
@@ -196,32 +183,9 @@ For example, to get the local currency, add in the template:
196183
```Html
197184
{{ b | localeCurrency:defaultLocale:currency:true:'1.2-2' }}
198185
```
199-
and include `get defaultLocale()` and `get currency()` in the component:
200-
```TypeScript
201-
// Gets the current currency.
202-
get currency(): string {
203-
204-
return this.locale.getCurrentCurrency();
205-
206-
}
207-
```
186+
and extend `Locale` class in the component.
208187

209-
### <a name="2.3"/>2.3 Quick use
210-
If you want, you can avoid including `get lang()`, `get defaultLocale()` or `get currency()` by extending the `Locale` superclass in the components:
211-
```TypeScript
212-
import { Locale, LocaleService, LocalizationService } from 'angular2localization';
213-
...
214-
export class AppComponent extends Locale {
215-
216-
constructor(public locale: LocaleService, public localization: LocalizationService) {
217-
super(locale, localization);
218-
...
219-
}
220-
221-
}
222-
```
223-
224-
### <a name="2.4"/>2.4 List
188+
### <a name="2.3"/>2.3 List
225189
Now you can localize a list simply. For example:
226190
```Html
227191
<md-card *ngFor="let item of DATA">
@@ -238,7 +202,7 @@ Now you can localize a list simply. For example:
238202
</md-card>
239203
```
240204

241-
#### <a name="2.4.1"/>2.4.1 Sorting & search
205+
#### <a name="2.3.1"/>2.3.1 Sorting & search
242206
[LocalizationService](#7.2) has the following methods for sorting and filtering a list by locales:
243207
* `sort(list: Array<any>, keyName: any, order?: string, extension?: string, options?: any): Array<any>;`
244208
* `sortAsync(list: Array<any>, keyName: any, order?: string, extension?: string, options?: any): Observable<Array<any>>;`
@@ -249,13 +213,13 @@ These methods use the [Intl.Collator](https://developer.mozilla.org/en-US/docs/W
249213

250214
*N.B. This feature is not supported by all browsers, even with the use of `Intl.js`.*
251215

252-
### <a name="2.5"/>2.5 Getting the translation in component class
216+
### <a name="2.4"/>2.4 Getting the translation in component class
253217
If you need to get the translation in component class, [LocalizationService](#7.2) has the following methods:
254218
* `translate(key: string, args?: any, lang?: string): string;`
255219
* `translateAsync(key: string, args?: any, lang?: string): Observable<string>;`
256220

257221
But if you need to get the translation when the selected language changes, you must subscribe to the following event:
258-
* `translationChanged: EventEmitter<any>;`
222+
* `translationChanged: EventEmitter<string>;`
259223

260224
For example:
261225
```TypeScript
@@ -437,7 +401,20 @@ this.locale.definePreferredLocale('en', 'US', 30);
437401
this.locale.definePreferredCurrency('USD');
438402
```
439403

440-
#### <a name="3.3.1"/>3.3.1 Using locale as language
404+
#### <a name="3.3.1"/>3.3.1 Changing locale and currency
405+
To change locale at runtime, call the following method:
406+
```TypeScript
407+
this.locale.setCurrentLocale(language, country);
408+
```
409+
where `language` is the two-letter or three-letter code of the new language (ISO 639) and `country` is the two-letter, uppercase code of the new country (ISO 3166).
410+
411+
To change currency at runtime, call the following method:
412+
```TypeScript
413+
this.locale.setCurrentCurrency(currency);
414+
```
415+
where `currency` is the three-letter code of the new currency (ISO 4217).
416+
417+
#### <a name="3.3.2"/>3.3.2 Option: using locale as language
441418
You can use different countries for the same language, calling `useLocaleAsLanguage` method at initialization of the `LocalizationService`:
442419
```TypeScript
443420
// Adds a new language (ISO 639 two-letter or three-letter code).
@@ -462,19 +439,6 @@ locale-ar-EG.json
462439
...
463440
```
464441

465-
#### <a name="3.3.2"/>3.3.2 Changing locale and currency
466-
To change locale at runtime, call the following method:
467-
```TypeScript
468-
this.locale.setCurrentLocale(language, country);
469-
```
470-
where `language` is the two-letter or three-letter code of the new language (ISO 639) and `country` is the two-letter, uppercase code of the new country (ISO 3166).
471-
472-
To change currency at runtime, call the following method:
473-
```TypeScript
474-
this.locale.setCurrentCurrency(currency);
475-
```
476-
where `currency` is the three-letter code of the new currency (ISO 4217).
477-
478442
## <a name="4"/>4 Default locale
479443
The default locale contains the current language and culture. It consists of:
480444
* `language code`: the two-letter or three-letter code of the language (ISO 639);
@@ -700,6 +664,7 @@ Finally, import `ReactiveFormsModule` in `AppModule`.
700664
### <a name="7.1"/>7.1 LocaleService
701665
Property | Value
702666
---------- | -----
667+
`defaultLocaleChanged: EventEmitter<string>;` | Output for event default locale changed
703668
`languageCodeChanged: EventEmitter<string>;` | Output for event current language code changed
704669
`countryCodeChanged: EventEmitter<string>;` | Output for event current country code changed
705670
`currencyCodeChanged: EventEmitter<string>;` | Output for event current currency code changed
@@ -732,7 +697,7 @@ Method | Function
732697
### <a name="7.2"/>7.2 LocalizationService
733698
Property | Value
734699
---------- | -----
735-
`translationChanged: EventEmitter<any>;` | Output for event translation changed
700+
`translationChanged: EventEmitter<string>;` | Output for event translation changed
736701
`languageCode: string;` | The language code for the service
737702
`loadingMode: LoadingMode;` | The loading mode for the service
738703
`serviceState: ServiceState;` | The service state

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular2localization",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "An Angular 2 library to translate messages, dates and numbers",
55
"main": "bundles/angular2localization.umd.js",
66
"module": "angular2localization.js",

0 commit comments

Comments
 (0)