i18n: enable local debug locale, en-XL (#9192)
This commit is contained in:
Родитель
f6df91ac59
Коммит
e3cbe02c05
|
@ -189,7 +189,7 @@ function _formatIcuMessage(locale, icuMessageId, fallbackMessage, values) {
|
|||
const messageForMessageFormat = localeMessage || fallbackMessage;
|
||||
if (messageForMessageFormat === undefined) throw new Error(_ICUMsgNotFoundMsg);
|
||||
// when using accented english, force the use of a different locale for number formatting
|
||||
const localeForMessageFormat = locale === 'en-XA' ? 'de-DE' : locale;
|
||||
const localeForMessageFormat = (locale === 'en-XA' || locale === 'en-XL') ? 'de-DE' : locale;
|
||||
// pre-process values for the message format like KB and milliseconds
|
||||
const valuesForMessageFormat = _preprocessMessageValues(messageForMessageFormat, values);
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@ const locales = {
|
|||
'de': require('./locales/de.json'), // de-AT, de-CH identical, so they fall back into de
|
||||
'el': require('./locales/el.json'),
|
||||
'en-XA': require('./locales/en-XA.json'), // psuedolocalization
|
||||
'en-XL': require('./locales/en-XL.json'), // local psuedolocalization
|
||||
'es': require('./locales/es.json'),
|
||||
'es-419': require('./locales/es-419.json'),
|
||||
// Aliases of es-419: https://raw.githubusercontent.com/unicode-cldr/cldr-core/master/supplemental/parentLocales.json
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -100,8 +100,48 @@ function collectAllStringsInDir(dir, strings = {}) {
|
|||
/**
|
||||
* @param {Record<string, ICUMessageDefn>} strings
|
||||
*/
|
||||
function writeEnStringsToLocaleFormat(strings) {
|
||||
const fullPath = path.join(LH_ROOT, `lighthouse-core/lib/i18n/en-US.json`);
|
||||
function createPsuedoLocaleStrings(strings) {
|
||||
/** @type {Record<string, ICUMessageDefn>} */
|
||||
const psuedoLocalizedStrings = {};
|
||||
for (const [key, defn] of Object.entries(strings)) {
|
||||
const message = defn.message;
|
||||
const psuedoLocalizedString = [];
|
||||
let braceCount = 0;
|
||||
let useHatForAccentMark = true;
|
||||
for (const char of message) {
|
||||
psuedoLocalizedString.push(char);
|
||||
if (char === '{') {
|
||||
braceCount++;
|
||||
} else if (char === '}') {
|
||||
braceCount--;
|
||||
}
|
||||
|
||||
// Hack to not change {plural{ICU}braces} nested an odd number of times.
|
||||
// ex: "{itemCount, plural, =1 {1 link found} other {# links found}}"
|
||||
// becomes "{itemCount, plural, =1 {1 l̂ín̂ḱ f̂óûńd̂} other {# ĺîńk̂ś f̂óûńd̂}}"
|
||||
// ex: "{itemCount, plural, =1 {1 link {nested_replacement} found} other {# links {nested_replacement} found}}"
|
||||
// becomes: "{itemCount, plural, =1 {1 l̂ín̂ḱ {nested_replacement} f̂óûńd̂} other {# ĺîńk̂ś {nested_replacement} f̂óûńd̂}}"
|
||||
if (braceCount % 2 === 1) continue;
|
||||
|
||||
// Add diacritical marks to the preceding letter, alternating between a hat ( ̂) and an acute (´).
|
||||
if (/[a-z]/i.test(char)) {
|
||||
psuedoLocalizedString.push(useHatForAccentMark ? `\u0302` : `\u0301`);
|
||||
useHatForAccentMark = !useHatForAccentMark;
|
||||
}
|
||||
}
|
||||
|
||||
psuedoLocalizedStrings[key] = {message: psuedoLocalizedString.join('')};
|
||||
}
|
||||
|
||||
return psuedoLocalizedStrings;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} locale
|
||||
* @param {Record<string, ICUMessageDefn>} strings
|
||||
*/
|
||||
function writeStringsToLocaleFormat(locale, strings) {
|
||||
const fullPath = path.join(LH_ROOT, `lighthouse-core/lib/i18n/${locale}.json`);
|
||||
/** @type {Record<string, ICUMessageDefn>} */
|
||||
const output = {};
|
||||
const sortedEntries = Object.entries(strings).sort(([keyA], [keyB]) => keyA.localeCompare(keyB));
|
||||
|
@ -113,10 +153,12 @@ function writeEnStringsToLocaleFormat(strings) {
|
|||
}
|
||||
|
||||
const strings = collectAllStringsInDir(path.join(LH_ROOT, 'lighthouse-core'));
|
||||
const psuedoLocalizedStrings = createPsuedoLocaleStrings(strings);
|
||||
console.log('Collected from LH core!');
|
||||
|
||||
collectAllStringsInDir(path.join(LH_ROOT, 'stack-packs/packs'), strings);
|
||||
console.log('Collected from Stack Packs!');
|
||||
|
||||
writeEnStringsToLocaleFormat(strings);
|
||||
writeStringsToLocaleFormat('en-US', strings);
|
||||
writeStringsToLocaleFormat('locales/en-XL', psuedoLocalizedStrings);
|
||||
console.log('Written to disk!');
|
||||
|
|
|
@ -74,7 +74,7 @@ declare global {
|
|||
serverResponseTimeByOrigin: {[origin: string]: number};
|
||||
}
|
||||
|
||||
export type Locale = 'en-US'|'en'|'en-AU'|'en-GB'|'en-IE'|'en-SG'|'en-ZA'|'en-IN'|'ar-XB'|'ar'|'bg'|'bs'|'ca'|'cs'|'da'|'de'|'el'|'en-XA'|'es'|'es-419'|'es-AR'|'es-BO'|'es-BR'|'es-BZ'|'es-CL'|'es-CO'|'es-CR'|'es-CU'|'es-DO'|'es-EC'|'es-GT'|'es-HN'|'es-MX'|'es-NI'|'es-PA'|'es-PE'|'es-PR'|'es-PY'|'es-SV'|'es-US'|'es-UY'|'es-VE'|'fi'|'fil'|'fr'|'he'|'hi'|'hr'|'hu'|'gsw'|'id'|'in'|'it'|'iw'|'ja'|'ko'|'ln'|'lt'|'lv'|'mo'|'nl'|'nb'|'no'|'pl'|'pt'|'pt-PT'|'ro'|'ru'|'sk'|'sl'|'sr'|'sr-Latn'|'sv'|'ta'|'te'|'th'|'tl'|'tr'|'uk'|'vi'|'zh'|'zh-HK'|'zh-TW';
|
||||
export type Locale = 'en-US'|'en'|'en-AU'|'en-GB'|'en-IE'|'en-SG'|'en-ZA'|'en-IN'|'ar-XB'|'ar'|'bg'|'bs'|'ca'|'cs'|'da'|'de'|'el'|'en-XA'|'en-XL'|'es'|'es-419'|'es-AR'|'es-BO'|'es-BR'|'es-BZ'|'es-CL'|'es-CO'|'es-CR'|'es-CU'|'es-DO'|'es-EC'|'es-GT'|'es-HN'|'es-MX'|'es-NI'|'es-PA'|'es-PE'|'es-PR'|'es-PY'|'es-SV'|'es-US'|'es-UY'|'es-VE'|'fi'|'fil'|'fr'|'he'|'hi'|'hr'|'hu'|'gsw'|'id'|'in'|'it'|'iw'|'ja'|'ko'|'ln'|'lt'|'lv'|'mo'|'nl'|'nb'|'no'|'pl'|'pt'|'pt-PT'|'ro'|'ru'|'sk'|'sl'|'sr'|'sr-Latn'|'sv'|'ta'|'te'|'th'|'tl'|'tr'|'uk'|'vi'|'zh'|'zh-HK'|'zh-TW';
|
||||
|
||||
export type OutputMode = 'json' | 'html' | 'csv';
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче