fix(Localization): BCP47 uses hyphens as separator (#11514)

https://tools.ietf.org/html/bcp47
This commit is contained in:
Victor Berchet 2016-09-12 11:27:15 -07:00 committed by Evan Martin
parent c9ad5e46d6
commit 7b82877ee5
2 changed files with 4 additions and 16 deletions

View File

@ -87,7 +87,7 @@ export function getPluralCase(locale: string, nLike: number | string): Plural {
const f = parseInt(nDecimal, 10); const f = parseInt(nDecimal, 10);
const t = parseInt(n.toString().replace(/^[^.]*\.?|0+$/g, ''), 10) || 0; const t = parseInt(n.toString().replace(/^[^.]*\.?|0+$/g, ''), 10) || 0;
const lang = locale.split('_')[0].toLowerCase(); const lang = locale.split('-')[0].toLowerCase();
switch (lang) { switch (lang) {
case 'af': case 'af':

View File

@ -57,7 +57,7 @@ export function main() {
describe('NgLocaleLocalization', () => { describe('NgLocaleLocalization', () => {
it('should return the correct values for the "en" locale', () => { 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(0)).toEqual('other');
expect(l10n.getPluralCategory(1)).toEqual('one'); expect(l10n.getPluralCategory(1)).toEqual('one');
@ -126,7 +126,7 @@ export function main() {
describe('getPluralCategory', () => { describe('getPluralCategory', () => {
it('should return plural category', () => { it('should return plural category', () => {
const l10n = new FrLocalization(); const l10n = new NgLocaleLocalization('fr');
expect(getPluralCategory(0, ['one', 'other'], l10n)).toEqual('one'); expect(getPluralCategory(0, ['one', 'other'], l10n)).toEqual('one');
expect(getPluralCategory(1, ['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', () => { 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(0, ['one', 'other', '=0'], l10n)).toEqual('=0');
expect(getPluralCategory(1, ['one', 'other'], l10n)).toEqual('one'); expect(getPluralCategory(1, ['one', 'other'], l10n)).toEqual('one');
@ -144,15 +144,3 @@ export function main() {
}); });
}); });
} }
class FrLocalization extends NgLocalization {
getPluralCategory(value: number): string {
switch (value) {
case 0:
case 1:
return 'one';
default:
return 'other';
}
}
}