Untitled
unknown
plain_text
10 months ago
3.4 kB
4
Indexable
// /utils/translations.ts
export type SupportedLanguages = 'EN' | 'DE';
interface NavigationTranslations {
home: string;
gallery: string;
placeholder: string;
help: string;
settings: string;
guide: string;
components: string;
fileConventions: string;
functions: string;
configOptions: string;
cli: string;
edgeRuntime: string;
accessibility: string;
fastRefresh: string;
compiler: string;
browsers: string;
turbopack: string;
}
interface CommonTranslations {
theme: string;
language: string;
english: string;
german: string;
aiAssistant: string;
}
interface BinTranslations {
paper: string;
plastic: string;
metal: string;
glass: string;
organic: string;
residual: string;
// Add other bin types as needed
}
interface Translations {
navigation: NavigationTranslations;
common: CommonTranslations;
bins: BinTranslations;
}
export const translations: Record<SupportedLanguages, Translations> = {
EN: {
navigation: {
home: "Home",
gallery: "Gallery",
placeholder: "Placeholder",
help: "Help",
settings: "Settings",
guide: "(Usage) Guide",
components: "Components",
fileConventions: "File Conventions",
functions: "Functions",
configOptions: "next.config.js Options",
cli: "CLI",
edgeRuntime: "Edge Runtime",
accessibility: "Accessibility",
fastRefresh: "Fast Refresh",
compiler: "Next.js Compiler",
browsers: "Supported Browsers",
turbopack: "Turbopack"
},
common: {
theme: "Theme",
language: "Language",
english: "English",
german: "German",
aiAssistant: "AI Recycling Assistant"
},
bins: {
paper: "Paper",
plastic: "Plastic",
metal: "Metal",
glass: "Glass",
organic: "Organic",
residual: "Residual"
}
},
DE: {
navigation: {
home: "Startseite",
gallery: "Galerie",
placeholder: "Platzhalter",
help: "Hilfe",
settings: "Einstellungen",
guide: "Bedienungsanleitung",
components: "Komponenten",
fileConventions: "Dateikonventionen",
functions: "Funktionen",
configOptions: "next.config.js Optionen",
cli: "CLI",
edgeRuntime: "Edge-Laufzeit",
accessibility: "Barrierefreiheit",
fastRefresh: "Schnelle Aktualisierung",
compiler: "Next.js Compiler",
browsers: "Unterstützte Browser",
turbopack: "Turbopack"
},
common: {
theme: "Design",
language: "Sprache",
english: "Englisch",
german: "Deutsch",
aiAssistant: "KI-Recycling-Assistent"
},
bins: {
paper: "Papier",
plastic: "Kunststoff",
metal: "Metall",
glass: "Glas",
organic: "Organisch",
residual: "Restmüll"
}
}
};
export function useTranslation(language: SupportedLanguages = 'EN') {
return {
t: (key: string) => {
const keys = key.split('.');
let value: any = translations[language];
for (const k of keys) {
if (value && typeof value === 'object') {
value = value[k];
} else {
return key;
}
}
return value || key;
}
};
}Editor is loading...
Leave a Comment