nuxt-i18n-micro 1.11.0 → 1.11.1
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/{5O6Zkut2.js → BpNRGTHy.js} +1 -1
- package/dist/client/_nuxt/D1fvHJQV.js +119 -0
- package/dist/client/_nuxt/{DulLifOC.js → DxMn4SAe.js} +1 -1
- package/dist/client/_nuxt/{hsW9SqPc.js → DzdJBprQ.js} +1 -1
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/721360c4-039e-4946-a38d-6794f6cf340b.json +1 -0
- package/dist/client/index.html +6 -6
- package/dist/module.json +1 -1
- package/dist/module.mjs +68 -23
- package/dist/runtime/components/i18n-link.vue +1 -1
- package/dist/runtime/components/i18n-switcher.vue +5 -2
- package/dist/runtime/plugins/01.plugin.js +6 -1
- package/dist/runtime/plugins/03.define.js +7 -3
- package/dist/runtime/server/middleware/i18n-redirect.js +5 -0
- package/package.json +1 -1
- package/dist/client/_nuxt/CX2tGbR4.js +0 -119
- package/dist/client/_nuxt/builds/meta/188e6c4c-cf5a-4166-a467-e82e4c5b743c.json +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{i as o,r as u,g as f,h as d,j as v,k as l,l as i,m as h,n as m}from"./
|
|
1
|
+
import{i as o,r as u,g as f,h as d,j as v,k as l,l as i,m as h,n as m}from"./D1fvHJQV.js";function U(t,a={}){const e=a.head||o();if(e)return e.ssr?e.push(t,a):p(e,t,a)}function p(t,a,e={}){const s=u(!1),n=u({});f(()=>{n.value=s.value?{}:d(a)});const r=t.push(n.value,e);return v(n,c=>{r.patch(c)}),m()&&(l(()=>{r.dispose()}),i(()=>{s.value=!0}),h(()=>{s.value=!1})),r}export{U as u};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{u as o}from"./
|
|
1
|
+
import{u as o}from"./DxMn4SAe.js";import{_ as a,o as s,c as i,a as e,t as r,p as u,f as l}from"./D1fvHJQV.js";const c=t=>(u("data-v-b63e9691"),t=t(),l(),t),d={class:"font-sans antialiased bg-white dark:bg-black text-black dark:text-white grid min-h-screen place-content-center overflow-hidden"},p=c(()=>e("div",{class:"fixed -bottom-1/2 left-0 right-0 h-1/2 spotlight"},null,-1)),h={class:"max-w-520px text-center"},b=["textContent"],g=["textContent"],f={__name:"error-500",props:{appName:{type:String,default:"Nuxt"},version:{type:String,default:""},statusCode:{type:Number,default:500},statusMessage:{type:String,default:"Server error"},description:{type:String,default:"This page is temporarily unavailable."}},setup(t){const n=t;return o({title:`${n.statusCode} - ${n.statusMessage} | ${n.appName}`,script:[],style:[{children:'*,:before,:after{box-sizing:border-box;border-width:0;border-style:solid;border-color:var(--un-default-border-color, #e5e7eb)}:before,:after{--un-content:""}html{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;tab-size:4;font-family:ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji",Segoe UI Symbol,"Noto Color Emoji";font-feature-settings:normal;font-variation-settings:normal;-webkit-tap-highlight-color:transparent}body{margin:0;line-height:inherit}h1{font-size:inherit;font-weight:inherit}h1,p{margin:0}*,:before,:after{--un-rotate:0;--un-rotate-x:0;--un-rotate-y:0;--un-rotate-z:0;--un-scale-x:1;--un-scale-y:1;--un-scale-z:1;--un-skew-x:0;--un-skew-y:0;--un-translate-x:0;--un-translate-y:0;--un-translate-z:0;--un-pan-x: ;--un-pan-y: ;--un-pinch-zoom: ;--un-scroll-snap-strictness:proximity;--un-ordinal: ;--un-slashed-zero: ;--un-numeric-figure: ;--un-numeric-spacing: ;--un-numeric-fraction: ;--un-border-spacing-x:0;--un-border-spacing-y:0;--un-ring-offset-shadow:0 0 rgb(0 0 0 / 0);--un-ring-shadow:0 0 rgb(0 0 0 / 0);--un-shadow-inset: ;--un-shadow:0 0 rgb(0 0 0 / 0);--un-ring-inset: ;--un-ring-offset-width:0px;--un-ring-offset-color:#fff;--un-ring-width:0px;--un-ring-color:rgb(147 197 253 / .5);--un-blur: ;--un-brightness: ;--un-contrast: ;--un-drop-shadow: ;--un-grayscale: ;--un-hue-rotate: ;--un-invert: ;--un-saturate: ;--un-sepia: ;--un-backdrop-blur: ;--un-backdrop-brightness: ;--un-backdrop-contrast: ;--un-backdrop-grayscale: ;--un-backdrop-hue-rotate: ;--un-backdrop-invert: ;--un-backdrop-opacity: ;--un-backdrop-saturate: ;--un-backdrop-sepia: }'}]}),(m,x)=>(s(),i("div",d,[p,e("div",h,[e("h1",{class:"text-8xl sm:text-10xl font-medium mb-8",textContent:r(t.statusCode)},null,8,b),e("p",{class:"text-xl px-8 sm:px-0 sm:text-4xl font-light mb-16 leading-tight",textContent:r(t.description)},null,8,g)])]))}},w=a(f,[["__scopeId","data-v-b63e9691"]]);export{w as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"id":"
|
|
1
|
+
{"id":"721360c4-039e-4946-a38d-6794f6cf340b","timestamp":1725113752053}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"id":"721360c4-039e-4946-a38d-6794f6cf340b","timestamp":1725113752053,"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.DjxsrOxm.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/D1fvHJQV.js">
|
|
5
5
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/B6E6ObS_.js">
|
|
6
6
|
<link rel="prefetch" as="style" href="/__nuxt-i18n-micro/_nuxt/error-404.D-AvUzLt.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/BpNRGTHy.js">
|
|
8
|
+
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/DxMn4SAe.js">
|
|
9
9
|
<link rel="prefetch" as="style" href="/__nuxt-i18n-micro/_nuxt/error-500.21ZDxC33.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/DzdJBprQ.js">
|
|
11
|
+
<script type="module" src="/__nuxt-i18n-micro/_nuxt/D1fvHJQV.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__">[{"serverRendered":1},false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"721360c4-039e-4946-a38d-6794f6cf340b",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -186,16 +186,24 @@ const module = defineNuxtModule({
|
|
|
186
186
|
const pagesDir = path.resolve(nuxt.options.rootDir, options.translationDir, "pages");
|
|
187
187
|
extendPages((pages) => {
|
|
188
188
|
const customPaths = {};
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
189
|
+
function extractCustomPaths(pages2, parentPath = "") {
|
|
190
|
+
for (const page of pages2) {
|
|
191
|
+
if (page.file) {
|
|
192
|
+
const filePath = path.resolve(nuxt.options.rootDir, page.file);
|
|
193
|
+
const fileContent = readFileSync(filePath, "utf-8");
|
|
194
|
+
const i18nRouteConfig = extractDefineI18nRouteConfig(fileContent, filePath);
|
|
195
|
+
if (i18nRouteConfig && i18nRouteConfig.localeRoutes) {
|
|
196
|
+
const fullPath = parentPath ? `${parentPath}/${page.path}` : page.path;
|
|
197
|
+
customPaths[fullPath] = i18nRouteConfig.localeRoutes;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (page.children && page.children.length > 0) {
|
|
201
|
+
const fullParentName = parentPath ? `${parentPath}/${page.path}` : page.path;
|
|
202
|
+
extractCustomPaths(page.children, fullParentName);
|
|
196
203
|
}
|
|
197
204
|
}
|
|
198
205
|
}
|
|
206
|
+
extractCustomPaths(pages);
|
|
199
207
|
const pagesNames = pages.map((page) => page.name).filter((name) => name && (!options.routesLocaleLinks || !options.routesLocaleLinks[name]));
|
|
200
208
|
function ensureFileExists(filePath) {
|
|
201
209
|
const fileDir = path.dirname(filePath);
|
|
@@ -218,6 +226,38 @@ const module = defineNuxtModule({
|
|
|
218
226
|
});
|
|
219
227
|
const newRoutes = [];
|
|
220
228
|
for (let i = 0; i < pages.length; i++) {
|
|
229
|
+
let localizeChildren = function(routes, parentPath = "") {
|
|
230
|
+
if (!parentPath.startsWith("/")) {
|
|
231
|
+
parentPath = "/" + parentPath;
|
|
232
|
+
}
|
|
233
|
+
return routes.map((route) => {
|
|
234
|
+
const fullPath = parentPath ? `${parentPath}/${route.path}` : route.path;
|
|
235
|
+
const customLocalePaths = customPaths[fullPath];
|
|
236
|
+
const localizedChildren = route.children ? localizeChildren(route.children, fullPath) : [];
|
|
237
|
+
const localizedRoutes = locales.map((locale) => {
|
|
238
|
+
let path2 = customLocalePaths && customLocalePaths[locale.code] ? `${customLocalePaths[locale.code]}` : `${fullPath}`;
|
|
239
|
+
if (path2.startsWith("/")) {
|
|
240
|
+
path2 = path2.slice(1);
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
...route,
|
|
244
|
+
name: `localized-${route.name}-${locale.code}`,
|
|
245
|
+
path: path2,
|
|
246
|
+
children: localizedChildren
|
|
247
|
+
// Use localized children
|
|
248
|
+
};
|
|
249
|
+
});
|
|
250
|
+
if (customLocalePaths) {
|
|
251
|
+
return localizedRoutes;
|
|
252
|
+
}
|
|
253
|
+
return {
|
|
254
|
+
...route,
|
|
255
|
+
name: `localized-${route.name}`,
|
|
256
|
+
children: localizedChildren
|
|
257
|
+
// Use localized children
|
|
258
|
+
};
|
|
259
|
+
}).flat();
|
|
260
|
+
};
|
|
221
261
|
const page = pages[i];
|
|
222
262
|
if (page.redirect && !page.file) {
|
|
223
263
|
continue;
|
|
@@ -230,17 +270,6 @@ const module = defineNuxtModule({
|
|
|
230
270
|
});
|
|
231
271
|
}
|
|
232
272
|
});
|
|
233
|
-
const newRoute = {
|
|
234
|
-
file: page.file,
|
|
235
|
-
meta: { ...page.meta },
|
|
236
|
-
alias: page.alias,
|
|
237
|
-
redirect: page.redirect,
|
|
238
|
-
children: page.children,
|
|
239
|
-
mode: page.mode,
|
|
240
|
-
path: `/:locale(${modLocaleRegex.join("|")})${page.path}`,
|
|
241
|
-
name: `localized-${page.name}`
|
|
242
|
-
};
|
|
243
|
-
newRoutes.push(newRoute);
|
|
244
273
|
if (customPaths[page.path]) {
|
|
245
274
|
locales.forEach((locale) => {
|
|
246
275
|
if (customPaths[page.path][locale.code]) {
|
|
@@ -258,6 +287,20 @@ const module = defineNuxtModule({
|
|
|
258
287
|
}
|
|
259
288
|
});
|
|
260
289
|
}
|
|
290
|
+
if (!modLocaleRegex.length && !page.children?.length) {
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
const newRoute = {
|
|
294
|
+
file: page.file,
|
|
295
|
+
meta: { ...page.meta },
|
|
296
|
+
alias: page.alias,
|
|
297
|
+
redirect: page.redirect,
|
|
298
|
+
children: page.children ? localizeChildren(page.children, page.name) : [],
|
|
299
|
+
mode: page.mode,
|
|
300
|
+
path: `/:locale(${modLocaleRegex.join("|")})${page.path}`,
|
|
301
|
+
name: `localized-${page.name}`
|
|
302
|
+
};
|
|
303
|
+
newRoutes.push(newRoute);
|
|
261
304
|
}
|
|
262
305
|
pages.push(...newRoutes);
|
|
263
306
|
nuxt.options.generate.routes = Array.isArray(nuxt.options.generate.routes) ? nuxt.options.generate.routes : [];
|
|
@@ -354,12 +397,14 @@ function extractDefineI18nRouteConfig(content, path2) {
|
|
|
354
397
|
function validateDefineI18nRouteConfig(obj) {
|
|
355
398
|
if (typeof obj !== "object" || obj === null)
|
|
356
399
|
return false;
|
|
357
|
-
if (
|
|
358
|
-
|
|
359
|
-
for (const localeKey in obj.locales) {
|
|
360
|
-
const translations = obj.locales[localeKey];
|
|
361
|
-
if (typeof translations !== "object" || translations === null)
|
|
400
|
+
if (obj.locales) {
|
|
401
|
+
if (typeof obj.locales !== "object")
|
|
362
402
|
return false;
|
|
403
|
+
for (const localeKey in obj.locales) {
|
|
404
|
+
const translations = obj.locales[localeKey];
|
|
405
|
+
if (typeof translations !== "object" || translations === null)
|
|
406
|
+
return false;
|
|
407
|
+
}
|
|
363
408
|
}
|
|
364
409
|
if (obj.localeRoutes) {
|
|
365
410
|
if (typeof obj.localeRoutes !== "object")
|
|
@@ -66,7 +66,7 @@ const props = withDefaults(defineProps<Props>(), {
|
|
|
66
66
|
|
|
67
67
|
const { $localeRoute, $getLocales, $getLocale } = useNuxtApp()
|
|
68
68
|
const locales = ref($getLocales())
|
|
69
|
-
const currentLocale =
|
|
69
|
+
const currentLocale = computed(() => $getLocale())
|
|
70
70
|
const dropdownOpen = ref(false)
|
|
71
71
|
|
|
72
72
|
const toggleDropdown = () => {
|
|
@@ -81,7 +81,10 @@ const currentLocaleLabel = computed(() => localeLabel({ code: currentLocale.valu
|
|
|
81
81
|
|
|
82
82
|
const getLocaleLink = (locale: Locale) => {
|
|
83
83
|
const route = useRoute()
|
|
84
|
-
const routeName = (route?.name ?? '').toString()
|
|
84
|
+
const routeName = (route?.name ?? '').toString()
|
|
85
|
+
.replace(`localized-`, '')
|
|
86
|
+
.replace(new RegExp(`-${currentLocale.value}$`), '')
|
|
87
|
+
.replace(new RegExp(`-${locale}$`), '')
|
|
85
88
|
|
|
86
89
|
return $localeRoute({ name: routeName }, locale.code)
|
|
87
90
|
}
|
|
@@ -74,7 +74,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
74
74
|
const i18nConfig = config.public.i18nConfig;
|
|
75
75
|
const plural = new Function("return " + i18nConfig.plural)();
|
|
76
76
|
const initialLocale = getCurrentLocale(route, i18nConfig);
|
|
77
|
-
if (!i18nHelper.hasGeneralTranslation(initialLocale)) {
|
|
77
|
+
if (import.meta.server && !i18nHelper.hasGeneralTranslation(initialLocale)) {
|
|
78
78
|
const data = await $fetch(`/_locales/general/${initialLocale}/data.json?v=${i18nConfig.dateBuild}`, { baseURL: i18nConfig.baseURL });
|
|
79
79
|
await i18nHelper.loadTranslations(initialLocale, data ?? {});
|
|
80
80
|
}
|
|
@@ -94,6 +94,11 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
94
94
|
await loadTranslationsIfNeeded(locale, initialRouteName);
|
|
95
95
|
}
|
|
96
96
|
useRouter().beforeEach(async (to, from, next) => {
|
|
97
|
+
if (import.meta.client) {
|
|
98
|
+
const locale = getCurrentLocale(to, i18nConfig);
|
|
99
|
+
const data = await $fetch(`/_locales/general/${locale}/data.json?v=${i18nConfig.dateBuild}`, { baseURL: i18nConfig.baseURL });
|
|
100
|
+
await i18nHelper.loadTranslations(locale, data ?? {});
|
|
101
|
+
}
|
|
97
102
|
if (import.meta.client && !i18nConfig.disablePageLocales) {
|
|
98
103
|
const locale = getCurrentLocale(to, i18nConfig);
|
|
99
104
|
const routeName = getRouteName(to, locale);
|
|
@@ -20,17 +20,21 @@ export default defineNuxtPlugin((_nuxtApp) => {
|
|
|
20
20
|
const currentLocale = (route.params.locale || i18nConfig.defaultLocale).toString();
|
|
21
21
|
const normalizedLocales = normalizeLocales(routeDefinition.locales);
|
|
22
22
|
const { name } = route;
|
|
23
|
-
if (normalizedLocales[currentLocale]) {
|
|
23
|
+
if (!Object.values(normalizedLocales).length || normalizedLocales[currentLocale]) {
|
|
24
24
|
const translation = normalizedLocales[currentLocale];
|
|
25
25
|
const nuxtApp = useNuxtApp();
|
|
26
26
|
nuxtApp.$mergeTranslations(translation);
|
|
27
27
|
} else {
|
|
28
|
-
let defaultRouteName = name?.toString().replace("localized-", "");
|
|
28
|
+
let defaultRouteName = name?.toString().replace("localized-", "").replace(new RegExp(`-${currentLocale}$`), "");
|
|
29
29
|
const resolvedRoute = router.resolve({ name: defaultRouteName });
|
|
30
30
|
const newParams = { ...route.params };
|
|
31
31
|
delete newParams.locale;
|
|
32
32
|
if (i18nConfig.includeDefaultLocaleRoute) {
|
|
33
|
-
|
|
33
|
+
if (router.hasRoute(`localized-${defaultRouteName}-${currentLocale}`)) {
|
|
34
|
+
defaultRouteName = `localized-${defaultRouteName}-${currentLocale}`;
|
|
35
|
+
} else {
|
|
36
|
+
defaultRouteName = `localized-${defaultRouteName}`;
|
|
37
|
+
}
|
|
34
38
|
newParams.locale = i18nConfig.defaultLocale;
|
|
35
39
|
newParams.name = defaultRouteName;
|
|
36
40
|
}
|
|
@@ -9,6 +9,11 @@ export default defineEventHandler(async (event) => {
|
|
|
9
9
|
const locales = i18nConfig.locales || [];
|
|
10
10
|
const pathParts = event.path.split("/").filter(Boolean);
|
|
11
11
|
const localeCode = pathParts[0];
|
|
12
|
+
const lastPart = pathParts[pathParts.length - 1];
|
|
13
|
+
const hasFileExtension = /\.[^/?]+(?:\?.*)?$/.test(lastPart);
|
|
14
|
+
if (hasFileExtension) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
12
17
|
const locale = locales.find((loc) => loc.code === localeCode);
|
|
13
18
|
if (!locale) {
|
|
14
19
|
const newPath = `/${i18nConfig.defaultLocale}/${pathParts.join("/")}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-i18n-micro",
|
|
3
|
-
"version": "1.11.
|
|
3
|
+
"version": "1.11.1",
|
|
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",
|