Convert translator callbacks to async/await (#3048)

Co-authored-by: veeck <michael@veeck.de>
This commit is contained in:
Veeck 2023-02-21 22:58:18 +01:00 committed by GitHub
parent a23769156e
commit 2b792cdbb8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 92 additions and 119 deletions

View file

@ -302,10 +302,8 @@ const Module = Class.extend({
/**
* Load all translations.
*
* @param {Function} callback Function called when done.
*/
loadTranslations(callback) {
async loadTranslations() {
const translations = this.getTranslations() || {};
const language = config.language.toLowerCase();
@ -313,7 +311,6 @@ const Module = Class.extend({
const fallbackLanguage = languages[0];
if (languages.length === 0) {
callback();
return;
}
@ -321,17 +318,14 @@ const Module = Class.extend({
const translationsFallbackFile = translations[fallbackLanguage];
if (!translationFile) {
Translator.load(this, translationsFallbackFile, true, callback);
return;
return Translator.load(this, translationsFallbackFile, true);
}
Translator.load(this, translationFile, false, () => {
if (translationFile !== translationsFallbackFile) {
Translator.load(this, translationsFallbackFile, true, callback);
} else {
callback();
}
});
await Translator.load(this, translationFile, false);
if (translationFile !== translationsFallbackFile) {
return Translator.load(this, translationsFallbackFile, true);
}
},
/**