Skip to content

Commit

Permalink
Merge branch 'add_transfer_notes' into sw_digester
Browse files Browse the repository at this point in the history
  • Loading branch information
schlagmichdoch committed Jul 14, 2024
2 parents 3b31472 + 51299bc commit db8d5f9
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions public/scripts/localization.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,36 @@ class Localization {
constructor() {
Localization.$htmlRoot = document.querySelector('html');

Localization.defaultLocale = "en";
Localization.supportedLocales = ["ar", "be", "ca", "da", "de", "en", "es", "fr", "he", "hu", "id", "it", "ja", "kn", "nb", "nl", "pl", "pt-BR", "ro", "ru", "tr", "zh-CN", "zh-TW"];
Localization.supportedLocalesRtl = ["ar", "he"];
Localization.localeDefault = "en";
Localization.localesSupported = ["ar", "be", "ca", "da", "de", "en", "es", "fr", "he", "hu", "id", "it", "ja", "kn", "nb", "nl", "pl", "pt-BR", "ro", "ru", "tr", "zh-CN", "zh-TW"];
Localization.localesRtl = ["ar", "he"];

Localization.translations = {};
Localization.translationsDefaultLocale = {};

Localization.systemLocale = Localization.getSupportedOrDefaultLocales(navigator.languages);
Localization.localeSystem = Localization.getSupportedOrDefaultLocales(navigator.languages);

let storedLanguageCode = localStorage.getItem('language_code');

Localization.initialLocale = storedLanguageCode && Localization.localeIsSupported(storedLanguageCode)
Localization.localeInitial = storedLanguageCode && Localization.localeIsSupported(storedLanguageCode)
? storedLanguageCode
: Localization.systemLocale;
: Localization.localeSystem;
}

static localeIsSupported(locale) {
return Localization.supportedLocales.indexOf(locale) > -1;
return Localization.localesSupported.indexOf(locale) > -1;
}

static localeIsRtl(locale) {
return Localization.supportedLocalesRtl.indexOf(locale) > -1;
return Localization.localesRtl.indexOf(locale) > -1;
}

static currentLocaleIsRtl() {
return Localization.localeIsRtl(Localization.locale);
}

static currentLocaleIsDefault() {
return Localization.locale === Localization.defaultLocale
return Localization.locale === Localization.localeDefault
}

static getSupportedOrDefaultLocales(locales) {
Expand All @@ -44,15 +44,15 @@ class Localization {
// If there is no perfect match for browser locales, try generic locales first before resorting to the default locale
return locales.find(Localization.localeIsSupported)
|| localesGeneric.find(Localization.localeIsSupported)
|| Localization.defaultLocale;
|| Localization.localeDefault;
}

async setInitialTranslation() {
await Localization.setTranslation(Localization.initialLocale)
await Localization.setTranslation(Localization.localeInitial)
}

static async setTranslation(locale) {
if (!locale) locale = Localization.systemLocale;
if (!locale) locale = Localization.localeSystem;

await Localization.setLocale(locale)
await Localization.translatePage();
Expand All @@ -68,7 +68,7 @@ class Localization {


Logger.debug("Page successfully translated",
`System language: ${Localization.systemLocale}`,
`System language: ${Localization.localeSystem}`,
`Selected language: ${locale}`
);

Expand All @@ -78,7 +78,7 @@ class Localization {
static async setLocale(newLocale) {
if (newLocale === Localization.locale) return false;

Localization.defaultTranslations = await Localization.fetchTranslationsFor(Localization.defaultLocale);
Localization.translationsDefaultLocale = await Localization.fetchTranslationsFor(Localization.localeDefault);

const newTranslations = await Localization.fetchTranslationsFor(newLocale);

Expand Down Expand Up @@ -192,7 +192,7 @@ class Localization {
else {
// Is not default locale yet
// Get translation for default language with same arguments
Logger.debug(`Using default language ${Localization.defaultLocale.toUpperCase()} instead.`);
Logger.debug(`Using default language ${Localization.localeDefault.toUpperCase()} instead.`);
translation = this.getTranslation(key, attr, data, true);
}
}
Expand All @@ -202,7 +202,7 @@ class Localization {

static logTranslationMissingOrBroken(key, attr, data, useDefault) {
let usedLocale = useDefault
? Localization.defaultLocale.toUpperCase()
? Localization.localeDefault.toUpperCase()
: Localization.locale.toUpperCase();

Logger.warn(`Missing or broken translation for language ${usedLocale}.\n`, 'key:', key, 'attr:', attr, 'data:', data);
Expand Down

0 comments on commit db8d5f9

Please sign in to comment.