Skip to content

Commit

Permalink
feat(core): replace intl API by our own locale files
Browse files Browse the repository at this point in the history
  • Loading branch information
ocombe committed Jun 28, 2017
1 parent 68fc65d commit 57894e0
Show file tree
Hide file tree
Showing 545 changed files with 85,808 additions and 525 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
bazel-*
node_modules
bower_components
tools/gulp-tasks/i18n/cldr-data/

# Include when developing application packages.
pubspec.lock
Expand Down
3 changes: 3 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 15 additions & 7 deletions packages/common/src/localization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


/**
Expand All @@ -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;
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 57894e0

Please sign in to comment.