import axios from 'axios'
import zhCN from '@public/locales/zh-CN.json'
import enUS from '@public/locales/en-US.json'
import thTH from '@public/locales/th-TH.json'
import zhTW from '@public/locales/zh-TW.json'
import viVN from '@public/locales/vi-VN.json'
import { Language } from '@/constants/language'
import { createI18n } from 'vue-i18n'
import { localData } from '../storage'

export const i18n = createI18n({
    locale: localData.getValue('appLanguage'),
    fallbackLocale: Language.English,
    messages: {
        [Language.Simplified]: zhCN,
        [Language.Traditional]: zhTW,
        [Language.English]: enUS,
        [Language.Thai]: thTH,
        [Language.Vietnamese]: viVN,
    }
})

axios('./locales/extras/zh-CN.json').then((res) => {
    i18n.global.mergeLocaleMessage(Language.Simplified, res.data)
})

axios('./locales/extras/zh-TW.json').then((res) => {
    i18n.global.mergeLocaleMessage(Language.Traditional, res.data)
})

axios('./locales/extras/en-US.json').then((res) => {
    i18n.global.mergeLocaleMessage(Language.English, res.data)
})

axios('./locales/extras/th-TH.json').then((res) => {
    i18n.global.mergeLocaleMessage(Language.Thai, res.data)
})

axios('./locales/extras/vi-VN.json').then((res) => {
    i18n.global.mergeLocaleMessage(Language.Vietnamese, res.data)
})