Skip to content

Commit

Permalink
fix: duplicate values-heb into values-iw so hebrew works on all devic…
Browse files Browse the repository at this point in the history
…es (ankidroid#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 <[email protected]>
  • Loading branch information
kpdyer16 and mikehardy authored May 2, 2024
1 parent dc53488 commit 0f795ce
Showing 1 changed file with 37 additions and 33 deletions.
70 changes: 37 additions & 33 deletions tools/localization/src/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

// 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;
}
if (anyError) {
console.error(
"At least one file of the last handled language contains an error.",
);
anyError = true;
}
});
}
}

0 comments on commit 0f795ce

Please sign in to comment.