nuxt-i18n-micro 1.85.1 → 1.86.0
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 +2 -2
- package/dist/client/404.html +2 -2
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/9b03c3ea-26a1-4619-b39e-b42f797680ba.json +1 -0
- package/dist/client/index.html +2 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +9 -0
- package/dist/runtime/plugins/03.define.js +17 -61
- package/dist/runtime/plugins/06.redirect.d.ts +2 -0
- package/dist/runtime/plugins/06.redirect.js +38 -0
- package/package.json +4 -4
- package/dist/client/_nuxt/builds/meta/73fe5312-b8b8-43c9-8321-d410f5f66e5c.json +0 -1
package/dist/client/200.html
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
<link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/BBbCCCx2.js">
|
|
9
9
|
<link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.BRj5A2lo.css">
|
|
10
10
|
<link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/CfVvufsh.js">
|
|
11
|
-
<script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/MjlAM4Ld.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},
|
|
12
|
-
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"
|
|
11
|
+
<script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/MjlAM4Ld.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},1745997671706,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"9b03c3ea-26a1-4619-b39e-b42f797680ba",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
package/dist/client/404.html
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
<link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/BBbCCCx2.js">
|
|
9
9
|
<link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.BRj5A2lo.css">
|
|
10
10
|
<link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/CfVvufsh.js">
|
|
11
|
-
<script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/MjlAM4Ld.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},
|
|
12
|
-
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"
|
|
11
|
+
<script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/MjlAM4Ld.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},1745997671707,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"9b03c3ea-26a1-4619-b39e-b42f797680ba",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"id":"
|
|
1
|
+
{"id":"9b03c3ea-26a1-4619-b39e-b42f797680ba","timestamp":1745997666200}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"id":"9b03c3ea-26a1-4619-b39e-b42f797680ba","timestamp":1745997666200,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|
package/dist/client/index.html
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
<link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/BBbCCCx2.js">
|
|
9
9
|
<link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.BRj5A2lo.css">
|
|
10
10
|
<link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/CfVvufsh.js">
|
|
11
|
-
<script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/MjlAM4Ld.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},
|
|
12
|
-
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"
|
|
11
|
+
<script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/MjlAM4Ld.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},1745997671707,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"9b03c3ea-26a1-4619-b39e-b42f797680ba",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -493,6 +493,7 @@ const module = defineNuxtModule({
|
|
|
493
493
|
meta: true,
|
|
494
494
|
debug: false,
|
|
495
495
|
define: true,
|
|
496
|
+
redirects: true,
|
|
496
497
|
plugin: true,
|
|
497
498
|
hooks: true,
|
|
498
499
|
types: true,
|
|
@@ -619,6 +620,14 @@ const module = defineNuxtModule({
|
|
|
619
620
|
order: 4
|
|
620
621
|
});
|
|
621
622
|
}
|
|
623
|
+
if (options.redirects) {
|
|
624
|
+
addPlugin({
|
|
625
|
+
src: resolver.resolve("./runtime/plugins/06.redirect"),
|
|
626
|
+
name: "i18n-plugin-redirect",
|
|
627
|
+
mode: "all",
|
|
628
|
+
order: 6
|
|
629
|
+
});
|
|
630
|
+
}
|
|
622
631
|
addServerHandler({
|
|
623
632
|
route: `/${apiBaseUrl}/:page/:locale/data.json`,
|
|
624
633
|
handler: resolver.resolve("./runtime/server/routes/get")
|
|
@@ -1,68 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return locales.reduce((acc, locale) => {
|
|
11
|
-
acc[locale] = {};
|
|
12
|
-
return acc;
|
|
13
|
-
}, {});
|
|
14
|
-
} else if (typeof locales === "object" && locales !== null) {
|
|
15
|
-
return locales;
|
|
16
|
-
}
|
|
17
|
-
return {};
|
|
18
|
-
};
|
|
19
|
-
const handleRedirect = async (to) => {
|
|
20
|
-
const currentLocale = nuxtApp.$getLocale().toString();
|
|
21
|
-
const { name } = to;
|
|
22
|
-
let defaultRouteName = name?.toString().replace("localized-", "").replace(new RegExp(`-${currentLocale}$`), "");
|
|
23
|
-
if (!to.params.locale) {
|
|
24
|
-
if (router.hasRoute(`localized-${to.name?.toString()}-${currentLocale}`)) {
|
|
25
|
-
defaultRouteName = `localized-${to.name?.toString()}-${currentLocale}`;
|
|
26
|
-
} else {
|
|
27
|
-
defaultRouteName = `localized-${to.name?.toString()}`;
|
|
28
|
-
}
|
|
29
|
-
if (!router.hasRoute(defaultRouteName)) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
const newParams = { ...to.params };
|
|
33
|
-
if (!isNoPrefixStrategy(i18nConfig.strategy)) {
|
|
34
|
-
newParams.locale = i18nConfig.defaultLocale;
|
|
35
|
-
}
|
|
36
|
-
return navigateTo({ name: defaultRouteName, params: newParams }, { redirectCode: 301, external: true });
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
if (import.meta.server) {
|
|
40
|
-
if (isPrefixStrategy(i18nConfig.strategy) || isNoPrefixStrategy(i18nConfig.strategy)) {
|
|
41
|
-
await handleRedirect(route);
|
|
42
|
-
}
|
|
1
|
+
import { defineNuxtPlugin, useNuxtApp, computed, watch, onUnmounted, unref } from "#imports";
|
|
2
|
+
const normalizeLocales = (locales) => {
|
|
3
|
+
if (Array.isArray(locales)) {
|
|
4
|
+
return locales.reduce((acc, locale) => {
|
|
5
|
+
acc[locale] = {};
|
|
6
|
+
return acc;
|
|
7
|
+
}, {});
|
|
8
|
+
} else if (typeof locales === "object" && locales !== null) {
|
|
9
|
+
return locales;
|
|
43
10
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
if (next) {
|
|
49
|
-
next();
|
|
50
|
-
}
|
|
51
|
-
});
|
|
11
|
+
return {};
|
|
12
|
+
};
|
|
13
|
+
export default defineNuxtPlugin(() => {
|
|
52
14
|
const defineI18nRoute = async (routeDefinition) => {
|
|
53
|
-
const { $getLocale } = useNuxtApp();
|
|
15
|
+
const { $getLocale, $mergeGlobalTranslations } = useNuxtApp();
|
|
54
16
|
let currentLocale = computed(() => $getLocale());
|
|
55
17
|
const normalizedLocales = normalizeLocales(routeDefinition.locales);
|
|
56
18
|
const updateTranslations = () => {
|
|
57
|
-
const
|
|
58
|
-
if (
|
|
59
|
-
|
|
60
|
-
const translation = normalizedLocales[currentLocaleValue];
|
|
61
|
-
const { $mergeGlobalTranslations } = useNuxtApp();
|
|
62
|
-
if ($mergeGlobalTranslations) {
|
|
63
|
-
$mergeGlobalTranslations(translation);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
19
|
+
const localeValue = unref(currentLocale);
|
|
20
|
+
if (localeValue && normalizedLocales[localeValue]) {
|
|
21
|
+
$mergeGlobalTranslations?.(normalizedLocales[localeValue]);
|
|
66
22
|
}
|
|
67
23
|
};
|
|
68
24
|
updateTranslations();
|
|
@@ -71,8 +27,8 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
71
27
|
onUnmounted(() => {
|
|
72
28
|
if (stopWatcher) {
|
|
73
29
|
stopWatcher();
|
|
74
|
-
currentLocale = null;
|
|
75
30
|
stopWatcher = null;
|
|
31
|
+
currentLocale = null;
|
|
76
32
|
}
|
|
77
33
|
});
|
|
78
34
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { isNoPrefixStrategy, isPrefixStrategy } from "nuxt-i18n-micro-core";
|
|
2
|
+
import { defineNuxtPlugin, useRuntimeConfig, useRoute, useRouter, navigateTo } from "#imports";
|
|
3
|
+
export default defineNuxtPlugin(async (nuxtApp) => {
|
|
4
|
+
const config = useRuntimeConfig();
|
|
5
|
+
const i18nConfig = config.public.i18nConfig;
|
|
6
|
+
const route = useRoute();
|
|
7
|
+
const router = useRouter();
|
|
8
|
+
const handleRedirect = async (to) => {
|
|
9
|
+
const currentLocale = nuxtApp.$getLocale().toString();
|
|
10
|
+
const name = to.name?.toString();
|
|
11
|
+
let defaultRouteName = name?.toString().replace("localized-", "").replace(new RegExp(`-${currentLocale}$`), "");
|
|
12
|
+
if (!to.params.locale) {
|
|
13
|
+
if (router.hasRoute(`localized-${name}-${currentLocale}`)) {
|
|
14
|
+
defaultRouteName = `localized-${name}-${currentLocale}`;
|
|
15
|
+
} else {
|
|
16
|
+
defaultRouteName = `localized-${name}`;
|
|
17
|
+
}
|
|
18
|
+
if (!router.hasRoute(defaultRouteName)) return;
|
|
19
|
+
const newParams = { ...to.params };
|
|
20
|
+
if (!isNoPrefixStrategy(i18nConfig.strategy)) {
|
|
21
|
+
newParams.locale = i18nConfig.defaultLocale;
|
|
22
|
+
}
|
|
23
|
+
return navigateTo({ name: defaultRouteName, params: newParams }, {
|
|
24
|
+
redirectCode: 301,
|
|
25
|
+
external: true
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
if (import.meta.server && (isPrefixStrategy(i18nConfig.strategy) || isNoPrefixStrategy(i18nConfig.strategy))) {
|
|
30
|
+
await handleRedirect(route);
|
|
31
|
+
}
|
|
32
|
+
router.beforeEach(async (to, from, next) => {
|
|
33
|
+
if (isPrefixStrategy(i18nConfig.strategy) || isNoPrefixStrategy(i18nConfig.strategy)) {
|
|
34
|
+
await handleRedirect(to);
|
|
35
|
+
}
|
|
36
|
+
next?.();
|
|
37
|
+
});
|
|
38
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-i18n-micro",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.86.0",
|
|
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",
|
|
@@ -59,9 +59,9 @@
|
|
|
59
59
|
"globby": "^14.1.0",
|
|
60
60
|
"sirv": "^2.0.4",
|
|
61
61
|
"ufo": "^1.5.4",
|
|
62
|
-
"nuxt-i18n-micro-
|
|
63
|
-
"nuxt-i18n-micro-types": "1.0.
|
|
64
|
-
"nuxt-i18n-micro-
|
|
62
|
+
"nuxt-i18n-micro-test-utils": "1.0.6",
|
|
63
|
+
"nuxt-i18n-micro-types": "1.0.5",
|
|
64
|
+
"nuxt-i18n-micro-core": "1.0.18"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@nuxt/devtools": "^2.1.0",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"id":"73fe5312-b8b8-43c9-8321-d410f5f66e5c","timestamp":1745916998724,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|