From 7b82877ee5d2b807f34d6c090f9370c4e12e879c Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Mon, 12 Sep 2016 11:27:15 -0700 Subject: [PATCH] fix(Localization): BCP47 uses hyphens as separator (#11514) https://tools.ietf.org/html/bcp47 --- modules/@angular/common/src/localization.ts | 2 +- .../@angular/common/test/localization_spec.ts | 18 +++--------------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/modules/@angular/common/src/localization.ts b/modules/@angular/common/src/localization.ts index a2073249b1..a84e73442a 100644 --- a/modules/@angular/common/src/localization.ts +++ b/modules/@angular/common/src/localization.ts @@ -87,7 +87,7 @@ export function getPluralCase(locale: string, nLike: number | string): Plural { const f = parseInt(nDecimal, 10); const t = parseInt(n.toString().replace(/^[^.]*\.?|0+$/g, ''), 10) || 0; - const lang = locale.split('_')[0].toLowerCase(); + const lang = locale.split('-')[0].toLowerCase(); switch (lang) { case 'af': diff --git a/modules/@angular/common/test/localization_spec.ts b/modules/@angular/common/test/localization_spec.ts index 75b29d3b3e..afec2c0dcb 100644 --- a/modules/@angular/common/test/localization_spec.ts +++ b/modules/@angular/common/test/localization_spec.ts @@ -57,7 +57,7 @@ export function main() { describe('NgLocaleLocalization', () => { it('should return the correct values for the "en" locale', () => { - const l10n = new NgLocaleLocalization('en_US'); + const l10n = new NgLocaleLocalization('en-US'); expect(l10n.getPluralCategory(0)).toEqual('other'); expect(l10n.getPluralCategory(1)).toEqual('one'); @@ -126,7 +126,7 @@ export function main() { describe('getPluralCategory', () => { it('should return plural category', () => { - const l10n = new FrLocalization(); + const l10n = new NgLocaleLocalization('fr'); expect(getPluralCategory(0, ['one', 'other'], l10n)).toEqual('one'); expect(getPluralCategory(1, ['one', 'other'], l10n)).toEqual('one'); @@ -134,7 +134,7 @@ export function main() { }); it('should return discrete cases', () => { - const l10n = new FrLocalization(); + const l10n = new NgLocaleLocalization('fr'); expect(getPluralCategory(0, ['one', 'other', '=0'], l10n)).toEqual('=0'); expect(getPluralCategory(1, ['one', 'other'], l10n)).toEqual('one'); @@ -143,16 +143,4 @@ export function main() { }); }); }); -} - -class FrLocalization extends NgLocalization { - getPluralCategory(value: number): string { - switch (value) { - case 0: - case 1: - return 'one'; - default: - return 'other'; - } - } } \ No newline at end of file