🐛(i18n): 修复按需加载下 i18n 的注册问题
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { createI18n } from "vue-i18n";
|
||||
import { getCurrentInstance } from "vue";
|
||||
import { createI18n, useI18n as __useI18n__ } from "vue-i18n";
|
||||
import zh_CN from "./locales/zh_CN";
|
||||
import en_US from "./locales/en_US";
|
||||
|
||||
@@ -11,4 +12,18 @@ const i18n = createI18n({
|
||||
},
|
||||
});
|
||||
|
||||
export function useI18n() {
|
||||
let i18nInstance;
|
||||
const app = getCurrentInstance()?.appContext.app;
|
||||
|
||||
try {
|
||||
i18nInstance = __useI18n__();
|
||||
} catch (e) {
|
||||
app?.use(i18n);
|
||||
i18nInstance = __useI18n__();
|
||||
}
|
||||
|
||||
return i18nInstance;
|
||||
}
|
||||
|
||||
export default i18n;
|
||||
|
||||
Reference in New Issue
Block a user