nuxt-i18n-micro 1.29.5 → 1.30.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/8392605f-2054-4360-b711-3dd07a3c7cbc.json +1 -0
- package/dist/client/index.html +2 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +23 -7
- package/dist/runtime/composables/useLocaleHead.js +1 -1
- package/dist/runtime/plugins/01.plugin.js +36 -3
- package/dist/runtime/plugins/03.define.js +1 -1
- package/package.json +2 -2
- package/dist/client/_nuxt/builds/meta/dd852be5-e5b6-4c76-85b7-ce1af545045f.json +0 -1
package/dist/client/200.html
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/0GmYR_kR.js">
|
|
9
9
|
<link rel="prefetch" as="style" crossorigin href="/__nuxt-i18n-micro/_nuxt/error-500.CBAEdpZV.css">
|
|
10
10
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/2C6ahHCU.js">
|
|
11
|
-
<script type="module" src="/__nuxt-i18n-micro/_nuxt/Czi4MokJ.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-i18n-micro",buildId:"
|
|
11
|
+
<script type="module" src="/__nuxt-i18n-micro/_nuxt/Czi4MokJ.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},1729764389678,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"8392605f-2054-4360-b711-3dd07a3c7cbc",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-i18n-micro/_nuxt/0GmYR_kR.js">
|
|
9
9
|
<link rel="prefetch" as="style" crossorigin href="/__nuxt-i18n-micro/_nuxt/error-500.CBAEdpZV.css">
|
|
10
10
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/2C6ahHCU.js">
|
|
11
|
-
<script type="module" src="/__nuxt-i18n-micro/_nuxt/Czi4MokJ.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-i18n-micro",buildId:"
|
|
11
|
+
<script type="module" src="/__nuxt-i18n-micro/_nuxt/Czi4MokJ.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},1729764389678,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"8392605f-2054-4360-b711-3dd07a3c7cbc",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"id":"
|
|
1
|
+
{"id":"8392605f-2054-4360-b711-3dd07a3c7cbc","timestamp":1729764378430}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"id":"8392605f-2054-4360-b711-3dd07a3c7cbc","timestamp":1729764378430,"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-i18n-micro/_nuxt/0GmYR_kR.js">
|
|
9
9
|
<link rel="prefetch" as="style" crossorigin href="/__nuxt-i18n-micro/_nuxt/error-500.CBAEdpZV.css">
|
|
10
10
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/2C6ahHCU.js">
|
|
11
|
-
<script type="module" src="/__nuxt-i18n-micro/_nuxt/Czi4MokJ.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-i18n-micro",buildId:"
|
|
11
|
+
<script type="module" src="/__nuxt-i18n-micro/_nuxt/Czi4MokJ.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},1729764389678,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"8392605f-2054-4360-b711-3dd07a3c7cbc",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -139,6 +139,9 @@ const normalizeRegex = (toNorm) => {
|
|
|
139
139
|
return toNorm.startsWith("/") && toNorm.endsWith("/") ? toNorm?.slice(1, -1) : toNorm;
|
|
140
140
|
};
|
|
141
141
|
|
|
142
|
+
const buildRouteNameFromRoute = (name, path2) => {
|
|
143
|
+
return name ?? (path2 ?? "").replace(/[^a-z0-9]/gi, "-").replace(/^-+|-+$/g, "");
|
|
144
|
+
};
|
|
142
145
|
class PageManager {
|
|
143
146
|
locales;
|
|
144
147
|
defaultLocale;
|
|
@@ -165,7 +168,6 @@ class PageManager {
|
|
|
165
168
|
pages.forEach((page) => {
|
|
166
169
|
if (!page.name) {
|
|
167
170
|
console.warn(`[nuxt-i18n-next] Page name is missing for the file: ${page.file}`);
|
|
168
|
-
return;
|
|
169
171
|
}
|
|
170
172
|
const customRoute = this.globalLocaleRoutes[page.name ?? ""] ?? null;
|
|
171
173
|
if (customRoute === false) {
|
|
@@ -177,12 +179,26 @@ class PageManager {
|
|
|
177
179
|
this.localizePage(page, additionalRoutes, customRegex);
|
|
178
180
|
}
|
|
179
181
|
});
|
|
182
|
+
if (this.includeDefaultLocaleRoute) {
|
|
183
|
+
for (let i = pages.length - 1; i >= 0; i--) {
|
|
184
|
+
const defaultLocalePath = this.localizedPaths[pages[i].path]?.[this.defaultLocale.code];
|
|
185
|
+
if (defaultLocalePath !== null) {
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
if (this.globalLocaleRoutes[pages[i].name ?? ""] !== null) {
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (!/^\/:locale/.test(pages[i].path) && pages[i].path !== "/") {
|
|
192
|
+
pages.splice(i, 1);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
180
196
|
pages.push(...additionalRoutes);
|
|
181
197
|
}
|
|
182
198
|
extractLocalizedPaths(pages, rootDir, parentPath = "") {
|
|
183
199
|
const localizedPaths = {};
|
|
184
200
|
pages.forEach((page) => {
|
|
185
|
-
const pageName = page.name
|
|
201
|
+
const pageName = buildRouteNameFromRoute(page.name, page.path);
|
|
186
202
|
const globalLocalePath = this.globalLocaleRoutes[pageName];
|
|
187
203
|
if (!globalLocalePath) {
|
|
188
204
|
if (page.file) {
|
|
@@ -240,7 +256,7 @@ class PageManager {
|
|
|
240
256
|
}
|
|
241
257
|
const currentChildren = page.children ? [...page.children] : [];
|
|
242
258
|
if (originalChildren.length) {
|
|
243
|
-
const newName = normalizePath(path.join("/", page.name
|
|
259
|
+
const newName = normalizePath(path.join("/", buildRouteNameFromRoute(page.name, page.path)));
|
|
244
260
|
const localizedChildren = this.mergeChildren(originalChildren, newName, [this.defaultLocale.code]);
|
|
245
261
|
const childrenMap = new Map(currentChildren.map((child) => [child.name, child]));
|
|
246
262
|
localizedChildren.forEach((localizedChild) => {
|
|
@@ -284,8 +300,8 @@ class PageManager {
|
|
|
284
300
|
return localeCodes.map((locale) => this.createLocalizedChildRoute(route, routePath, locale, customLocalePaths, localizedChildren, modifyName, addLocalePrefix));
|
|
285
301
|
}
|
|
286
302
|
createLocalizedRoute(page, localeCodes, originalChildren, isCustom, customPath = "", customRegex) {
|
|
287
|
-
const routePath = this.buildRoutePath(localeCodes, page.path, customPath, isCustom, customRegex);
|
|
288
|
-
const routeName = buildRouteName(page.name
|
|
303
|
+
const routePath = this.buildRoutePath(localeCodes, page.path, encodeURI(customPath), isCustom, customRegex);
|
|
304
|
+
const routeName = buildRouteName(buildRouteNameFromRoute(page.name, page.path), localeCodes[0], isCustom);
|
|
289
305
|
return {
|
|
290
306
|
...page,
|
|
291
307
|
children: this.createLocalizedChildren(originalChildren, page.path, localeCodes, true),
|
|
@@ -295,7 +311,7 @@ class PageManager {
|
|
|
295
311
|
}
|
|
296
312
|
createLocalizedChildRoute(route, routePath, locale, customLocalePaths, children, modifyName, addLocalePrefix) {
|
|
297
313
|
const finalPath = this.buildLocalizedRoutePath(routePath, locale, customLocalePaths, addLocalePrefix);
|
|
298
|
-
const routeName = this.buildLocalizedRouteName(route.name
|
|
314
|
+
const routeName = this.buildLocalizedRouteName(buildRouteNameFromRoute(route.name, route.path), locale, modifyName);
|
|
299
315
|
return {
|
|
300
316
|
...route,
|
|
301
317
|
name: routeName,
|
|
@@ -305,7 +321,7 @@ class PageManager {
|
|
|
305
321
|
}
|
|
306
322
|
buildLocalizedRoutePath(routePath, locale, customLocalePaths, addLocalePrefix) {
|
|
307
323
|
const basePath = customLocalePaths?.[locale] || routePath;
|
|
308
|
-
const normalizedBasePath = normalizePath(basePath);
|
|
324
|
+
const normalizedBasePath = encodeURI(normalizePath(basePath));
|
|
309
325
|
return shouldAddLocalePrefix(locale, this.defaultLocale, addLocalePrefix, this.includeDefaultLocaleRoute) ? buildFullPath(locale, normalizedBasePath) : normalizedBasePath;
|
|
310
326
|
}
|
|
311
327
|
buildLocalizedRouteName(baseName, locale, modifyName) {
|
|
@@ -8,7 +8,7 @@ export const useLocaleHead = ({ addDirAttribute = true, identifierAttribute = "i
|
|
|
8
8
|
});
|
|
9
9
|
function updateMeta() {
|
|
10
10
|
const { defaultLocale, includeDefaultLocaleRoute } = useRuntimeConfig().public.i18nConfig;
|
|
11
|
-
const { $getLocales, $getLocale } = useNuxtApp()
|
|
11
|
+
const { $getLocales, $getLocale } = useNuxtApp();
|
|
12
12
|
const route = useRoute();
|
|
13
13
|
const locale = unref($getLocale());
|
|
14
14
|
const routeName = (route.name ?? "").toString();
|
|
@@ -70,9 +70,6 @@ function switchLocale(fromLocale, toLocale, route, router, i18nConfig, i18nRoute
|
|
|
70
70
|
return router.push(switchedRoute);
|
|
71
71
|
}
|
|
72
72
|
function getLocalizedRoute(to, router, route, i18nConfig, locale, hashLocale) {
|
|
73
|
-
const currentLocale = locale || getCurrentLocale(route, i18nConfig, hashLocale);
|
|
74
|
-
const selectRoute = router.resolve(to);
|
|
75
|
-
const routeName = getRouteName(selectRoute, currentLocale);
|
|
76
73
|
const resolveParams = (to2) => {
|
|
77
74
|
const params = typeof to2 === "object" && "params" in to2 && typeof to2.params === "object" ? { ...to2.params } : {};
|
|
78
75
|
if (typeof to2 === "string") {
|
|
@@ -83,6 +80,42 @@ function getLocalizedRoute(to, router, route, i18nConfig, locale, hashLocale) {
|
|
|
83
80
|
}
|
|
84
81
|
return params;
|
|
85
82
|
};
|
|
83
|
+
if (i18nConfig.includeDefaultLocaleRoute) {
|
|
84
|
+
const defaultLocale = i18nConfig.defaultLocale;
|
|
85
|
+
let resolvedTo = to;
|
|
86
|
+
if (typeof to === "string") {
|
|
87
|
+
resolvedTo = router.resolve("/" + defaultLocale + to);
|
|
88
|
+
}
|
|
89
|
+
const defaultRouteName = getRouteName(resolvedTo, defaultLocale);
|
|
90
|
+
const newParams2 = resolveParams(to);
|
|
91
|
+
newParams2.locale = defaultLocale;
|
|
92
|
+
if (router.hasRoute(`localized-${defaultRouteName}`)) {
|
|
93
|
+
to = router.resolve({
|
|
94
|
+
name: `localized-${defaultRouteName}`,
|
|
95
|
+
params: newParams2
|
|
96
|
+
});
|
|
97
|
+
} else if (router.hasRoute(`localized-${defaultRouteName}-${defaultLocale}`)) {
|
|
98
|
+
to = router.resolve({
|
|
99
|
+
name: `localized-${defaultRouteName}-${defaultLocale}`,
|
|
100
|
+
params: newParams2
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const currentLocale = locale || getCurrentLocale(route, i18nConfig, hashLocale);
|
|
105
|
+
const selectRoute = router.resolve(to);
|
|
106
|
+
const routeName = getRouteName(selectRoute, currentLocale).replace(new RegExp(`-${i18nConfig.defaultLocale}$`), "");
|
|
107
|
+
if (!routeName || routeName === "") {
|
|
108
|
+
const resolved = router.resolve(to);
|
|
109
|
+
let url = resolved.path.replace(new RegExp(`^/${currentLocale}/`), "/");
|
|
110
|
+
if (currentLocale !== i18nConfig.defaultLocale || i18nConfig.includeDefaultLocaleRoute) {
|
|
111
|
+
url = "/" + currentLocale + url;
|
|
112
|
+
}
|
|
113
|
+
return router.resolve({
|
|
114
|
+
path: url,
|
|
115
|
+
query: selectRoute.query,
|
|
116
|
+
hash: selectRoute.hash
|
|
117
|
+
});
|
|
118
|
+
}
|
|
86
119
|
if (router.hasRoute(`localized-${routeName}-${currentLocale}`)) {
|
|
87
120
|
const newParams2 = resolveParams(selectRoute);
|
|
88
121
|
newParams2.locale = currentLocale;
|
|
@@ -53,7 +53,7 @@ export default defineNuxtPlugin(async (_nuxtApp) => {
|
|
|
53
53
|
if (Object.values(normalizedLocales).length) {
|
|
54
54
|
if (normalizedLocales[currentLocale]) {
|
|
55
55
|
const translation = normalizedLocales[currentLocale];
|
|
56
|
-
const { $mergeTranslations } = useNuxtApp()
|
|
56
|
+
const { $mergeTranslations } = useNuxtApp();
|
|
57
57
|
$mergeTranslations(translation);
|
|
58
58
|
}
|
|
59
59
|
if (!normalizedLocales[currentLocale]) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-i18n-micro",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.30.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",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"dev:build": "nuxi build playground",
|
|
45
45
|
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
46
46
|
"dev:generate": "nuxi generate playground",
|
|
47
|
-
"release": "npm run lint && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
|
|
47
|
+
"release": "npm run lint && npm run typecheck && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
|
|
48
48
|
"lint": "eslint .",
|
|
49
49
|
"lint:fix": "eslint . --fix",
|
|
50
50
|
"test": "playwright test --grep-invert \"test/performance\\.test\\.ts\"",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"id":"dd852be5-e5b6-4c76-85b7-ce1af545045f","timestamp":1729589538009,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|