index.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import i18n from 'i18next';
  2. import { initReactI18next } from 'react-i18next';
  3. import LanguageDetector from 'i18next-browser-languagedetector';
  4. // Import translations directly for bundling
  5. import en from './locales/en';
  6. import de from './locales/de';
  7. import fr from './locales/fr';
  8. import ja from './locales/ja';
  9. import it from './locales/it';
  10. import ptBR from './locales/pt-BR';
  11. import zhCN from './locales/zh-CN';
  12. import zhTW from './locales/zh-TW';
  13. const resources = {
  14. en: { translation: en },
  15. de: { translation: de },
  16. fr: { translation: fr },
  17. ja: { translation: ja },
  18. it: { translation: it },
  19. 'pt-BR': { translation: ptBR },
  20. 'zh-CN': { translation: zhCN },
  21. 'zh-TW': { translation: zhTW },
  22. };
  23. i18n
  24. .use(LanguageDetector)
  25. .use(initReactI18next)
  26. .init({
  27. resources,
  28. fallbackLng: 'en',
  29. supportedLngs: ['en', 'de', 'fr', 'ja', 'it', 'pt-BR', 'zh-CN', 'zh-TW'],
  30. detection: {
  31. // Order of detection methods
  32. order: ['localStorage', 'navigator', 'htmlTag'],
  33. // Key to use in localStorage
  34. lookupLocalStorage: 'bambutrack_language',
  35. // Cache user language
  36. caches: ['localStorage'],
  37. },
  38. interpolation: {
  39. escapeValue: false, // React already escapes
  40. },
  41. react: {
  42. useSuspense: false,
  43. },
  44. });
  45. export default i18n;
  46. // Helper to get available languages
  47. export const availableLanguages = [
  48. { code: 'en', name: 'English', nativeName: 'English' },
  49. { code: 'de', name: 'German', nativeName: 'Deutsch' },
  50. { code: 'fr', name: 'French', nativeName: 'Français' },
  51. { code: 'ja', name: 'Japanese', nativeName: '日本語' },
  52. { code: 'it', name: 'Italian', nativeName: 'Italiano' },
  53. { code: 'pt-BR', name: 'Portuguese (Brazil)', nativeName: 'Português (Brasil)' },
  54. { code: 'zh-CN', name: 'Chinese (Simplified)', nativeName: '简体中文' },
  55. { code: 'zh-TW', name: 'Chinese (Traditional)', nativeName: '繁體中文' },
  56. ];