nuxt-i18n-micro 1.32.0 → 1.32.2
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 +6 -6
- package/dist/client/404.html +6 -6
- package/dist/client/_nuxt/{C4eGGOXV.js → CL71IQiy.js} +1 -1
- package/dist/client/_nuxt/{BARbCa2g.js → Cwq8qovn.js} +1 -1
- package/dist/client/_nuxt/{DwKyf7FR.js → DDIvEkjZ.js} +1 -1
- package/dist/client/_nuxt/De2IYGEm.js +98 -0
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/e22a2afa-23e9-4d8d-9d9a-796ce96339fd.json +1 -0
- package/dist/client/index.html +6 -6
- package/dist/module.json +1 -1
- package/dist/module.mjs +4 -0
- package/dist/runtime/plugins/01.plugin.js +47 -32
- package/package.json +1 -1
- package/dist/client/_nuxt/CTiMIQCz.js +0 -98
- package/dist/client/_nuxt/builds/meta/3a8f8134-7719-41eb-aa2a-6d83ba6fda72.json +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"id":"
|
|
1
|
+
{"id":"e22a2afa-23e9-4d8d-9d9a-796ce96339fd","timestamp":1731570174097}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"id":"e22a2afa-23e9-4d8d-9d9a-796ce96339fd","timestamp":1731570174097,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|
package/dist/client/index.html
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
<!DOCTYPE html><html data-capo=""><head><meta charset="utf-8">
|
|
2
2
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
3
3
|
<link rel="stylesheet" href="/__nuxt-i18n-micro/_nuxt/entry.BqOlM4b6.css">
|
|
4
|
-
<link rel="modulepreload" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/
|
|
4
|
+
<link rel="modulepreload" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/De2IYGEm.js">
|
|
5
5
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/B6E6ObS_.js">
|
|
6
6
|
<link rel="prefetch" as="style" crossorigin href="/__nuxt-i18n-micro/_nuxt/error-404.C_4C5G96.css">
|
|
7
|
-
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/
|
|
8
|
-
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/
|
|
7
|
+
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/DDIvEkjZ.js">
|
|
8
|
+
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/CL71IQiy.js">
|
|
9
9
|
<link rel="prefetch" as="style" crossorigin href="/__nuxt-i18n-micro/_nuxt/error-500.CBAEdpZV.css">
|
|
10
|
-
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/
|
|
11
|
-
<script type="module" src="/__nuxt-i18n-micro/_nuxt/
|
|
12
|
-
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"
|
|
10
|
+
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/Cwq8qovn.js">
|
|
11
|
+
<script type="module" src="/__nuxt-i18n-micro/_nuxt/De2IYGEm.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},1731570187038,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"e22a2afa-23e9-4d8d-9d9a-796ce96339fd",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -495,17 +495,20 @@ const module = defineNuxtModule({
|
|
|
495
495
|
};
|
|
496
496
|
addPlugin({
|
|
497
497
|
src: resolver.resolve("./runtime/plugins/01.plugin"),
|
|
498
|
+
name: "i18n-plugin-loader",
|
|
498
499
|
order: 0
|
|
499
500
|
});
|
|
500
501
|
if (options.meta) {
|
|
501
502
|
addPlugin({
|
|
502
503
|
src: resolver.resolve("./runtime/plugins/02.meta"),
|
|
504
|
+
name: "i18n-plugin-meta",
|
|
503
505
|
order: 2
|
|
504
506
|
});
|
|
505
507
|
}
|
|
506
508
|
if (options.define) {
|
|
507
509
|
addPlugin({
|
|
508
510
|
src: resolver.resolve("./runtime/plugins/03.define"),
|
|
511
|
+
name: "i18n-plugin-define",
|
|
509
512
|
order: 3
|
|
510
513
|
});
|
|
511
514
|
}
|
|
@@ -513,6 +516,7 @@ const module = defineNuxtModule({
|
|
|
513
516
|
addPlugin({
|
|
514
517
|
src: resolver.resolve("./runtime/plugins/04.auto-detect"),
|
|
515
518
|
mode: "server",
|
|
519
|
+
name: "i18n-plugin-auto-detect",
|
|
516
520
|
order: 4
|
|
517
521
|
});
|
|
518
522
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useTranslationHelper } from "../translationHelper.js";
|
|
2
2
|
import { defineNuxtPlugin, useRuntimeConfig } from "#app";
|
|
3
|
-
import { useRoute, useRouter, useCookie, useState } from "#imports";
|
|
3
|
+
import { useRoute, useRouter, useCookie, useState, navigateTo } from "#imports";
|
|
4
4
|
import { plural } from "#build/i18n.plural.mjs";
|
|
5
5
|
const i18nHelper = useTranslationHelper();
|
|
6
6
|
const isDev = process.env.NODE_ENV !== "production";
|
|
@@ -92,6 +92,9 @@ function switchLocale(fromLocale, toLocale, route, router, i18nConfig, i18nRoute
|
|
|
92
92
|
i18nConfig,
|
|
93
93
|
i18nRouteParams
|
|
94
94
|
);
|
|
95
|
+
if (typeof switchedRoute === "string" && switchedRoute.startsWith("http")) {
|
|
96
|
+
return navigateTo(switchedRoute, { redirectCode: 200, external: true });
|
|
97
|
+
}
|
|
95
98
|
return router.push(switchedRoute);
|
|
96
99
|
}
|
|
97
100
|
function getLocalizedRoute(to, router, route, i18nConfig, locale, hashLocale) {
|
|
@@ -201,14 +204,14 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
201
204
|
console.warn(`[nuxt-i18n-next] The page name is missing in the path: ${path}. Please ensure that definePageMeta({ name: 'pageName' }) is set.`);
|
|
202
205
|
return;
|
|
203
206
|
}
|
|
204
|
-
const
|
|
205
|
-
const data = await $fetch(
|
|
207
|
+
const route2 = `/${apiBaseUrl}/${fRouteName}/${locale}/data.json?v=${i18nConfig.dateBuild}`.replace(/\/{2,}/g, "/");
|
|
208
|
+
const data = await $fetch(route2, { baseURL: runtimeConfig.app.baseURL });
|
|
206
209
|
await i18nHelper.loadPageTranslations(locale, routeName, data ?? {});
|
|
207
210
|
}
|
|
208
211
|
} catch (_error) {
|
|
209
212
|
}
|
|
210
213
|
};
|
|
211
|
-
|
|
214
|
+
async function loadTranslationsForRoute(to, next) {
|
|
212
215
|
const hashLocale2 = i18nConfig.hashMode ? nuxtApp.runWithContext(() => (useCookie("hash-locale").value ?? i18nConfig.defaultLocale).toString()).toString() : null;
|
|
213
216
|
const locale = getCurrentLocale(to, i18nConfig, hashLocale2);
|
|
214
217
|
if (!i18nHelper.hasGeneralTranslation(locale)) {
|
|
@@ -226,12 +229,21 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
226
229
|
if (next) {
|
|
227
230
|
next();
|
|
228
231
|
}
|
|
232
|
+
}
|
|
233
|
+
useRouter().beforeEach(async (to, from, next) => {
|
|
234
|
+
if (to.path !== from.path) {
|
|
235
|
+
await loadTranslationsForRoute(to, next);
|
|
236
|
+
}
|
|
237
|
+
next();
|
|
229
238
|
});
|
|
239
|
+
const route = useRoute();
|
|
240
|
+
await loadTranslationsForRoute(route);
|
|
230
241
|
const getTranslation = (key, params, defaultValue) => {
|
|
231
242
|
if (!key) return "";
|
|
243
|
+
const route2 = useRoute();
|
|
232
244
|
const hashLocale2 = i18nConfig.hashMode ? (useCookie("hash-locale").value ?? i18nConfig.defaultLocale).toString() : null;
|
|
233
|
-
const locale = getCurrentLocale(
|
|
234
|
-
const routeName = getRouteName(
|
|
245
|
+
const locale = getCurrentLocale(route2, i18nConfig, hashLocale2);
|
|
246
|
+
const routeName = getRouteName(route2, locale);
|
|
235
247
|
let value = i18nHelper.getTranslation(locale, routeName, key);
|
|
236
248
|
if (!value) {
|
|
237
249
|
if (isDev && import.meta.client) {
|
|
@@ -256,9 +268,9 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
256
268
|
getLocaleName: () => getCurrentName(useRoute(), i18nConfig, hashLocale),
|
|
257
269
|
defaultLocale: () => i18nConfig.defaultLocale,
|
|
258
270
|
getLocales: () => i18nConfig.locales || [],
|
|
259
|
-
getRouteName: (
|
|
271
|
+
getRouteName: (route2, locale) => {
|
|
260
272
|
const selectedLocale = locale ?? getCurrentLocale(useRoute(), i18nConfig, hashLocale);
|
|
261
|
-
const selectedRoute =
|
|
273
|
+
const selectedRoute = route2 ?? useRoute();
|
|
262
274
|
return getRouteName(selectedRoute, selectedLocale);
|
|
263
275
|
},
|
|
264
276
|
t: getTranslation,
|
|
@@ -267,43 +279,46 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
267
279
|
return value?.toString() ?? defaultValue ?? key;
|
|
268
280
|
},
|
|
269
281
|
tc: (key, count, defaultValue) => {
|
|
270
|
-
const
|
|
282
|
+
const route2 = useRoute();
|
|
283
|
+
const currentLocale = getCurrentLocale(route2, i18nConfig, hashLocale);
|
|
271
284
|
return plural(key, count, currentLocale, getTranslation) ?? defaultValue ?? key;
|
|
272
285
|
},
|
|
273
286
|
tn: (value, options) => {
|
|
274
|
-
const
|
|
287
|
+
const route2 = useRoute();
|
|
288
|
+
const locale = getCurrentLocale(route2, i18nConfig, hashLocale);
|
|
275
289
|
return formatNumber(value, locale, options);
|
|
276
290
|
},
|
|
277
291
|
td: (value, options) => {
|
|
278
|
-
const
|
|
292
|
+
const route2 = useRoute();
|
|
293
|
+
const locale = getCurrentLocale(route2, i18nConfig, hashLocale);
|
|
279
294
|
return formatDate(value, locale, options);
|
|
280
295
|
},
|
|
281
296
|
has: (key) => {
|
|
282
297
|
return !!getTranslation(key);
|
|
283
298
|
},
|
|
284
299
|
mergeTranslations: (newTranslations) => {
|
|
285
|
-
const
|
|
286
|
-
const locale = getCurrentLocale(
|
|
287
|
-
const routeName = getRouteName(
|
|
300
|
+
const route2 = useRoute();
|
|
301
|
+
const locale = getCurrentLocale(route2, i18nConfig, hashLocale);
|
|
302
|
+
const routeName = getRouteName(route2, locale);
|
|
288
303
|
i18nHelper.mergeTranslation(locale, routeName, newTranslations);
|
|
289
304
|
},
|
|
290
305
|
switchLocaleRoute: (toLocale) => {
|
|
291
306
|
const router = useRouter();
|
|
292
|
-
const
|
|
293
|
-
const fromLocale = getCurrentLocale(
|
|
307
|
+
const route2 = useRoute();
|
|
308
|
+
const fromLocale = getCurrentLocale(route2, i18nConfig, hashLocale);
|
|
294
309
|
if (i18nConfig.hashMode) {
|
|
295
310
|
hashLocale = toLocale;
|
|
296
311
|
}
|
|
297
|
-
return switchLocaleRoute(fromLocale, toLocale,
|
|
312
|
+
return switchLocaleRoute(fromLocale, toLocale, route2, router, i18nConfig, i18nRouteParams.value);
|
|
298
313
|
},
|
|
299
314
|
switchLocalePath: (toLocale) => {
|
|
300
315
|
const router = useRouter();
|
|
301
|
-
const
|
|
302
|
-
const fromLocale = getCurrentLocale(
|
|
316
|
+
const route2 = useRoute();
|
|
317
|
+
const fromLocale = getCurrentLocale(route2, i18nConfig, hashLocale);
|
|
303
318
|
if (i18nConfig.hashMode) {
|
|
304
319
|
hashLocale = toLocale;
|
|
305
320
|
}
|
|
306
|
-
const localeRoute = switchLocaleRoute(fromLocale, toLocale,
|
|
321
|
+
const localeRoute = switchLocaleRoute(fromLocale, toLocale, route2, router, i18nConfig, i18nRouteParams.value);
|
|
307
322
|
if (typeof localeRoute === "string") {
|
|
308
323
|
return localeRoute;
|
|
309
324
|
}
|
|
@@ -314,33 +329,33 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
314
329
|
},
|
|
315
330
|
switchLocale: (toLocale) => {
|
|
316
331
|
const router = useRouter();
|
|
317
|
-
const
|
|
318
|
-
const fromLocale = getCurrentLocale(
|
|
332
|
+
const route2 = useRoute();
|
|
333
|
+
const fromLocale = getCurrentLocale(route2, i18nConfig, hashLocale);
|
|
319
334
|
if (i18nConfig.hashMode) {
|
|
320
335
|
hashLocale = toLocale;
|
|
321
336
|
}
|
|
322
|
-
switchLocale(fromLocale, toLocale,
|
|
337
|
+
switchLocale(fromLocale, toLocale, route2, router, i18nConfig, i18nRouteParams.value);
|
|
323
338
|
},
|
|
324
|
-
switchRoute: (
|
|
339
|
+
switchRoute: (route2, toLocale) => {
|
|
325
340
|
const router = useRouter();
|
|
326
|
-
if (typeof
|
|
327
|
-
|
|
341
|
+
if (typeof route2 === "string") {
|
|
342
|
+
route2 = router.resolve(route2);
|
|
328
343
|
}
|
|
329
|
-
const fromLocale = getCurrentLocale(
|
|
344
|
+
const fromLocale = getCurrentLocale(route2, i18nConfig, hashLocale);
|
|
330
345
|
if (i18nConfig.hashMode) {
|
|
331
346
|
hashLocale = toLocale ?? fromLocale;
|
|
332
347
|
}
|
|
333
|
-
switchLocale(fromLocale, toLocale ?? fromLocale,
|
|
348
|
+
switchLocale(fromLocale, toLocale ?? fromLocale, route2, router, i18nConfig, i18nRouteParams.value);
|
|
334
349
|
},
|
|
335
350
|
localeRoute: (to, locale) => {
|
|
336
351
|
const router = useRouter();
|
|
337
|
-
const
|
|
338
|
-
return getLocalizedRoute(to, router,
|
|
352
|
+
const route2 = useRoute();
|
|
353
|
+
return getLocalizedRoute(to, router, route2, i18nConfig, locale, hashLocale);
|
|
339
354
|
},
|
|
340
355
|
localePath: (to, locale) => {
|
|
341
356
|
const router = useRouter();
|
|
342
|
-
const
|
|
343
|
-
const localeRoute = getLocalizedRoute(to, router,
|
|
357
|
+
const route2 = useRoute();
|
|
358
|
+
const localeRoute = getLocalizedRoute(to, router, route2, i18nConfig, locale, hashLocale);
|
|
344
359
|
if (typeof localeRoute === "string") {
|
|
345
360
|
return localeRoute;
|
|
346
361
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-i18n-micro",
|
|
3
|
-
"version": "1.32.
|
|
3
|
+
"version": "1.32.2",
|
|
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",
|