Skip to content
Permalink
Browse files

feat(core): replace intl API by our own locale files

  • Loading branch information...
ocombe committed Jun 19, 2017
1 parent 68fc65d commit 5cfab73a2db02e781adc8e0e17762462a483117c
Showing 545 changed files with 85,817 additions and 525 deletions.
@@ -4,6 +4,7 @@
bazel-*
node_modules
bower_components
tools/gulp-tasks/i18n/cldr-data/

# Include when developing application packages.
pubspec.lock
@@ -42,3 +42,6 @@ gulp.task('serve', loadTask('serve', 'default'));
gulp.task('serve-examples', loadTask('serve', 'examples'));
gulp.task('changelog', loadTask('changelog'));
gulp.task('check-env', () => {/* this is a noop because the env test ran already above */});
gulp.task('i18n:extract', loadTask('i18n', 'extract'));
gulp.task('i18n:download', loadTask('i18n', 'download'));
gulp.task('i18n:format', loadTask('i18n', 'format'));
@@ -49,7 +49,9 @@
"canonical-path": "0.0.2",
"chokidar": "^1.1.0",
"clang-format": "^1.0.32",
"cldr": "^3.5.2",
"cldr": "^4.3.0",
"cldr-data-downloader": "^0.3.0",
"cldrjs": "^0.4.8",
"conventional-changelog": "^1.1.0",
"cors": "^2.7.1",
"dgeni": "^0.4.2",
@@ -6,12 +6,14 @@
* found in the LICENSE file at https://angular.io/license
*/

import {Inject, Injectable, LOCALE_ID} from '@angular/core';
import {Inject, Injectable, LOCALE_DATA, LOCALE_ID, NgLocale, findNgLocale} from '@angular/core';

/**
* @experimental
*/
export abstract class NgLocalization { abstract getPluralCategory(value: any): string; }
export abstract class NgLocalization {
abstract getPluralCategory(value: any, locale?: string): string;
}


/**
@@ -22,14 +24,14 @@ export abstract class NgLocalization { abstract getPluralCategory(value: any): s
* @internal
*/
export function getPluralCategory(
value: number, cases: string[], ngLocalization: NgLocalization): string {
value: number, cases: string[], ngLocalization: NgLocalization, locale?: string): string {
let key = `=${value}`;

if (cases.indexOf(key) > -1) {
return key;
}

key = ngLocalization.getPluralCategory(value);
key = ngLocalization.getPluralCategory(value, locale);

if (cases.indexOf(key) > -1) {
return key;
@@ -49,10 +51,15 @@ export function getPluralCategory(
*/
@Injectable()
export class NgLocaleLocalization extends NgLocalization {
constructor(@Inject(LOCALE_ID) protected locale: string) { super(); }
constructor(
@Inject(LOCALE_ID) protected locale: string,
@Inject(LOCALE_DATA) protected localeData: NgLocale[]) {
super();
}

getPluralCategory(value: any): string {
const plural = getPluralCase(this.locale, value);
getPluralCategory(value: any, locale?: string): string {
const localeDatum = findNgLocale(locale || this.locale, this.localeData);
const plural = localeDatum.getPluralCase(value);

switch (plural) {
case Plural.Zero:
@@ -88,6 +95,7 @@ export enum Plural {
* Returns the plural case based on the locale
*
* @experimental
* @deprecated use the getPluralCase method of NgLocale instead
*/
export function getPluralCase(locale: string, nLike: number | string): Plural {
// TODO(vicb): lazy compute
Oops, something went wrong.

0 comments on commit 5cfab73

Please sign in to comment.
You can’t perform that action at this time.