Move to smartling for translation services

This commit is contained in:
Scott Nonnenberg 2022-09-27 14:01:06 -07:00 committed by GitHub
parent 620067342a
commit 5957c111cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
73 changed files with 1394 additions and 64465 deletions

View file

@ -20,15 +20,7 @@ function removeRegion(locale: string): string {
}
function getLocaleMessages(locale: string): LocaleMessagesType {
const onDiskLocale = locale.replace('-', '_');
const targetFile = join(
__dirname,
'..',
'_locales',
onDiskLocale,
'messages.json'
);
const targetFile = join(__dirname, '..', '_locales', locale, 'messages.json');
return JSON.parse(readFileSync(targetFile, 'utf-8'));
}
@ -81,7 +73,7 @@ export function load({
//
// possible locales:
// https://source.chromium.org/chromium/chromium/src/+/main:ui/base/l10n/l10n_util.cc
const normalized = removeRegion(appLocale);
const languageOnly = removeRegion(appLocale);
try {
return finalize(getLocaleMessages(appLocale), english, appLocale);
@ -90,11 +82,11 @@ export function load({
}
try {
logger.warn(`Falling back to parent language: '${normalized}'`);
logger.warn(`Falling back to parent language: '${languageOnly}'`);
// Note: messages are from parent language, but we still keep the region
return finalize(getLocaleMessages(normalized), english, appLocale);
return finalize(getLocaleMessages(languageOnly), english, appLocale);
} catch (e) {
logger.error(`Problem loading messages for locale ${normalized}`);
logger.error(`Problem loading messages for locale ${languageOnly}`);
logger.warn("Falling back to 'en' locale");
return finalize(english, english, 'en');