feat(i18n): provide LOCALE_ID and NgLocalization

This commit is contained in:
Victor Berchet
2016-08-12 16:52:55 -07:00
committed by Vikram Subramanian
parent 4df48b202c
commit ce4eae65a7
10 changed files with 162 additions and 122 deletions

View File

@ -18,29 +18,21 @@ import {SwitchView} from './ng_switch';
* `ngPlural` is an i18n directive that displays DOM sub-trees that match the switch expression
* value, or failing that, DOM sub-trees that match the switch expression's pluralization category.
*
* To use this directive, you must provide an extension of `NgLocalization` that maps values to
* category names. You then define a container element that sets the `[ngPlural]` attribute to a
* To use this directive you must provide a container element that sets the `[ngPlural]` attribute
* to a
* switch expression.
* - Inner elements defined with an `[ngPluralCase]` attribute will display based on their
* expression.
* - If `[ngPluralCase]` is set to a value starting with `=`, it will only display if the value
* matches the switch expression exactly.
* - Otherwise, the view will be treated as a "category match", and will only display if exact
* value matches aren't found and the value maps to its category using the `getPluralCategory`
* function provided.
* value matches aren't found and the value maps to its category for the defined locale.
*
* ```typescript
* class MyLocalization extends NgLocalization {
* getPluralCategory(value: any) {
* if(value < 5) {
* return 'few';
* }
* }
* }
*
* @Component({
* selector: 'app',
* providers: [{provide: NgLocalization, useClass: MyLocalization}]
* // best practice is to define the locale at the application level
* providers: [{provide: LOCALE_ID, useValue: 'en_US'}]
* })
* @View({
* template: `