Replies: 1 comment
-
// this is my code
import type { App } from 'vue';
import type { I18nOptions } from 'vue-i18n';
import cn from './lang/zh-CN/index.json'
import en from './lang/en/index.json'
import { createI18n } from 'vue-i18n';
export let i18n: ReturnType<typeof createI18n>;
export const t = (key: string) => i18n.global.t(key);
const messages={
cn,en
}
async function createI18nOptions(): Promise<I18nOptions> {
return {
legacy: false,
globalInjection: true, // 全局注册$t方法
locale: 'cn',
messages
};
}
// setup i18n instance with glob
export async function setupI18n(app: App) {
const options = await createI18nOptions();
i18n = createI18n(options);
app.use(i18n);
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I using
i18n.global.t
function to translate, it normal workingHowever, I received a typescript error, how can I resolve it?
Beta Was this translation helpful? Give feedback.
All reactions