| | |
| | | /* |
| | | * @Description: file content |
| | | * @Author: Ben Lin |
| | | * @version: |
| | | * @Date: 2024-06-18 15:09:47 |
| | | * @LastEditors: Ben Lin |
| | | * @LastEditTime: 2024-07-17 04:31:26 |
| | | */ |
| | | import type { App } from 'vue'; |
| | | import type { I18n, I18nOptions } from 'vue-i18n'; |
| | | |
| | | import { createI18n } from 'vue-i18n'; |
| | | import { setHtmlPageLang, setLoadLocalePool } from './helper'; |
| | | import { localeSetting } from '/@/settings/localeSetting'; |
| | | import { useLocaleStoreWithOut } from '/@/store/modules/locale'; |
| | | import { localeSetting } from '@/settings/localeSetting'; |
| | | import { useLocaleStoreWithOut } from '@/store/modules/locale'; |
| | | |
| | | const { fallback, availableLocales } = localeSetting; |
| | | |
| | | export let i18n: ReturnType<typeof createI18n>; |
| | | |
| | | // eslint-disable-next-line @typescript-eslint/no-unused-vars |
| | | function getLangJson(enObj, cnObj) { |
| | | const json = {}; |
| | | if (typeof enObj === 'object') { |
| | | for (const key in enObj) { |
| | | if ( |
| | | Object.prototype.hasOwnProperty.call(enObj, key) && |
| | | Object.prototype.hasOwnProperty.call(cnObj, key) |
| | | ) { |
| | | const en = enObj[key]; |
| | | const cn = cnObj[key]; |
| | | if (typeof en === 'object') { |
| | | json[key] = getLangJson(en, cn); // 递归处理子对象 |
| | | } else { |
| | | json[key] = {}; |
| | | json[key].en = en; |
| | | json[key].cn = cn; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return json; |
| | | } |
| | | |
| | | async function createI18nOptions(): Promise<I18nOptions> { |
| | | const localeStore = useLocaleStoreWithOut(); |
| | | const locale = localeStore.getLocale; |
| | | const defaultLocal = await import(`./lang/${locale}.ts`); |
| | | const message = defaultLocal.default?.apiMessage ?? {}; |
| | | //生成语言包文件 |
| | | // const en = (await import(`./lang/${'en'}.ts`)).default?.message; |
| | | // const cn = defaultLocal.default?.message; |
| | | // let lang = getLangJson(en, cn); |
| | | const message = defaultLocal.default?.message ?? {}; |
| | | |
| | | setHtmlPageLang(locale); |
| | | setLoadLocalePool((loadLocalePool) => { |