chore(backend): translationHelper logger
This commit is contained in:
parent
6d05978568
commit
55ab0c0b47
2 changed files with 8 additions and 6 deletions
|
@ -1,7 +1,6 @@
|
|||
import { Request, Response } from 'express';
|
||||
import { themes } from '../data/themes.js';
|
||||
import { loadTranslations } from "../util/translationHelper.js";
|
||||
import { FALLBACK_LANG } from '../config.js';
|
||||
import { loadTranslations } from '../util/translationHelper.js';
|
||||
|
||||
interface Translations {
|
||||
curricula_page: {
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import yaml from 'js-yaml';
|
||||
import {FALLBACK_LANG} from "../../config";
|
||||
import {FALLBACK_LANG} from "../../config.js";
|
||||
import { getLogger, Logger } from '../logging/initalize.js';
|
||||
|
||||
const logger: Logger = getLogger();
|
||||
|
||||
export function loadTranslations<T>(language: string): T {
|
||||
try {
|
||||
|
@ -9,10 +12,10 @@ export function loadTranslations<T>(language: string): T {
|
|||
const yamlFile = fs.readFileSync(filePath, 'utf8');
|
||||
return yaml.load(yamlFile) as T;
|
||||
} catch (error) {
|
||||
console.error(
|
||||
`Cannot load translation for ${language}, fallen back to dutch`
|
||||
logger.warn(
|
||||
`Cannot load translation for ${language}, fallen back to dutch`,
|
||||
error
|
||||
);
|
||||
console.error(error);
|
||||
const fallbackPath = path.join(process.cwd(), '_i18n', `${FALLBACK_LANG}.yml`);
|
||||
return yaml.load(fs.readFileSync(fallbackPath, 'utf8')) as T;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue