All files / src/i18n index.ts

56.25% Statements 9/16
0% Branches 0/4
0% Functions 0/2
64.28% Lines 9/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38119x 119x 119x 119x   119x     119x               119x             119x                         119x  
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import en from './locales/en.json';
import tr from './locales/tr.json';
 
export const SUPPORTED_LOCALES = ['en', 'tr'] as const;
export type Locale = (typeof SUPPORTED_LOCALES)[number];
 
export function isSupportedLocale(value: string | null | undefined): value is Locale {
  return value === 'en' || value === 'tr';
}
 
/**
 * Picks the best supported locale for a device language tag, falling back to
 * English. e.g. "tr-TR" -> "tr", "en-US" -> "en", "fr-FR" -> "en".
 */
export function resolveLocale(deviceTag: string | null | undefined): Locale {
  Iif (!deviceTag) return 'en';
  const lower = deviceTag.toLowerCase();
  Iif (lower.startsWith('tr')) return 'tr';
  return 'en';
}
 
void i18n.use(initReactI18next).init({
  resources: {
    en: { translation: en },
    tr: { translation: tr },
  },
  lng: 'en',
  fallbackLng: 'en',
  interpolation: { escapeValue: false },
  returnNull: false,
  // We keep our own mutable locale via LocaleContext; i18next is just the engine.
  react: { useSuspense: false },
});
 
export default i18n;