Implementiere i18n für Frontend, Admin und Datenbank

This commit is contained in:
Hördle Bot
2025-11-28 15:36:06 +01:00
parent 9df9a808bf
commit 771d0d06f3
37 changed files with 3717 additions and 560 deletions

41
lib/i18n.ts Normal file
View File

@@ -0,0 +1,41 @@
export type LocalizedString = {
[key: string]: string;
};
export function getLocalizedValue(
value: any,
locale: string,
fallback: string = ''
): string {
if (!value) return fallback;
// If it's already a string, return it (backward compatibility or simple values)
if (typeof value === 'string') return value;
// If it's an object, try to get the requested locale
if (typeof value === 'object') {
if (value[locale]) return value[locale];
// Fallback to 'de'
if (value['de']) return value['de'];
// Fallback to 'en'
if (value['en']) return value['en'];
// Fallback to first key
const keys = Object.keys(value);
if (keys.length > 0) return value[keys[0]];
}
return fallback;
}
export function createLocalizedObject(
de: string,
en?: string
): LocalizedString {
return {
de: de.trim(),
en: (en || de).trim()
};
}