Within Google, closure compiler is used for dealing with translations. We generate a closure-compatible locale file that allows for registration within Angular, so that Closure i18n works well together with Angular applications. Closure compiler does not limit its locales to BCP47-canonical locale identifiers. This commit updates the generation logic so that we also support deprecated (but aliased) locale identifiers, or other aliases which are likely used within Closure. We use CLDR's alias supplemental data for this. It instructs us to alias `iw` to `he` for example. `iw` is still supported in Closure. Note that we do not manually extract all locales supported in Closure; instead we only support the CLDR canonical locales (as done before) + common aliases that CLDR provides data for. We are not aware of other locale aliases within Closure that wouldn't be part of the CLDR aliases. If there would be, then Angular/Closure would fail accordingly. PR Close #42230
43 lines
1.6 KiB
TypeScript
43 lines
1.6 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright Google LLC All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.io/license
|
|
*/
|
|
|
|
import {CldrLocaleData} from './cldr-data';
|
|
import {fileHeader} from './file-header';
|
|
import {BaseCurrencies} from './locale-base-currencies';
|
|
import {generateDayPeriodsSupplementalString} from './locale-extra-file';
|
|
import {generateBasicLocaleString} from './locale-file';
|
|
import {getPluralFunction} from './plural-function';
|
|
|
|
/**
|
|
* Generated the contents for the global locale file
|
|
*/
|
|
export function generateLocaleGlobalFile(
|
|
locale: string, localeData: CldrLocaleData, baseCurrencies: BaseCurrencies) {
|
|
const basicLocaleData = generateBasicLocaleString(locale, localeData, baseCurrencies);
|
|
const extraLocaleData = generateDayPeriodsSupplementalString(locale, localeData);
|
|
const data = basicLocaleData.replace(/\]$/, `, ${extraLocaleData}]`);
|
|
return `${fileHeader}
|
|
(function(global) {
|
|
global.ng = global.ng || {};
|
|
global.ng.common = global.ng.common || {};
|
|
global.ng.common.locales = global.ng.common.locales || {};
|
|
const u = undefined;
|
|
${getPluralFunction(localeData, false)}
|
|
global.ng.common.locales['${normalizeLocale(locale)}'] = ${data};
|
|
})(typeof globalThis !== 'undefined' && globalThis || typeof global !== 'undefined' && global || typeof window !== 'undefined' && window);
|
|
`;
|
|
}
|
|
|
|
|
|
/**
|
|
* In Angular the locale is referenced by a "normalized" form.
|
|
*/
|
|
function normalizeLocale(locale: string): string {
|
|
return locale.toLowerCase().replace(/_/g, '-');
|
|
}
|