lang: unit tests in django/await first loading of dict

This commit is contained in:
AdrienLSH
2024-02-13 14:49:38 +01:00
parent b398134101
commit 157383748f
3 changed files with 34 additions and 4 deletions

View File

@ -8,10 +8,10 @@ export default class LanguageManager {
this.currentLang = 'en'
this.chosenLang = localStorage.getItem('preferedLanguage') || this.currentLang;
if (this.chosenLang !== this.currentLang && this.availableLanguages.includes(this.chosenLang)) {
this.translatePage();
this.loading = this.translatePage();
this.currentLang = this.chosenLang;
} else {
this.loadDict(this.chosenLang);
this.loading = this.loadDict(this.chosenLang);
}
document.getElementById('languageDisplay').innerHTML =
document.querySelector(`#languageSelector > [value=${this.currentLang}]`)?.innerHTML;
@ -61,6 +61,10 @@ export default class LanguageManager {
this.dict = await response.json();
}
async waitLoading() {
await this.loading;
}
get(key, defaultTxt) {
if (!this.dict)
return defaultTxt;