Untitled

 avatar
unknown
plain_text
a month ago
2.8 kB
3
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 Translations {
  navigation: NavigationTranslations;
  common: CommonTranslations;
}

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"
    }
  },
  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"
    }
  }
};

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;
    }
  };
}
Leave a Comment