import i18n from 'i18next'
import { initReactI18next } from 'react-i18next'
import LanguageDetector from 'i18next-browser-languagedetector'

import en from './locales/en.json'
import ko from './locales/ko.json'
import ja from './locales/ja.json'
import zh from './locales/zh.json'
import zh_TW from './locales/zh_TW.json'
import de from './locales/de.json'
import es from './locales/es.json'
import fr from './locales/fr.json'
import it from './locales/it.json'
import pt from './locales/pt.json'
import ru from './locales/ru.json'
import th from './locales/th.json'
import vi from './locales/vi.json'

export const LANGUAGES = [
  { code: 'en',    label: 'English' },
  { code: 'ko',    label: '한국어' },
  { code: 'ja',    label: '日本語' },
  { code: 'zh',    label: '简体中文' },
  { code: 'zh-TW', label: '繁體中文' },
  { code: 'de',    label: 'Deutsch' },
  { code: 'es',    label: 'Español' },
  { code: 'fr',    label: 'Français' },
  { code: 'it',    label: 'Italiano' },
  { code: 'pt',    label: 'Português' },
  { code: 'ru',    label: 'Русский' },
  { code: 'th',    label: 'ภาษาไทย' },
  { code: 'vi',    label: 'Tiếng Việt' },
]

i18n
  .use(LanguageDetector)
  .use(initReactI18next)
  .init({
    resources: {
      en:    { translation: en },
      ko:    { translation: ko },
      ja:    { translation: ja },
      zh:    { translation: zh },
      'zh-TW': { translation: zh_TW },
      de:    { translation: de },
      es:    { translation: es },
      fr:    { translation: fr },
      it:    { translation: it },
      pt:    { translation: pt },
      ru:    { translation: ru },
      th:    { translation: th },
      vi:    { translation: vi },
    },
    fallbackLng: 'en',
    interpolation: { escapeValue: false },
    detection: {
      order: ['localStorage', 'navigator'],
      caches: ['localStorage'],
    },
  })

export default i18n
