chore(backend): translationHelper logger

This commit is contained in:
Tibo De Peuter 2025-03-04 16:53:39 +01:00
parent 6d05978568
commit 55ab0c0b47
Signed by: tdpeuter
GPG key ID: 38297DE43F75FFE2
2 changed files with 8 additions and 6 deletions

View file

@ -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: {

View file

@ -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;
}