i18n: fix crash if language file is missing

This commit is contained in:
Girish Ramakrishnan
2024-08-23 10:20:35 +02:00
parent b6becae396
commit d32819da4e
+2 -2
View File
@@ -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
}