mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2026-05-29 22:54:42 +00:00
Merge branch 'translate' into weblate-pairdrop-pairdrop-spa
This commit is contained in:
@@ -5,7 +5,7 @@ class Localization {
|
|||||||
Localization.translations = {};
|
Localization.translations = {};
|
||||||
Localization.defaultTranslations = {};
|
Localization.defaultTranslations = {};
|
||||||
|
|
||||||
const initialLocale = Localization.supportedOrDefault(Localization.browserLocales());
|
const initialLocale = Localization.supportedOrDefault(navigator.languages);
|
||||||
|
|
||||||
Localization.setLocale(initialLocale)
|
Localization.setLocale(initialLocale)
|
||||||
.then(_ => {
|
.then(_ => {
|
||||||
@@ -21,17 +21,13 @@ class Localization {
|
|||||||
return locales.find(Localization.isSupported) || Localization.defaultLocale;
|
return locales.find(Localization.isSupported) || Localization.defaultLocale;
|
||||||
}
|
}
|
||||||
|
|
||||||
static browserLocales() {
|
|
||||||
return navigator.languages.map(locale =>
|
|
||||||
locale.split("-")[0]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
static async setLocale(newLocale) {
|
static async setLocale(newLocale) {
|
||||||
if (newLocale === Localization.locale) return false;
|
if (newLocale === Localization.locale) return false;
|
||||||
const firstTranslation = !Localization.locale
|
|
||||||
|
const isFirstTranslation = !Localization.locale
|
||||||
|
|
||||||
Localization.defaultTranslations = await Localization.fetchTranslationsFor(Localization.defaultLocale);
|
Localization.defaultTranslations = await Localization.fetchTranslationsFor(Localization.defaultLocale);
|
||||||
|
|
||||||
const newTranslations = await Localization.fetchTranslationsFor(newLocale);
|
const newTranslations = await Localization.fetchTranslationsFor(newLocale);
|
||||||
|
|
||||||
if(!newTranslations) return false;
|
if(!newTranslations) return false;
|
||||||
@@ -39,7 +35,7 @@ class Localization {
|
|||||||
Localization.locale = newLocale;
|
Localization.locale = newLocale;
|
||||||
Localization.translations = newTranslations;
|
Localization.translations = newTranslations;
|
||||||
|
|
||||||
if (firstTranslation) {
|
if (isFirstTranslation) {
|
||||||
Events.fire("translation-loaded");
|
Events.fire("translation-loaded");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,6 +81,7 @@ class Localization {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let lastKey = keys[keys.length-1];
|
let lastKey = keys[keys.length-1];
|
||||||
|
|
||||||
if (attr) lastKey += "_" + attr;
|
if (attr) lastKey += "_" + attr;
|
||||||
|
|
||||||
let translation = translationCandidates[lastKey];
|
let translation = translationCandidates[lastKey];
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ class Localization {
|
|||||||
Localization.translations = {};
|
Localization.translations = {};
|
||||||
Localization.defaultTranslations = {};
|
Localization.defaultTranslations = {};
|
||||||
|
|
||||||
const initialLocale = Localization.supportedOrDefault(Localization.browserLocales());
|
const initialLocale = Localization.supportedOrDefault(navigator.languages);
|
||||||
|
|
||||||
Localization.setLocale(initialLocale)
|
Localization.setLocale(initialLocale)
|
||||||
.then(_ => {
|
.then(_ => {
|
||||||
@@ -21,17 +21,13 @@ class Localization {
|
|||||||
return locales.find(Localization.isSupported) || Localization.defaultLocale;
|
return locales.find(Localization.isSupported) || Localization.defaultLocale;
|
||||||
}
|
}
|
||||||
|
|
||||||
static browserLocales() {
|
|
||||||
return navigator.languages.map(locale =>
|
|
||||||
locale.split("-")[0]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
static async setLocale(newLocale) {
|
static async setLocale(newLocale) {
|
||||||
if (newLocale === Localization.locale) return false;
|
if (newLocale === Localization.locale) return false;
|
||||||
const firstTranslation = !Localization.locale
|
|
||||||
|
const isFirstTranslation = !Localization.locale
|
||||||
|
|
||||||
Localization.defaultTranslations = await Localization.fetchTranslationsFor(Localization.defaultLocale);
|
Localization.defaultTranslations = await Localization.fetchTranslationsFor(Localization.defaultLocale);
|
||||||
|
|
||||||
const newTranslations = await Localization.fetchTranslationsFor(newLocale);
|
const newTranslations = await Localization.fetchTranslationsFor(newLocale);
|
||||||
|
|
||||||
if(!newTranslations) return false;
|
if(!newTranslations) return false;
|
||||||
@@ -39,7 +35,7 @@ class Localization {
|
|||||||
Localization.locale = newLocale;
|
Localization.locale = newLocale;
|
||||||
Localization.translations = newTranslations;
|
Localization.translations = newTranslations;
|
||||||
|
|
||||||
if (firstTranslation) {
|
if (isFirstTranslation) {
|
||||||
Events.fire("translation-loaded");
|
Events.fire("translation-loaded");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,6 +81,7 @@ class Localization {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let lastKey = keys[keys.length-1];
|
let lastKey = keys[keys.length-1];
|
||||||
|
|
||||||
if (attr) lastKey += "_" + attr;
|
if (attr) lastKey += "_" + attr;
|
||||||
|
|
||||||
let translation = translationCandidates[lastKey];
|
let translation = translationCandidates[lastKey];
|
||||||
|
|||||||
Reference in New Issue
Block a user