|
@@ -7,47 +7,35 @@ import { interpolateTemplate } from "./locale/utils";
|
|
|
import vEllipsis from './directives/v-ellipsis'
|
|
import vEllipsis from './directives/v-ellipsis'
|
|
|
import { createI18n } from "vue-i18n";
|
|
import { createI18n } from "vue-i18n";
|
|
|
import { routeInterceptor } from '@/utils/routeInterceptor.js'
|
|
import { routeInterceptor } from '@/utils/routeInterceptor.js'
|
|
|
|
|
+import { lang } from '@/composables/config'
|
|
|
|
|
+import { watch } from "vue";
|
|
|
|
|
+import vT from './directives/v-t'
|
|
|
export const i18n = createI18n({
|
|
export const i18n = createI18n({
|
|
|
legacy: false,
|
|
legacy: false,
|
|
|
allowComposition: true,
|
|
allowComposition: true,
|
|
|
- locale: uni.getStorageSync("lang") || "cn",
|
|
|
|
|
|
|
+ locale: lang.value || "cn",
|
|
|
messages,
|
|
messages,
|
|
|
});
|
|
});
|
|
|
|
|
+globalThis.__i18n = i18n
|
|
|
const pinia = createPinia();
|
|
const pinia = createPinia();
|
|
|
|
|
|
|
|
-const originalT = i18n.global.t;
|
|
|
|
|
-i18n.global.t = function (key, param1, param2) {
|
|
|
|
|
- const result = originalT.call(this, key, param1, param2);
|
|
|
|
|
- if (param1 === undefined && param2 === undefined) {
|
|
|
|
|
- return result;
|
|
|
|
|
- }
|
|
|
|
|
- let values = param1;
|
|
|
|
|
- if (
|
|
|
|
|
- typeof param1 === "object" &&
|
|
|
|
|
- !Array.isArray(param1) &&
|
|
|
|
|
- Array.isArray(param2)
|
|
|
|
|
- ) {
|
|
|
|
|
- values = param1;
|
|
|
|
|
- } else if (Array.isArray(param1)) {
|
|
|
|
|
- values = param1;
|
|
|
|
|
- } else if (typeof param1 === "object" && param1 !== null) {
|
|
|
|
|
- values = param1;
|
|
|
|
|
- } else if (param1 !== undefined) {
|
|
|
|
|
- values = [param1];
|
|
|
|
|
- }
|
|
|
|
|
- return interpolateTemplate(result, values);
|
|
|
|
|
-};
|
|
|
|
|
// #ifdef VUE3
|
|
// #ifdef VUE3
|
|
|
import { createSSRApp } from "vue";
|
|
import { createSSRApp } from "vue";
|
|
|
export function createApp() {
|
|
export function createApp() {
|
|
|
const app = createSSRApp(App);
|
|
const app = createSSRApp(App);
|
|
|
- app.directive('ellipsis', vEllipsis)
|
|
|
|
|
|
|
+ app.directive('ellipsis', vEllipsis);
|
|
|
app.use(uviewPlus);
|
|
app.use(uviewPlus);
|
|
|
app.use(pinia);
|
|
app.use(pinia);
|
|
|
app.use(i18n);
|
|
app.use(i18n);
|
|
|
- routeInterceptor.install()
|
|
|
|
|
- return {
|
|
|
|
|
- app,
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ app.directive('t', vT);
|
|
|
|
|
+ // 保持 locale 与存储 lang 同步(可选)
|
|
|
|
|
+ watch(() => lang.value, (val) => {
|
|
|
|
|
+ if (!val) return;
|
|
|
|
|
+ if (i18n?.global?.locale?.value !== undefined) {
|
|
|
|
|
+ i18n.global.locale.value = val;
|
|
|
|
|
+ }
|
|
|
|
|
+ }, { immediate: true, flush: 'sync' });
|
|
|
|
|
+ routeInterceptor.install();
|
|
|
|
|
+ return { app };
|
|
|
}
|
|
}
|
|
|
// #endif
|
|
// #endif
|