mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-04-20 23:16:13 -04:00
Load initial translation as proper async call instead of using an event
This commit is contained in:
parent
021c67bd77
commit
5a2ec9c670
2 changed files with 22 additions and 22 deletions
|
@ -14,13 +14,6 @@ class Localization {
|
||||||
Localization.initialLocale = storedLanguageCode && Localization.isSupported(storedLanguageCode)
|
Localization.initialLocale = storedLanguageCode && Localization.isSupported(storedLanguageCode)
|
||||||
? storedLanguageCode
|
? storedLanguageCode
|
||||||
: Localization.systemLocale;
|
: Localization.systemLocale;
|
||||||
|
|
||||||
Localization
|
|
||||||
.setTranslation(Localization.initialLocale)
|
|
||||||
.then(_ => {
|
|
||||||
console.log("Initial translation successful.");
|
|
||||||
Events.fire("initial-translation-loaded");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static isSupported(locale) {
|
static isSupported(locale) {
|
||||||
|
@ -41,6 +34,10 @@ class Localization {
|
||||||
|| Localization.defaultLocale;
|
|| Localization.defaultLocale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async setInitialTranslation() {
|
||||||
|
await Localization.setTranslation(Localization.initialLocale)
|
||||||
|
}
|
||||||
|
|
||||||
static async setTranslation(locale) {
|
static async setTranslation(locale) {
|
||||||
if (!locale) locale = Localization.systemLocale;
|
if (!locale) locale = Localization.systemLocale;
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,13 @@ class PairDrop {
|
||||||
const themeUI = new ThemeUI();
|
const themeUI = new ThemeUI();
|
||||||
const backgroundCanvas = new BackgroundCanvas();
|
const backgroundCanvas = new BackgroundCanvas();
|
||||||
|
|
||||||
Events.on('initial-translation-loaded', _ => {
|
// Translate page before fading in
|
||||||
|
const localization = new Localization();
|
||||||
|
localization
|
||||||
|
.setInitialTranslation()
|
||||||
|
.then(() => {
|
||||||
|
console.log("Initial translation successful.");
|
||||||
|
|
||||||
// FooterUI needs translations
|
// FooterUI needs translations
|
||||||
const footerUI = new FooterUI();
|
const footerUI = new FooterUI();
|
||||||
|
|
||||||
|
@ -30,10 +36,7 @@ class PairDrop {
|
||||||
|
|
||||||
// Load deferred assets
|
// Load deferred assets
|
||||||
this.loadDeferredAssets();
|
this.loadDeferredAssets();
|
||||||
});
|
})
|
||||||
|
|
||||||
// Translate page -> fires 'initial-translation-loaded' on finish
|
|
||||||
const localization = new Localization();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
registerServiceWorker() {
|
registerServiceWorker() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue