From 0f795cea363ace67bd55ec56775c5beae73c7c9e Mon Sep 17 00:00:00 2001 From: Kevin Date: Thu, 2 May 2024 15:35:58 -0700 Subject: [PATCH] fix: duplicate values-heb into values-iw so hebrew works on all devices (#16316) * fix: localizations not being added to values-iw Some devices rely on hebrew translations being in the values-heb resource directory and others rely on the translations being in values-iw. This change is a quick fix which reuses the same algorithm for updating localization resources, while duplicating hebrew translations to values-heb and values-iw. * Update tools/localization/src/update.ts --------- Co-authored-by: Mike Hardy --- tools/localization/src/update.ts | 70 +++++++++++++++++--------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/tools/localization/src/update.ts b/tools/localization/src/update.ts index 5697a022c7..11ee96383b 100644 --- a/tools/localization/src/update.ts +++ b/tools/localization/src/update.ts @@ -180,59 +180,63 @@ export async function updateI18nFiles() { // but this comment hopefully clarifies for the reader that BCP47 / ISO-639-2 3-letter language tags do work in practice. // // The codes are not case-sensitive; the r prefix is used to distinguish the region portion. You cannot specify a region alone. - let androidLanguage = ""; + let androidLanguages = []; const languageCode = language.split("-", 1)[0]; if (LOCALIZED_REGIONS.includes(languageCode)) { - androidLanguage = language.replace("-", "-r"); // zh-CN becomes zh-rCN + androidLanguages = [language.replace("-", "-r")]; // zh-CN becomes zh-rCN } else { - androidLanguage = language.split("-", 1)[0]; // Example: es-ES becomes es + androidLanguages = [language.split("-", 1)[0]]; // Example: es-ES becomes es } switch (language) { case "yu": - androidLanguage = "yue"; + androidLanguages = ["yue"]; break; case "he": - androidLanguage = "heb"; + // some Android phones use values-heb, some use values-iw - issue 9451 + // the only way for Hebrew to work on all devices is to copy into both possible locations + androidLanguages = ["heb", "iw"]; break; case "id": - androidLanguage = "ind"; + androidLanguages = ["ind"]; break; case "tl": - androidLanguage = "tgl"; + androidLanguages = ["tgl"]; break; } - console.log( - "\nCopying language files from " + language + " to " + androidLanguage, - ); - const valuesDirectory = path.join(RES_VALUES_LANG_DIR + androidLanguage + "/"); - createDirIfNotExisting(valuesDirectory); - - // Copy localization files, mask chars and append gnu/gpl licence - for (const f of I18N_FILES) { - const fileExt = fileExtFor(f); - const translatedContent = fs.readFileSync( - TEMP_DIR + "/" + language + "/" + f + fileExt, - "utf-8", + androidLanguages.map(async androidLanguage => { + console.log( + "\nCopying language files from " + language + " to " + androidLanguage, ); - anyError = !(await update( - valuesDirectory, - translatedContent, - f, - fileExt, - language, - )); - } + const valuesDirectory = path.join(RES_VALUES_LANG_DIR + androidLanguage + "/"); + createDirIfNotExisting(valuesDirectory); - if (anyError) { - console.error( - "At least one file of the last handled language contains an error.", - ); - anyError = true; - } + // Copy localization files, mask chars and append gnu/gpl licence + for (const f of I18N_FILES) { + const fileExt = fileExtFor(f); + const translatedContent = fs.readFileSync( + TEMP_DIR + "/" + language + "/" + f + fileExt, + "utf-8", + ); + anyError = !(await update( + valuesDirectory, + translatedContent, + f, + fileExt, + language, + )); + } + + if (anyError) { + console.error( + "At least one file of the last handled language contains an error.", + ); + anyError = true; + } + }); } }