i18n: fix crash if language file is missing
This commit is contained in:
+2
-2
@@ -54,7 +54,7 @@ async function getTranslations() {
|
||||
|
||||
const lang = await cloudron.getLanguage();
|
||||
|
||||
const translations = safe.JSON.parse(fs.readFileSync(path.join(paths.TRANSLATIONS_DIR, lang + '.json'), 'utf8'));
|
||||
const translations = safe.JSON.parse(safe.fs.readFileSync(path.join(paths.TRANSLATIONS_DIR, `${lang}.json`), 'utf8'));
|
||||
if (!translations) debug(`getTranslations: Requested language ${lang} not found. ${safe.error.message}`);
|
||||
|
||||
return { translations: translations || {}, fallback: fallback || {} };
|
||||
@@ -63,7 +63,7 @@ async function getTranslations() {
|
||||
async function listLanguages() {
|
||||
const [error, result] = await safe(fs.promises.readdir(paths.TRANSLATIONS_DIR));
|
||||
if (error) {
|
||||
debug('listLanguages: Failed to list translations. %o', error);
|
||||
debug(`listLanguages: Failed to list translations. %${error.message}`);
|
||||
return [ 'en' ]; // we always return english to avoid dashboard breakage
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user