0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-19 19:42:17 +02:00

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 <github@mikehardy.net>
This commit is contained in:
Kevin 2024-05-02 15:35:58 -07:00 committed by GitHub
parent dc5348852b
commit 0f795cea36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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;
}
});
}
}