mirror of
https://github.com/CringeStudios/element-desktop.git
synced 2025-01-18 15:34:59 +01:00
Allow loading language files with two part language code (#339)
* Change the imported filenames to inlcude underscore in two part language names. (issue #19218) Signed-off-by: Timo Piiroinen <timo.piiroinen@unikie.com> * Refactoring the code Signed-off-by: Timo Piiroinen <timo.piiroinen@unikie.com> * Refactored code and added comment Signed-off-by: Timo Piiroinen <timo.piiroinen@unikie.com>
This commit is contained in:
parent
4d67e0561d
commit
fcfda67511
@ -92,10 +92,22 @@ export class AppLocalization {
|
||||
this.resetLocalizedUI();
|
||||
}
|
||||
|
||||
// Format language strings from normalized form to non-normalized form (e.g. en-gb to en_GB)
|
||||
private denormalize(locale: string): string {
|
||||
if (locale === "en") {
|
||||
locale = "en_EN";
|
||||
}
|
||||
const parts = locale.split("-");
|
||||
if (parts.length > 1) {
|
||||
parts[1] = parts[1].toUpperCase();
|
||||
}
|
||||
return parts.join("_");
|
||||
}
|
||||
|
||||
public fetchTranslationJson(locale: string): Record<string, string> {
|
||||
try {
|
||||
console.log("Fetching translation json for locale: " + locale);
|
||||
return require(`./i18n/strings/${locale}.json`);
|
||||
return require(`./i18n/strings/${this.denormalize(locale)}.json`);
|
||||
} catch (e) {
|
||||
console.log(`Could not fetch translation json for locale: '${locale}'`, e);
|
||||
return null;
|
||||
|
Loading…
Reference in New Issue
Block a user