make TRANSLATIONS_DIR a constant
This commit is contained in:
@@ -14,8 +14,6 @@ const assert = require('assert'),
|
||||
paths = require('./paths.js'),
|
||||
safe = require('safetydance');
|
||||
|
||||
const TRANSLATION_FOLDER = path.join(paths.DASHBOARD_DIR, 'translation');
|
||||
|
||||
// to be used together with getTranslations() => { translations, fallback }
|
||||
function translate(input, assets) {
|
||||
assert.strictEqual(typeof input, 'string');
|
||||
@@ -51,19 +49,19 @@ function translate(input, assets) {
|
||||
}
|
||||
|
||||
async function getTranslations() {
|
||||
const fallback = safe.JSON.parse(fs.readFileSync(path.join(TRANSLATION_FOLDER, 'en.json'), 'utf8'));
|
||||
const fallback = safe.JSON.parse(fs.readFileSync(path.join(paths.TRANSLATIONS_DIR, 'en.json'), 'utf8'));
|
||||
if (!fallback) debug(`getTranslations: Fallback language en not found. ${safe.error.message}`);
|
||||
|
||||
const lang = await cloudron.getLanguage();
|
||||
|
||||
const translations = safe.JSON.parse(fs.readFileSync(path.join(TRANSLATION_FOLDER, lang + '.json'), 'utf8'));
|
||||
const translations = safe.JSON.parse(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 || {} };
|
||||
}
|
||||
|
||||
async function listLanguages() {
|
||||
const [error, result] = await safe(fs.promises.readdir(TRANSLATION_FOLDER));
|
||||
const [error, result] = await safe(fs.promises.readdir(paths.TRANSLATIONS_DIR));
|
||||
if (error) {
|
||||
debug('listLanguages: Failed to list translations. %o', error);
|
||||
return [ 'en' ]; // we always return english to avoid dashboard breakage
|
||||
|
||||
Reference in New Issue
Block a user