nuxt-i18n-micro 1.1.8 → 1.1.9
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/client/200.html +1 -1
- package/dist/client/404.html +1 -1
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/3c9001bb-920a-4988-9ad0-29eff844b06b.json +1 -0
- package/dist/client/index.html +1 -1
- package/dist/module.d.mts +1 -0
- package/dist/module.d.ts +1 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +3 -1
- package/dist/runtime/01.plugin.js +52 -18
- package/dist/runtime/03.define.js +7 -1
- package/dist/runtime/_01.plugin.d.ts +1 -0
- package/dist/runtime/_01.plugin.js +0 -0
- package/package.json +1 -1
- package/dist/client/_nuxt/builds/meta/7d3d3cf9-6064-4ba3-a2ec-347447f8edd0.json +0 -1
package/dist/client/200.html
CHANGED
|
@@ -8,4 +8,4 @@
|
|
|
8
8
|
<link rel="prefetch" as="style" href="/__nuxt-i18n-micro/_nuxt/error-500.B4KzowuE.css">
|
|
9
9
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/HZLiFEh-.js">
|
|
10
10
|
<script type="module" src="/__nuxt-i18n-micro/_nuxt/6EJ4fAZ2.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" id="__NUXT_DATA__" data-ssr="false">[{"serverRendered":1},false]</script>
|
|
11
|
-
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"
|
|
11
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"3c9001bb-920a-4988-9ad0-29eff844b06b",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
package/dist/client/404.html
CHANGED
|
@@ -8,4 +8,4 @@
|
|
|
8
8
|
<link rel="prefetch" as="style" href="/__nuxt-i18n-micro/_nuxt/error-500.B4KzowuE.css">
|
|
9
9
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/HZLiFEh-.js">
|
|
10
10
|
<script type="module" src="/__nuxt-i18n-micro/_nuxt/6EJ4fAZ2.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" id="__NUXT_DATA__" data-ssr="false">[{"serverRendered":1},false]</script>
|
|
11
|
-
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"
|
|
11
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"3c9001bb-920a-4988-9ad0-29eff844b06b",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"id":"
|
|
1
|
+
{"id":"3c9001bb-920a-4988-9ad0-29eff844b06b","timestamp":1723999902563}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"id":"3c9001bb-920a-4988-9ad0-29eff844b06b","timestamp":1723999902563,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|
package/dist/client/index.html
CHANGED
|
@@ -8,4 +8,4 @@
|
|
|
8
8
|
<link rel="prefetch" as="style" href="/__nuxt-i18n-micro/_nuxt/error-500.B4KzowuE.css">
|
|
9
9
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/HZLiFEh-.js">
|
|
10
10
|
<script type="module" src="/__nuxt-i18n-micro/_nuxt/6EJ4fAZ2.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" id="__NUXT_DATA__" data-ssr="false">[{"serverRendered":1},false]</script>
|
|
11
|
-
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"
|
|
11
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"3c9001bb-920a-4988-9ad0-29eff844b06b",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
package/dist/module.d.mts
CHANGED
package/dist/module.d.ts
CHANGED
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -79,6 +79,7 @@ const module = defineNuxtModule({
|
|
|
79
79
|
translationDir: "locales",
|
|
80
80
|
autoDetectLanguage: true,
|
|
81
81
|
includeDefaultLocaleRoute: false,
|
|
82
|
+
cache: false,
|
|
82
83
|
plural: `function (translation, count, _locale) {
|
|
83
84
|
const forms = translation.toString().split('|')
|
|
84
85
|
if (count === 0 && forms.length > 2) {
|
|
@@ -100,7 +101,8 @@ const module = defineNuxtModule({
|
|
|
100
101
|
defaultLocale: options.defaultLocale ?? "en",
|
|
101
102
|
translationDir: options.translationDir ?? "locales",
|
|
102
103
|
autoDetectLanguage: options.autoDetectLanguage ?? true,
|
|
103
|
-
includeDefaultLocaleRoute: options.includeDefaultLocaleRoute ?? false
|
|
104
|
+
includeDefaultLocaleRoute: options.includeDefaultLocaleRoute ?? false,
|
|
105
|
+
cache: options.cache ?? false
|
|
104
106
|
};
|
|
105
107
|
addPlugin({
|
|
106
108
|
src: resolver.resolve("./runtime/01.plugin"),
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { defineNuxtPlugin, useRuntimeConfig } from "#app";
|
|
2
2
|
import { useRoute, useRouter } from "#imports";
|
|
3
|
+
const isDev = process.env.NODE_ENV !== "production";
|
|
3
4
|
const generalLocaleCache = {};
|
|
4
5
|
const routeLocaleCache = {};
|
|
5
6
|
const dynamicTranslationsCaches = [];
|
|
7
|
+
const translationCache = { map: /* @__PURE__ */ new Map() };
|
|
6
8
|
function deepClone(value) {
|
|
7
9
|
if (Array.isArray(value)) {
|
|
8
10
|
return value.slice();
|
|
@@ -12,13 +14,16 @@ function deepClone(value) {
|
|
|
12
14
|
return value;
|
|
13
15
|
}
|
|
14
16
|
function getTranslation(translations, key) {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
const parts = key.split(".");
|
|
18
|
+
let value = translations;
|
|
19
|
+
for (let i = 0; i < parts.length; i++) {
|
|
20
|
+
if (value && typeof value === "object" && parts[i] in value) {
|
|
21
|
+
value = value[parts[i]];
|
|
22
|
+
} else {
|
|
23
|
+
return null;
|
|
18
24
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (value && typeof value === "object") {
|
|
25
|
+
}
|
|
26
|
+
if (typeof value === "object" && value !== null) {
|
|
22
27
|
return deepClone(value);
|
|
23
28
|
}
|
|
24
29
|
return value ?? null;
|
|
@@ -55,7 +60,7 @@ function switchLocale(locale, route, router, i18nConfig) {
|
|
|
55
60
|
const checkLocale = i18nConfig.locales?.find((l) => l.code === locale);
|
|
56
61
|
if (!checkLocale) {
|
|
57
62
|
console.warn(`Locale ${locale} is not available`);
|
|
58
|
-
return;
|
|
63
|
+
return Promise.reject(`Locale ${locale} is not available`);
|
|
59
64
|
}
|
|
60
65
|
const { defaultLocale } = i18nConfig;
|
|
61
66
|
const routeName = route.name.replace(`localized-`, "");
|
|
@@ -65,7 +70,7 @@ function switchLocale(locale, route, router, i18nConfig) {
|
|
|
65
70
|
if (locale !== defaultLocale || i18nConfig.includeDefaultLocaleRoute) {
|
|
66
71
|
newParams.locale = locale;
|
|
67
72
|
}
|
|
68
|
-
router.push({ name: newRouteName, params: newParams });
|
|
73
|
+
return router.push({ name: newRouteName, params: newParams });
|
|
69
74
|
}
|
|
70
75
|
function getLocalizedRoute(to, router, route, i18nConfig, locale) {
|
|
71
76
|
const { defaultLocale } = i18nConfig;
|
|
@@ -99,24 +104,38 @@ export default defineNuxtPlugin(async (_nuxtApp) => {
|
|
|
99
104
|
await loadTranslations(initialLocale, initialRouteName, i18nConfig.translationDir);
|
|
100
105
|
return {
|
|
101
106
|
provide: {
|
|
102
|
-
getLocale: () =>
|
|
107
|
+
getLocale: () => {
|
|
108
|
+
const route2 = useRoute();
|
|
109
|
+
return (route2.params?.locale ?? i18nConfig.defaultLocale).toString();
|
|
110
|
+
},
|
|
103
111
|
getLocales: () => i18nConfig.locales || [],
|
|
104
112
|
t: (key, params, defaultValue) => {
|
|
105
113
|
if (!key) {
|
|
106
114
|
console.log(`$t: key not exist`);
|
|
107
115
|
return "";
|
|
108
116
|
}
|
|
109
|
-
const
|
|
110
|
-
const
|
|
117
|
+
const route2 = useRoute();
|
|
118
|
+
const locale = (route2.params?.locale ?? i18nConfig.defaultLocale).toString();
|
|
119
|
+
const cacheKey = locale + ":" + key;
|
|
120
|
+
if (i18nConfig.cache && translationCache.map.has(cacheKey)) {
|
|
121
|
+
return translationCache.map.get(cacheKey);
|
|
122
|
+
}
|
|
123
|
+
const routeName = route2.name.replace(`localized-`, "");
|
|
111
124
|
let value = getTranslation(routeLocaleCache[`${locale}:${routeName}`] ?? {}, key) || getTranslation(generalLocaleCache[locale] ?? {}, key) || dynamicTranslationsCaches.reduce((result, cache) => {
|
|
112
125
|
return result || getTranslation(cache[locale] ?? {}, key);
|
|
113
126
|
}, null);
|
|
114
127
|
if (!value) {
|
|
128
|
+
if (isDev && import.meta.client) {
|
|
129
|
+
console.warn(`Not found '${key}' key in '${locale}' locale messages.`);
|
|
130
|
+
}
|
|
115
131
|
value = defaultValue || key;
|
|
116
132
|
}
|
|
117
133
|
if (typeof value === "string" && params) {
|
|
118
134
|
value = interpolate(value, params);
|
|
119
135
|
}
|
|
136
|
+
if (i18nConfig.cache) {
|
|
137
|
+
translationCache.map.set(cacheKey, value);
|
|
138
|
+
}
|
|
120
139
|
return value;
|
|
121
140
|
},
|
|
122
141
|
tc: (key, count, defaultValue) => {
|
|
@@ -124,26 +143,41 @@ export default defineNuxtPlugin(async (_nuxtApp) => {
|
|
|
124
143
|
console.log(`$tc: key not exist`);
|
|
125
144
|
return "";
|
|
126
145
|
}
|
|
127
|
-
const
|
|
128
|
-
const
|
|
146
|
+
const route2 = useRoute();
|
|
147
|
+
const locale = (route2.params?.locale ?? i18nConfig.defaultLocale).toString();
|
|
148
|
+
const cacheKey = locale + ":" + key + ":" + count;
|
|
149
|
+
if (i18nConfig.cache && translationCache.map.has(cacheKey)) {
|
|
150
|
+
return translationCache.map.get(cacheKey);
|
|
151
|
+
}
|
|
152
|
+
const routeName = route2.name.replace(`localized-`, "");
|
|
129
153
|
let translation = getPluralTranslation(routeLocaleCache[`${locale}:${routeName}`] ?? {}, key) || getPluralTranslation(generalLocaleCache[locale] ?? {}, key) || dynamicTranslationsCaches.reduce((result, cache) => {
|
|
130
154
|
return result || getPluralTranslation(cache[locale] ?? {}, key);
|
|
131
155
|
}, null);
|
|
132
156
|
if (!translation) {
|
|
157
|
+
if (isDev && import.meta.client) {
|
|
158
|
+
console.warn(`Not found '${key}' key in '${locale}' locale messages.`);
|
|
159
|
+
}
|
|
133
160
|
translation = defaultValue || key;
|
|
134
161
|
}
|
|
135
|
-
|
|
162
|
+
const value = plural(translation.toString(), count, locale);
|
|
163
|
+
if (i18nConfig.cache) {
|
|
164
|
+
translationCache.map.set(cacheKey, value);
|
|
165
|
+
}
|
|
166
|
+
return value;
|
|
136
167
|
},
|
|
137
168
|
mergeTranslations: (newTranslations) => {
|
|
138
|
-
const
|
|
139
|
-
const
|
|
169
|
+
const route2 = useRoute();
|
|
170
|
+
const routeName = route2.name.replace(`localized-`, "");
|
|
171
|
+
const locale = (route2.params?.locale ?? i18nConfig.defaultLocale).toString();
|
|
140
172
|
mergeTranslations(routeName, locale, newTranslations);
|
|
141
173
|
},
|
|
142
174
|
switchLocale: (locale) => {
|
|
143
|
-
|
|
175
|
+
const route2 = useRoute();
|
|
176
|
+
switchLocale(locale, route2, router, i18nConfig);
|
|
144
177
|
},
|
|
145
178
|
localeRoute: (to, locale) => {
|
|
146
|
-
|
|
179
|
+
const route2 = useRoute();
|
|
180
|
+
return getLocalizedRoute(to, router, route2, i18nConfig, locale);
|
|
147
181
|
}
|
|
148
182
|
}
|
|
149
183
|
};
|
|
@@ -10,8 +10,14 @@ export default defineNuxtPlugin((_nuxtApp) => {
|
|
|
10
10
|
const { locales } = routeDefinition;
|
|
11
11
|
const { name } = route;
|
|
12
12
|
if (locales && !locales.includes(currentLocale)) {
|
|
13
|
-
|
|
13
|
+
let defaultRouteName = name?.toString().replace("localized-", "");
|
|
14
14
|
const resolvedRoute = router.resolve({ name: defaultRouteName });
|
|
15
|
+
const newParams = { ...route.params };
|
|
16
|
+
delete newParams.locale;
|
|
17
|
+
if (i18nConfig.includeDefaultLocaleRoute) {
|
|
18
|
+
defaultRouteName = `localized-${defaultRouteName}`;
|
|
19
|
+
newParams.locale = i18nConfig.defaultLocale;
|
|
20
|
+
}
|
|
15
21
|
return router.push(resolvedRoute);
|
|
16
22
|
}
|
|
17
23
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-i18n-micro",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.9",
|
|
4
4
|
"description": "Nuxt I18n Micro is a lightweight, high-performance internationalization module for Nuxt, designed to handle multi-language support with minimal overhead, fast build times, and efficient runtime performance.",
|
|
5
5
|
"repository": "s00d/nuxt-i18n-micro",
|
|
6
6
|
"license": "MIT",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"id":"7d3d3cf9-6064-4ba3-a2ec-347447f8edd0","timestamp":1723968282041,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|