Permalink
Browse files

feat(common): add locale id parameter to `registerLocaleData` (#20623)

PR Close #20623
  • Loading branch information...
ocombe authored and mhevery committed Nov 24, 2017
1 parent 8ecda94 commit 24bf3e2a251634811096b939e61d63297934579e
@@ -4895,6 +4895,5 @@ switch (goog.LOCALE) {
}
if (l) {
l[0] = goog.LOCALE;
registerLocaleData(l);
registerLocaleData(l, goog.LOCALE);
}
@@ -17,9 +17,17 @@ export const LOCALE_DATA: {[localeId: string]: any} = {};
*
* @experimental i18n support is experimental.
*/
export function registerLocaleData(data: any, extraData?: any) {
const localeId = data[LocaleDataIndex.LocaleId].toLowerCase().replace(/_/g, '-');
// The signature registerLocaleData(data: any, extraData?: any) is deprecated since v5.1
export function registerLocaleData(data: any, localeId?: string | any, extraData?: any): void {
if (typeof localeId !== 'string') {
extraData = localeId;
localeId = data[LocaleDataIndex.LocaleId];
}
localeId = localeId.toLowerCase().replace(/_/g, '-');
LOCALE_DATA[localeId] = data;
if (extraData) {
LOCALE_DATA[localeId][LocaleDataIndex.ExtraData] = extraData;
}
@@ -10,8 +10,8 @@ import localeCaESVALENCIA from '../../locales/ca-ES-VALENCIA';
import localeEn from '../../locales/en';
import localeFr from '../../locales/fr';
import localeFrCA from '../../locales/fr-CA';
import {findLocaleData} from '../../src/i18n/locale_data_api';
import {registerLocaleData} from '../../src/i18n/locale_data';
import {findLocaleData} from '../../src/i18n/locale_data_api';
export function main() {
describe('locale data api', () => {
@@ -20,6 +20,8 @@ export function main() {
registerLocaleData(localeEn);
registerLocaleData(localeFr);
registerLocaleData(localeFrCA);
registerLocaleData(localeFr, 'fake-id');
registerLocaleData(localeFrCA, 'fake_Id2');
});
describe('findLocaleData', () => {
@@ -42,6 +44,12 @@ export function main() {
expect(findLocaleData('ca-ES-VALENCIA')).toEqual(localeCaESVALENCIA);
expect(findLocaleData('CA_es_Valencia')).toEqual(localeCaESVALENCIA);
});
it(`should find the LOCALE_DATA if the locale id was registered`, () => {
expect(findLocaleData('fake-id')).toEqual(localeFr);
expect(findLocaleData('fake_iD')).toEqual(localeFr);
expect(findLocaleData('fake-id2')).toEqual(localeFrCA);
});
});
});
}
@@ -143,8 +143,7 @@ switch (goog.LOCALE) {
${LOCALES.map(locale => generateCases(locale)).join('')}}
if(l) {
l[0] = goog.LOCALE;
registerLocaleData(l);
registerLocaleData(l, goog.LOCALE);
}
`;
// clang-format on
@@ -422,7 +422,7 @@ export interface PopStateEvent {
}
/** @experimental */
export declare function registerLocaleData(data: any, extraData?: any): void;
export declare function registerLocaleData(data: any, localeId?: string | any, extraData?: any): void;
/** @stable */
export declare class SlicePipe implements PipeTransform {

0 comments on commit 24bf3e2

Please sign in to comment.