mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-04-23 08:16:19 -04:00
Merge branch 'add_transfer_notes' into sw_digester
This commit is contained in:
commit
db8d5f97ea
1 changed files with 16 additions and 16 deletions
|
@ -2,28 +2,28 @@ 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() {
|
||||
|
@ -31,7 +31,7 @@ class Localization {
|
|||
}
|
||||
|
||||
static currentLocaleIsDefault() {
|
||||
return Localization.locale === Localization.defaultLocale
|
||||
return Localization.locale === Localization.localeDefault
|
||||
}
|
||||
|
||||
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
|
||||
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();
|
||||
|
@ -68,7 +68,7 @@ class Localization {
|
|||
|
||||
|
||||
Logger.debug("Page successfully translated",
|
||||
`System language: ${Localization.systemLocale}`,
|
||||
`System language: ${Localization.localeSystem}`,
|
||||
`Selected language: ${locale}`
|
||||
);
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue