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 { Request, Response } from 'express';
|
||||||
import { themes } from '../data/themes.js';
|
import { themes } from '../data/themes.js';
|
||||||
import { loadTranslations } from "../util/translationHelper.js";
|
import { loadTranslations } from '../util/translationHelper.js';
|
||||||
import { FALLBACK_LANG } from '../config.js';
|
|
||||||
|
|
||||||
interface Translations {
|
interface Translations {
|
||||||
curricula_page: {
|
curricula_page: {
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import yaml from 'js-yaml';
|
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 {
|
export function loadTranslations<T>(language: string): T {
|
||||||
try {
|
try {
|
||||||
|
@ -9,10 +12,10 @@ export function loadTranslations<T>(language: string): T {
|
||||||
const yamlFile = fs.readFileSync(filePath, 'utf8');
|
const yamlFile = fs.readFileSync(filePath, 'utf8');
|
||||||
return yaml.load(yamlFile) as T;
|
return yaml.load(yamlFile) as T;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(
|
logger.warn(
|
||||||
`Cannot load translation for ${language}, fallen back to dutch`
|
`Cannot load translation for ${language}, fallen back to dutch`,
|
||||||
|
error
|
||||||
);
|
);
|
||||||
console.error(error);
|
|
||||||
const fallbackPath = path.join(process.cwd(), '_i18n', `${FALLBACK_LANG}.yml`);
|
const fallbackPath = path.join(process.cwd(), '_i18n', `${FALLBACK_LANG}.yml`);
|
||||||
return yaml.load(fs.readFileSync(fallbackPath, 'utf8')) as T;
|
return yaml.load(fs.readFileSync(fallbackPath, 'utf8')) as T;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue