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

import en from './locales/en.json';
import zh from './locales/zh.json';
import ja from './locales/ja.json';

i18n
    .use(LanguageDetector)
    .use(initReactI18next)
    .init({
        resources: {
            en: { translation: en },
            zh: { translation: zh },
            ja: { translation: ja }
        },
        supportedLngs: ['zh', 'en', 'ja'],
        load: 'languageOnly', // matches 'en-US' -> 'en', 'zh-CN' -> 'zh'
        fallbackLng: 'zh',
        detection: {
            // order: ['querystring', 'cookie', 'localStorage', 'navigator', 'htmlTag', 'path', 'subdomain'],
            order: ['localStorage', 'navigator'],
            caches: ['localStorage'],
        },
        debug: false,
        interpolation: {
            escapeValue: false // not needed for react as it escapes by default
        }
    });

export default i18n;
