79214924

Date: 2024-11-22 12:05:19
Score: 0.5
Natty:
Report link

This is my i18next config:

import i18n from 'i18next';
import {initReactI18next} from 'react-i18next';
import en from './lang/en.json';
import cn from './lang/cn.json';
import bh from './lang/bh.json';

const resources = {
  en: {
    translation: en,
  },
  cn: {
    translation: cn,
  },
  bh: {
    translation: bh,
  },
};

export type TSupportedLanguages = keyof typeof resources;
export const SupportedLanguages = Object.keys(
  resources,
) as (keyof typeof resources)[]; // I turn object keys to an array

i18n
  .use(initReactI18next) // passes i18n down to react-i18next
  .init({
    compatibilityJSON: 'v3',
    resources,
    fallbackLng: 'en',
    lng: 'en',
    interpolation: {
      escapeValue: false, // react already safes from xss
    },
  });

export default i18n;

later i can use SupportedLanguages as an array of Supported Languages

enter image description here

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Kitani Islam