Skip to content

Commit

Permalink
feat(core): remove dependency to intl API
Browse files Browse the repository at this point in the history
BREAKING CHANGE: all i18n pipes have been updated to not require the intl API anymore. Some results might vary, see the document to update from v4 to v5 for more information.

Fixes angular#10809, angular#9524, angular#7008, angular#9324, angular#7590, angular#6724, angular#3429, angular#17576, angular#17478, angular#17319, angular#17200, angular#16838, angular#16624, angular#16625, angular#16591, angular#14131, angular#12632, angular#11376, angular#11187
  • Loading branch information
ocombe committed Jun 28, 2017
1 parent 68fc65d commit b24ad4f
Show file tree
Hide file tree
Showing 545 changed files with 85,832 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
2 changes: 2 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ 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'));
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 b24ad4f

Please sign in to comment.