fix(common): generate closure-locale data file with exported plural functions (#21873)
Fixes #21870 PR Close #21873
This commit is contained in:
parent
bb577c624b
commit
b62739a989
File diff suppressed because it is too large
Load Diff
|
@ -110,8 +110,13 @@ function generateAllLocalesFile(LOCALES, ALIASES) {
|
||||||
// find the existing content file
|
// find the existing content file
|
||||||
const path = `${RELATIVE_I18N_DATA_FOLDER}/${l}.ts`;
|
const path = `${RELATIVE_I18N_DATA_FOLDER}/${l}.ts`;
|
||||||
if (fs.existsSync(`${RELATIVE_I18N_DATA_FOLDER}/${l}.ts`)) {
|
if (fs.existsSync(`${RELATIVE_I18N_DATA_FOLDER}/${l}.ts`)) {
|
||||||
|
const localeName = formatLocale(locale);
|
||||||
existingLocalesData[locale] =
|
existingLocalesData[locale] =
|
||||||
fs.readFileSync(path, 'utf8').replace(`${HEADER}\nexport default `, '');
|
fs.readFileSync(path, 'utf8')
|
||||||
|
.replace(`${HEADER}\n`, '')
|
||||||
|
.replace('export default ', `export const locale_${localeName} = `)
|
||||||
|
.replace('function plural', `function plural_${localeName}`)
|
||||||
|
.replace(/,(\n | )plural/, `, plural_${localeName}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,17 +130,17 @@ function generateAllLocalesFile(LOCALES, ALIASES) {
|
||||||
str += `case '${l}':\n`;
|
str += `case '${l}':\n`;
|
||||||
}
|
}
|
||||||
|
|
||||||
str += ` l = ${formatLocale(locale)};
|
str += ` l = locale_${formatLocale(locale)};
|
||||||
break;\n`;
|
break;\n`;
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatLocale(locale) { return `locale_${locale.replace(/-/g, '_')}`; }
|
function formatLocale(locale) { return locale.replace(/-/g, '_'); }
|
||||||
// clang-format off
|
// clang-format off
|
||||||
return `${HEADER}
|
return `${HEADER}
|
||||||
import {registerLocaleData} from '../src/i18n/locale_data';
|
import {registerLocaleData} from '../src/i18n/locale_data';
|
||||||
|
|
||||||
${LOCALES.map(locale => `export const ${formatLocale(locale)} = ${existingLocalesData[locale]}`).join('\n')}
|
${LOCALES.map(locale => `${existingLocalesData[locale]}`).join('\n')}
|
||||||
|
|
||||||
let l: any;
|
let l: any;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue