feat(ivy): use i18n locale data to determine the plural form of ICU expressions (#29249)
Plural ICU expressions depend on the locale (different languages have different plural forms). Until now the locale was hard coded as `en-US`. For compatibility reasons, if you use ivy with AOT and bootstrap your app with `bootstrapModule` then the `LOCALE_ID` token will be set automatically for ivy, which is then used to get the correct plural form. If you use JIT, you need to define the `LOCALE_ID` provider on the module that you bootstrap. For `TestBed` you can use either `configureTestingModule` or `overrideProvider` to define that provider. If you don't use the compat mode and start your app with `renderComponent` you need to call `ɵsetLocaleId` manually to define the `LOCALE_ID` before bootstrap. We expect this to change once we start adding the new i18n APIs, so don't rely on this function (there's a reason why it's a private export). PR Close #29249
This commit is contained in:

committed by
Matias Niemelä

parent
f5b0c8a323
commit
5e0f982961
@ -14,11 +14,14 @@ const cldr = require('cldr');
|
||||
// used to extract all other cldr data
|
||||
const cldrJs = require('cldrjs');
|
||||
|
||||
const PACKAGE_FOLDER = 'packages/common';
|
||||
const I18N_FOLDER = `${PACKAGE_FOLDER}/src/i18n`;
|
||||
const I18N_DATA_FOLDER = `${PACKAGE_FOLDER}/locales`;
|
||||
const COMMON_PACKAGE = 'packages/common';
|
||||
const CORE_PACKAGE = 'packages/core';
|
||||
const I18N_FOLDER = `${COMMON_PACKAGE}/src/i18n`;
|
||||
const I18N_CORE_FOLDER = `${CORE_PACKAGE}/src/i18n`;
|
||||
const I18N_DATA_FOLDER = `${COMMON_PACKAGE}/locales`;
|
||||
const I18N_DATA_EXTRA_FOLDER = `${I18N_DATA_FOLDER}/extra`;
|
||||
const RELATIVE_I18N_FOLDER = path.resolve(__dirname, `../../../${I18N_FOLDER}`);
|
||||
const RELATIVE_I18N_CORE_FOLDER = path.resolve(__dirname, `../../../${I18N_CORE_FOLDER}`);
|
||||
const RELATIVE_I18N_DATA_FOLDER = path.resolve(__dirname, `../../../${I18N_DATA_FOLDER}`);
|
||||
const RELATIVE_I18N_DATA_EXTRA_FOLDER = path.resolve(__dirname, `../../../${I18N_DATA_EXTRA_FOLDER}`);
|
||||
const DEFAULT_RULE = 'function anonymous(n\n/*``*/) {\nreturn"other"\n}';
|
||||
@ -60,9 +63,9 @@ module.exports = (gulp, done) => {
|
||||
|
||||
const baseCurrencies = generateBaseCurrencies(new cldrJs('en'));
|
||||
// additional "en" file that will be included in common
|
||||
console.log(`Writing file ${I18N_FOLDER}/locale_en.ts`);
|
||||
console.log(`Writing file ${I18N_CORE_FOLDER}/locale_en.ts`);
|
||||
const localeEnFile = generateLocale('en', new cldrJs('en'), baseCurrencies);
|
||||
fs.writeFileSync(`${RELATIVE_I18N_FOLDER}/locale_en.ts`, localeEnFile);
|
||||
fs.writeFileSync(`${RELATIVE_I18N_CORE_FOLDER}/locale_en.ts`, localeEnFile);
|
||||
|
||||
LOCALES.forEach((locale, index) => {
|
||||
const localeData = new cldrJs(locale);
|
||||
@ -82,7 +85,7 @@ module.exports = (gulp, done) => {
|
||||
.src([
|
||||
`${I18N_DATA_FOLDER}/**/*.ts`,
|
||||
`${I18N_FOLDER}/currencies.ts`,
|
||||
`${I18N_FOLDER}/locale_en.ts`
|
||||
`${I18N_CORE_FOLDER}/locale_en.ts`
|
||||
], {base: '.'})
|
||||
.pipe(format.format('file', clangFormat))
|
||||
.pipe(gulp.dest('.'));
|
||||
|
2
tools/public_api_guard/common/common.d.ts
vendored
2
tools/public_api_guard/common/common.d.ts
vendored
@ -103,7 +103,7 @@ export declare function getLocaleNumberFormat(locale: string, type: NumberFormat
|
||||
|
||||
export declare function getLocaleNumberSymbol(locale: string, symbol: NumberSymbol): string;
|
||||
|
||||
export declare function getLocalePluralCase(locale: string): (value: number) => Plural;
|
||||
export declare const getLocalePluralCase: (locale: string) => ((value: number) => Plural);
|
||||
|
||||
export declare function getLocaleTimeFormat(locale: string, width: FormatWidth): string;
|
||||
|
||||
|
Reference in New Issue
Block a user