fix: util translation helper
This commit is contained in:
parent
80fa6b9f94
commit
a8f6f5f776
4 changed files with 27 additions and 23 deletions
|
@ -1,39 +1,19 @@
|
|||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import yaml from 'js-yaml';
|
||||
import { Request, Response } from 'express';
|
||||
import { themes } from '../data/themes.js';
|
||||
import { loadTranslations } from "../util/translationHelper.js";
|
||||
|
||||
interface Translations {
|
||||
curricula_page: {
|
||||
[key: string]: { title: string; description?: string }; // Optioneel veld description
|
||||
[key: string]: { title: string; description?: string };
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Laadt de vertalingen uit een YAML-bestand
|
||||
*/
|
||||
function loadTranslations(language: string): Translations {
|
||||
try {
|
||||
const filePath = path.join(process.cwd(), '_i18n', `${language}.yml`);
|
||||
const yamlFile = fs.readFileSync(filePath, 'utf8');
|
||||
return yaml.load(yamlFile) as Translations;
|
||||
} catch (error) {
|
||||
console.error(
|
||||
`Kan vertaling niet laden voor ${language}, fallback naar Nederlands`
|
||||
);
|
||||
console.error(error);
|
||||
const fallbackPath = path.join(process.cwd(), '_i18n', 'nl.yml');
|
||||
return yaml.load(fs.readFileSync(fallbackPath, 'utf8')) as Translations;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /themes → Haalt de lijst met thema's op inclusief vertalingen
|
||||
*/
|
||||
export function getThemes(req: Request, res: Response) {
|
||||
const language = (req.query.language as string)?.toLowerCase() || 'nl';
|
||||
const translations = loadTranslations(language);
|
||||
const translations = loadTranslations<Translations>(language);
|
||||
|
||||
const themeList = themes.map((theme) => {
|
||||
return {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue