mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-04-20 15:06:15 -04:00
Refactor static variable names
This commit is contained in:
parent
5f6d330386
commit
51299bcf73
1 changed files with 15 additions and 15 deletions
|
@ -2,28 +2,28 @@ class Localization {
|
||||||
constructor() {
|
constructor() {
|
||||||
Localization.$htmlRoot = document.querySelector('html');
|
Localization.$htmlRoot = document.querySelector('html');
|
||||||
|
|
||||||
Localization.defaultLocale = "en";
|
Localization.localeDefault = "en";
|
||||||
Localization.supportedLocales = ["ar", "ca", "de", "en", "es", "fr", "id", "it", "ja", "kn", "nb", "nl", "pt-BR", "ro", "ru", "tr", "zh-CN"];
|
Localization.localesSupported = ["ar", "ca", "de", "en", "es", "fr", "id", "it", "ja", "kn", "nb", "nl", "pt-BR", "ro", "ru", "tr", "zh-CN"];
|
||||||
Localization.supportedLocalesRtl = ["ar"];
|
Localization.localesRtl = ["ar"];
|
||||||
|
|
||||||
Localization.translations = {};
|
Localization.translations = {};
|
||||||
Localization.translationsDefaultLocale = {};
|
Localization.translationsDefaultLocale = {};
|
||||||
|
|
||||||
Localization.systemLocale = Localization.getSupportedOrDefaultLocales(navigator.languages);
|
Localization.localeSystem = Localization.getSupportedOrDefaultLocales(navigator.languages);
|
||||||
|
|
||||||
let storedLanguageCode = localStorage.getItem('language_code');
|
let storedLanguageCode = localStorage.getItem('language_code');
|
||||||
|
|
||||||
Localization.initialLocale = storedLanguageCode && Localization.localeIsSupported(storedLanguageCode)
|
Localization.localeInitial = storedLanguageCode && Localization.localeIsSupported(storedLanguageCode)
|
||||||
? storedLanguageCode
|
? storedLanguageCode
|
||||||
: Localization.systemLocale;
|
: Localization.localeSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
static localeIsSupported(locale) {
|
static localeIsSupported(locale) {
|
||||||
return Localization.supportedLocales.indexOf(locale) > -1;
|
return Localization.localesSupported.indexOf(locale) > -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static localeIsRtl(locale) {
|
static localeIsRtl(locale) {
|
||||||
return Localization.supportedLocalesRtl.indexOf(locale) > -1;
|
return Localization.localesRtl.indexOf(locale) > -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static currentLocaleIsRtl() {
|
static currentLocaleIsRtl() {
|
||||||
|
@ -31,7 +31,7 @@ class Localization {
|
||||||
}
|
}
|
||||||
|
|
||||||
static currentLocaleIsDefault() {
|
static currentLocaleIsDefault() {
|
||||||
return Localization.locale === Localization.defaultLocale
|
return Localization.locale === Localization.localeDefault
|
||||||
}
|
}
|
||||||
|
|
||||||
static getSupportedOrDefaultLocales(locales) {
|
static getSupportedOrDefaultLocales(locales) {
|
||||||
|
@ -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
|
// If there is no perfect match for browser locales, try generic locales first before resorting to the default locale
|
||||||
return locales.find(Localization.localeIsSupported)
|
return locales.find(Localization.localeIsSupported)
|
||||||
|| localesGeneric.find(Localization.localeIsSupported)
|
|| localesGeneric.find(Localization.localeIsSupported)
|
||||||
|| Localization.defaultLocale;
|
|| Localization.localeDefault;
|
||||||
}
|
}
|
||||||
|
|
||||||
async setInitialTranslation() {
|
async setInitialTranslation() {
|
||||||
await Localization.setTranslation(Localization.initialLocale)
|
await Localization.setTranslation(Localization.localeInitial)
|
||||||
}
|
}
|
||||||
|
|
||||||
static async setTranslation(locale) {
|
static async setTranslation(locale) {
|
||||||
if (!locale) locale = Localization.systemLocale;
|
if (!locale) locale = Localization.localeSystem;
|
||||||
|
|
||||||
await Localization.setLocale(locale)
|
await Localization.setLocale(locale)
|
||||||
await Localization.translatePage();
|
await Localization.translatePage();
|
||||||
|
@ -68,7 +68,7 @@ class Localization {
|
||||||
|
|
||||||
|
|
||||||
Logger.debug("Page successfully translated",
|
Logger.debug("Page successfully translated",
|
||||||
`System language: ${Localization.systemLocale}`,
|
`System language: ${Localization.localeSystem}`,
|
||||||
`Selected language: ${locale}`
|
`Selected language: ${locale}`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -192,7 +192,7 @@ class Localization {
|
||||||
else {
|
else {
|
||||||
// Is not default locale yet
|
// Is not default locale yet
|
||||||
// Get translation for default language with same arguments
|
// 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);
|
translation = this.getTranslation(key, attr, data, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -202,7 +202,7 @@ class Localization {
|
||||||
|
|
||||||
static logTranslationMissingOrBroken(key, attr, data, useDefault) {
|
static logTranslationMissingOrBroken(key, attr, data, useDefault) {
|
||||||
let usedLocale = useDefault
|
let usedLocale = useDefault
|
||||||
? Localization.defaultLocale.toUpperCase()
|
? Localization.localeDefault.toUpperCase()
|
||||||
: Localization.locale.toUpperCase();
|
: Localization.locale.toUpperCase();
|
||||||
|
|
||||||
Logger.warn(`Missing or broken translation for language ${usedLocale}.\n`, 'key:', key, 'attr:', attr, 'data:', data);
|
Logger.warn(`Missing or broken translation for language ${usedLocale}.\n`, 'key:', key, 'attr:', attr, 'data:', data);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue