@uipkge/nuxt 0.1.12 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -42,6 +42,11 @@ const module$1 = defineNuxtModule({
|
|
|
42
42
|
src: resolver.resolve("./runtime/plugin"),
|
|
43
43
|
mode: "server"
|
|
44
44
|
});
|
|
45
|
+
addImports({
|
|
46
|
+
name: "useI18now",
|
|
47
|
+
as: "useI18now",
|
|
48
|
+
from: resolver.resolve("./runtime/composables/useI18n")
|
|
49
|
+
});
|
|
45
50
|
if (nuxt.options.dev) {
|
|
46
51
|
addPlugin({
|
|
47
52
|
src: resolver.resolve("./runtime/plugin.client"),
|
|
@@ -50,12 +55,6 @@ const module$1 = defineNuxtModule({
|
|
|
50
55
|
addPlugin({
|
|
51
56
|
src: resolver.resolve("./runtime/plugin.suppress-warnings")
|
|
52
57
|
});
|
|
53
|
-
addImports({
|
|
54
|
-
name: "useI18n",
|
|
55
|
-
as: "useI18n",
|
|
56
|
-
from: resolver.resolve("./runtime/composables/useI18n"),
|
|
57
|
-
priority: 2
|
|
58
|
-
});
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
60
|
});
|
|
@@ -3,9 +3,11 @@ type UseI18nOptions = Parameters<typeof _useI18n>[0];
|
|
|
3
3
|
type UseI18nReturn = ReturnType<typeof _useI18n>;
|
|
4
4
|
/**
|
|
5
5
|
* Drop-in replacement for useI18n() that wraps t() to sync missing keys to i18now.
|
|
6
|
-
*
|
|
6
|
+
* Use this instead of useI18n() — auto-imported by the @uipkge/nuxt module.
|
|
7
|
+
*
|
|
8
|
+
* Migration: find-replace `useI18n()` → `useI18now()` in your components.
|
|
7
9
|
*/
|
|
8
|
-
export declare function
|
|
10
|
+
export declare function useI18now(options?: UseI18nOptions): UseI18nReturn & {
|
|
9
11
|
te: (key: string, locale?: string) => boolean;
|
|
10
12
|
};
|
|
11
13
|
export {};
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { useNuxtApp } from "#app";
|
|
2
2
|
import { useI18n as _useI18n } from "vue-i18n";
|
|
3
|
-
export function
|
|
3
|
+
export function useI18now(options) {
|
|
4
4
|
const i18n = _useI18n({ useScope: "global", ...options });
|
|
5
5
|
const nuxtApp = useNuxtApp();
|
|
6
6
|
const originalT = i18n.t.bind(i18n);
|
|
7
|
-
const patchedT = (key, defaultValue,
|
|
8
|
-
const result =
|
|
7
|
+
const patchedT = (key, defaultValue, ...rest) => {
|
|
8
|
+
const result = defaultValue !== void 0 ? originalT(key, defaultValue) : originalT(key);
|
|
9
9
|
const sync = nuxtApp.$i18nowSync;
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const defaultStr = typeof defaultValue === "string" ? defaultValue : typeof rest[0] === "string" ? rest[0] : void 0;
|
|
11
|
+
if (sync && !sync.existingKeys.has(key) && defaultStr !== void 0) {
|
|
12
|
+
sync.syncKey(key, defaultStr);
|
|
12
13
|
}
|
|
13
14
|
return result;
|
|
14
15
|
};
|
|
@@ -89,10 +89,11 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
89
89
|
await loadLocale(locale);
|
|
90
90
|
const originalGlobalT = nuxtApp.vueApp.config.globalProperties.$t;
|
|
91
91
|
if (originalGlobalT) {
|
|
92
|
-
nuxtApp.vueApp.config.globalProperties.$t = function(key, defaultValue,
|
|
93
|
-
const result =
|
|
94
|
-
|
|
95
|
-
|
|
92
|
+
nuxtApp.vueApp.config.globalProperties.$t = function(key, defaultValue, ...rest) {
|
|
93
|
+
const result = defaultValue !== void 0 ? originalGlobalT.call(this, key, defaultValue) : originalGlobalT.call(this, key);
|
|
94
|
+
const defaultStr = typeof defaultValue === "string" ? defaultValue : typeof rest[0] === "string" ? rest[0] : void 0;
|
|
95
|
+
if (!syncer.existingKeys.has(key) && defaultStr !== void 0) {
|
|
96
|
+
syncer.syncKey(key, defaultStr);
|
|
96
97
|
}
|
|
97
98
|
return result;
|
|
98
99
|
};
|