import sysConfig from "@/config"
import tool from '@/utils/tool'
import { createI18n } from 'vue-i18n'
import el_zh_cn from 'element-plus/lib/locale/lang/zh-cn'
import el_en from 'element-plus/lib/locale/lang/en'

import zh_cn from './lang/zh-CN.js'
import en_us from './lang/en-US.js'

const messages = {
	'zh-CN': {
		el: el_zh_cn,
		...zh_cn
	},
	'en-US': {
		el: el_en,
		...en_us
	}
}

const i18n = createI18n({
	locale: getLangStorage() || sysConfig.LANG,
	fallbackLocale: 'zh-CN',
	globalInjection: true,
	messages,
})

function getLangStorage() {
	if (tool.data.get("APP_LANG"))
	{
		if (tool.data.get("APP_LANG") != "zh-CN" && tool.data.get("APP_LANG") != "en-US") 
		{
			tool.data.remove("APP_LANG");
			return null;
		}
	}
	return tool.data.get("APP_LANG");
}

export function $t(args) {
	return i18n.global.tc(args)
}

export default i18n;
