replace debug() with our custom logger
mostly we want trace() and log(). trace() can be enabled whenever we want by flipping a flag and restarting box
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import assert from 'node:assert';
|
||||
import cloudron from './cloudron.js';
|
||||
import debugModule from 'debug';
|
||||
import logger from './logger.js';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import paths from './paths.js';
|
||||
import safe from 'safetydance';
|
||||
|
||||
const debug = debugModule('box:translation');
|
||||
const { log, trace } = logger('translation');
|
||||
|
||||
|
||||
// to be used together with getTranslations() => { translations, fallback }
|
||||
@@ -45,13 +45,13 @@ function translate(input, assets) {
|
||||
|
||||
async function getTranslations() {
|
||||
const fallbackData = fs.readFileSync(path.join(paths.TRANSLATIONS_DIR, 'en.json'), 'utf8');
|
||||
if (!fallbackData) debug(`getTranslations: Fallback language en not found. ${safe.error.message}`);
|
||||
if (!fallbackData) log(`getTranslations: Fallback language en not found. ${safe.error.message}`);
|
||||
const fallback = safe.JSON.parse(fallbackData) || {};
|
||||
|
||||
const lang = await cloudron.getLanguage();
|
||||
|
||||
const translationData = safe.fs.readFileSync(path.join(paths.TRANSLATIONS_DIR, `${lang}.json`), 'utf8');
|
||||
if (!translationData) debug(`getTranslations: Requested language ${lang} not found. ${safe.error.message}`);
|
||||
if (!translationData) log(`getTranslations: Requested language ${lang} not found. ${safe.error.message}`);
|
||||
const translations = safe.JSON.parse(translationData) || {};
|
||||
|
||||
return { translations, fallback };
|
||||
@@ -60,7 +60,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. %${error.message}`);
|
||||
log(`listLanguages: Failed to list translations. %${error.message}`);
|
||||
return [ 'en' ]; // we always return english to avoid dashboard breakage
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user