nuxt-i18n-micro 1.14.0 → 1.15.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 +6 -6
- package/dist/client/404.html +6 -6
- package/dist/client/_nuxt/CrMD8tE2.js +1 -0
- package/dist/client/_nuxt/D4krr5Cl.js +119 -0
- package/dist/client/_nuxt/DKQku3vX.js +1 -0
- package/dist/client/_nuxt/DrbVAtr9.js +1 -0
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/1b227ff9-c2d8-4498-a2d2-9e203ce63363.json +1 -0
- package/dist/client/index.html +6 -6
- package/dist/module.d.mts +2 -0
- package/dist/module.d.ts +2 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +4 -0
- package/dist/runtime/components/i18n-t.vue.d.ts +4 -4
- package/dist/runtime/composables/useLocaleHead.d.ts +36 -0
- package/dist/runtime/plugins/01.plugin.d.ts +2 -2
- package/dist/runtime/plugins/01.plugin.js +24 -34
- package/dist/runtime/plugins/03.define.d.ts +2 -2
- package/dist/runtime/plugins/03.define.js +22 -4
- package/dist/runtime/plugins/04.auto-detect.js +2 -1
- package/dist/runtime/server/middleware/i18n-loader.js +32 -7
- package/package.json +5 -5
- package/dist/client/_nuxt/BpNRGTHy.js +0 -1
- package/dist/client/_nuxt/D1fvHJQV.js +0 -119
- package/dist/client/_nuxt/DxMn4SAe.js +0 -1
- package/dist/client/_nuxt/DzdJBprQ.js +0 -1
- package/dist/client/_nuxt/builds/meta/cef9112f-2f86-40b3-9815-286383780fe2.json +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{u as a}from"./CrMD8tE2.js";import{_ as s,o as i,c as u,a as t,t as o}from"./D4krr5Cl.js";const l={class:"font-sans antialiased bg-white dark:bg-black text-black dark:text-white grid min-h-screen place-content-center overflow-hidden"},c={class:"max-w-520px text-center"},d=["textContent"],p=["textContent"],g={__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(e){const n=e;return a({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: }'}]}),(b,r)=>(i(),u("div",l,[r[0]||(r[0]=t("div",{class:"fixed -bottom-1/2 left-0 right-0 h-1/2 spotlight"},null,-1)),t("div",c,[t("h1",{class:"text-8xl sm:text-10xl font-medium mb-8",textContent:o(e.statusCode)},null,8,d),t("p",{class:"text-xl px-8 sm:px-0 sm:text-4xl font-light mb-16 leading-tight",textContent:o(e.description)},null,8,p)])]))}},m=s(g,[["__scopeId","data-v-b63e9691"]]);export{m as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{_ as s,o as i,c as u,a as t,t as o,b as l,w as c,d,e as p}from"./D4krr5Cl.js";import{u as f}from"./CrMD8tE2.js";const g={class:"font-sans antialiased bg-white dark:bg-black text-black dark:text-white grid min-h-screen place-content-center overflow-hidden"},b={class:"max-w-520px text-center z-20"},h=["textContent"],x=["textContent"],m={class:"w-full flex items-center justify-center"},y={__name:"error-404",props:{appName:{type:String,default:"Nuxt"},version:{type:String,default:""},statusCode:{type:Number,default:404},statusMessage:{type:String,default:"Not Found"},description:{type:String,default:"Sorry, the page you are looking for could not be found."},backHome:{type:String,default:"Go back home"}},setup(e){const n=e;return f({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}a{color:inherit;text-decoration: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: }'}]}),(k,r)=>{const a=p;return i(),u("div",g,[r[0]||(r[0]=t("div",{class:"fixed left-0 right-0 spotlight z-10"},null,-1)),t("div",b,[t("h1",{class:"text-8xl sm:text-10xl font-medium mb-8",textContent:o(e.statusCode)},null,8,h),t("p",{class:"text-xl px-8 sm:px-0 sm:text-4xl font-light mb-16 leading-tight",textContent:o(e.description)},null,8,x),t("div",m,[l(a,{to:"/",class:"gradient-border text-md sm:text-xl py-2 px-4 sm:py-3 sm:px-6 cursor-pointer"},{default:c(()=>[d(o(e.backHome),1)]),_:1})])])])}}},z=s(y,[["__scopeId","data-v-83de2354"]]);export{z as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"id":"
|
|
1
|
+
{"id":"1b227ff9-c2d8-4498-a2d2-9e203ce63363","timestamp":1725618374874}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"id":"1b227ff9-c2d8-4498-a2d2-9e203ce63363","timestamp":1725618374874,"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/D4krr5Cl.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/DrbVAtr9.js">
|
|
8
|
+
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/CrMD8tE2.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/DKQku3vX.js">
|
|
11
|
+
<script type="module" src="/__nuxt-i18n-micro/_nuxt/D4krr5Cl.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:"1b227ff9-c2d8-4498-a2d2-9e203ce63363",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
package/dist/module.d.mts
CHANGED
|
@@ -21,6 +21,8 @@ interface ModuleOptions {
|
|
|
21
21
|
routesLocaleLinks?: Record<string, string>;
|
|
22
22
|
plural?: string;
|
|
23
23
|
disablePageLocales?: boolean;
|
|
24
|
+
fallbackLocale?: string;
|
|
25
|
+
localeCookie?: string;
|
|
24
26
|
}
|
|
25
27
|
interface ModuleOptionsExtend extends ModuleOptions {
|
|
26
28
|
plural: string;
|
package/dist/module.d.ts
CHANGED
|
@@ -21,6 +21,8 @@ interface ModuleOptions {
|
|
|
21
21
|
routesLocaleLinks?: Record<string, string>;
|
|
22
22
|
plural?: string;
|
|
23
23
|
disablePageLocales?: boolean;
|
|
24
|
+
fallbackLocale?: string;
|
|
25
|
+
localeCookie?: string;
|
|
24
26
|
}
|
|
25
27
|
interface ModuleOptionsExtend extends ModuleOptions {
|
|
26
28
|
plural: string;
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -347,6 +347,8 @@ const module = defineNuxtModule({
|
|
|
347
347
|
disablePageLocales: false,
|
|
348
348
|
disableWatcher: false,
|
|
349
349
|
includeDefaultLocaleRoute: false,
|
|
350
|
+
fallbackLocale: void 0,
|
|
351
|
+
localeCookie: "user-locale",
|
|
350
352
|
routesLocaleLinks: {},
|
|
351
353
|
plural: `function (translation, count, _locale) {
|
|
352
354
|
const forms = translation.toString().split('|')
|
|
@@ -373,10 +375,12 @@ const module = defineNuxtModule({
|
|
|
373
375
|
disableWatcher: options.disableWatcher ?? false,
|
|
374
376
|
defaultLocale: options.defaultLocale ?? "en",
|
|
375
377
|
translationDir: options.translationDir ?? "locales",
|
|
378
|
+
localeCookie: options.localeCookie ?? "user-locale",
|
|
376
379
|
autoDetectLanguage: options.autoDetectLanguage ?? true,
|
|
377
380
|
autoDetectPath: options.autoDetectPath ?? "*",
|
|
378
381
|
includeDefaultLocaleRoute: options.includeDefaultLocaleRoute ?? false,
|
|
379
382
|
routesLocaleLinks: options.routesLocaleLinks ?? {},
|
|
383
|
+
fallbackLocale: options.fallbackLocale ?? void 0,
|
|
380
384
|
dateBuild: Date.now(),
|
|
381
385
|
baseURL: nuxt.options.app.baseURL
|
|
382
386
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
declare const _default: import("vue").DefineComponent<{
|
|
1
|
+
declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
2
2
|
keypath: {
|
|
3
3
|
type: StringConstructor;
|
|
4
4
|
required: true;
|
|
@@ -30,7 +30,7 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
30
30
|
type: FunctionConstructor;
|
|
31
31
|
default: null;
|
|
32
32
|
};
|
|
33
|
-
}
|
|
33
|
+
}>, () => any, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
34
34
|
keypath: {
|
|
35
35
|
type: StringConstructor;
|
|
36
36
|
required: true;
|
|
@@ -62,12 +62,12 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
62
62
|
type: FunctionConstructor;
|
|
63
63
|
default: null;
|
|
64
64
|
};
|
|
65
|
-
}
|
|
65
|
+
}>> & Readonly<{}>, {
|
|
66
66
|
tag: string;
|
|
67
67
|
params: Record<string, any>;
|
|
68
68
|
defaultValue: string;
|
|
69
69
|
html: boolean;
|
|
70
70
|
hideIfEmpty: boolean;
|
|
71
71
|
customPluralRule: Function;
|
|
72
|
-
}, {}>;
|
|
72
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
73
73
|
export default _default;
|
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
interface MetaLink {
|
|
2
|
+
[key: string]: string | undefined;
|
|
3
|
+
rel: string;
|
|
4
|
+
href: string;
|
|
5
|
+
hreflang?: string;
|
|
6
|
+
}
|
|
7
|
+
interface MetaTag {
|
|
8
|
+
[key: string]: string;
|
|
9
|
+
property: string;
|
|
10
|
+
content: string;
|
|
11
|
+
}
|
|
12
|
+
interface MetaObject {
|
|
13
|
+
htmlAttrs: {
|
|
14
|
+
lang?: string;
|
|
15
|
+
dir?: 'ltr' | 'rtl' | 'auto';
|
|
16
|
+
};
|
|
17
|
+
link: MetaLink[];
|
|
18
|
+
meta: MetaTag[];
|
|
19
|
+
}
|
|
1
20
|
export declare const useLocaleHead: ({ addDirAttribute, identifierAttribute, addSeoAttributes, baseUrl }?: {
|
|
2
21
|
addDirAttribute?: boolean | undefined;
|
|
3
22
|
identifierAttribute?: string | undefined;
|
|
@@ -19,4 +38,21 @@ export declare const useLocaleHead: ({ addDirAttribute, identifierAttribute, add
|
|
|
19
38
|
property: string;
|
|
20
39
|
content: string;
|
|
21
40
|
}[];
|
|
41
|
+
}, MetaObject | {
|
|
42
|
+
htmlAttrs: {
|
|
43
|
+
lang?: string | undefined;
|
|
44
|
+
dir?: ("ltr" | "rtl" | "auto") | undefined;
|
|
45
|
+
};
|
|
46
|
+
link: {
|
|
47
|
+
[x: string]: string | undefined;
|
|
48
|
+
rel: string;
|
|
49
|
+
href: string;
|
|
50
|
+
hreflang?: string | undefined;
|
|
51
|
+
}[];
|
|
52
|
+
meta: {
|
|
53
|
+
[x: string]: string;
|
|
54
|
+
property: string;
|
|
55
|
+
content: string;
|
|
56
|
+
}[];
|
|
22
57
|
}>;
|
|
58
|
+
export {};
|
|
@@ -17,7 +17,7 @@ declare const _default: import("#app").Plugin<{
|
|
|
17
17
|
td: (value: Date | number | string, options?: Intl.DateTimeFormatOptions) => string;
|
|
18
18
|
has: (key: string) => boolean;
|
|
19
19
|
mergeTranslations: (newTranslations: Translations) => void;
|
|
20
|
-
switchLocale: (
|
|
20
|
+
switchLocale: (toLocale: string) => void;
|
|
21
21
|
localeRoute: (to: RouteLocationRaw, locale?: string) => RouteLocationRaw;
|
|
22
22
|
}> & import("#app").ObjectPlugin<{
|
|
23
23
|
getLocale: () => string;
|
|
@@ -29,7 +29,7 @@ declare const _default: import("#app").Plugin<{
|
|
|
29
29
|
td: (value: Date | number | string, options?: Intl.DateTimeFormatOptions) => string;
|
|
30
30
|
has: (key: string) => boolean;
|
|
31
31
|
mergeTranslations: (newTranslations: Translations) => void;
|
|
32
|
-
switchLocale: (
|
|
32
|
+
switchLocale: (toLocale: string) => void;
|
|
33
33
|
localeRoute: (to: RouteLocationRaw, locale?: string) => RouteLocationRaw;
|
|
34
34
|
}>;
|
|
35
35
|
export default _default;
|
|
@@ -12,26 +12,26 @@ function getCurrentLocale(route, i18nConfig) {
|
|
|
12
12
|
function getRouteName(route, locale) {
|
|
13
13
|
return (route?.name ?? "").toString().replace("localized-", "").replace(new RegExp(`-${locale}$`), "");
|
|
14
14
|
}
|
|
15
|
-
function switchLocale(
|
|
16
|
-
const checkLocale = i18nConfig.locales?.find((l) => l.code ===
|
|
15
|
+
function switchLocale(fromLocale, toLocale, route, router, i18nConfig) {
|
|
16
|
+
const checkLocale = i18nConfig.locales?.find((l) => l.code === toLocale);
|
|
17
17
|
if (!checkLocale) {
|
|
18
|
-
console.warn(`Locale ${
|
|
19
|
-
return Promise.reject(`Locale ${
|
|
18
|
+
console.warn(`Locale ${toLocale} is not available`);
|
|
19
|
+
return Promise.reject(`Locale ${toLocale} is not available`);
|
|
20
20
|
}
|
|
21
|
-
const routeName = getRouteName(route,
|
|
22
|
-
if (router.hasRoute(`localized-${routeName}-${
|
|
21
|
+
const routeName = getRouteName(route, fromLocale);
|
|
22
|
+
if (router.hasRoute(`localized-${routeName}-${toLocale}`)) {
|
|
23
23
|
const newParams2 = { ...route.params };
|
|
24
|
-
newParams2.locale =
|
|
24
|
+
newParams2.locale = toLocale;
|
|
25
25
|
return router.push({
|
|
26
26
|
params: newParams2,
|
|
27
|
-
name: `localized-${routeName}-${
|
|
27
|
+
name: `localized-${routeName}-${toLocale}`
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
|
-
const newRouteName =
|
|
30
|
+
const newRouteName = toLocale !== i18nConfig.defaultLocale || i18nConfig.includeDefaultLocaleRoute ? `localized-${routeName}` : routeName;
|
|
31
31
|
const newParams = { ...route.params };
|
|
32
32
|
delete newParams.locale;
|
|
33
|
-
if (
|
|
34
|
-
newParams.locale =
|
|
33
|
+
if (toLocale !== i18nConfig.defaultLocale || i18nConfig.includeDefaultLocaleRoute) {
|
|
34
|
+
newParams.locale = toLocale;
|
|
35
35
|
}
|
|
36
36
|
return router.push({ name: newRouteName, params: newParams });
|
|
37
37
|
}
|
|
@@ -75,15 +75,9 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
75
75
|
if (!nuxtApp.payload.data.translations) {
|
|
76
76
|
nuxtApp.payload.data.translations = {};
|
|
77
77
|
}
|
|
78
|
-
const route = useRoute();
|
|
79
78
|
const config = useRuntimeConfig();
|
|
80
79
|
const i18nConfig = config.public.i18nConfig;
|
|
81
80
|
const plural = new Function("return " + i18nConfig.plural)();
|
|
82
|
-
const initialLocale = getCurrentLocale(route, i18nConfig);
|
|
83
|
-
if (import.meta.server && !i18nHelper.hasGeneralTranslation(initialLocale)) {
|
|
84
|
-
const data = await $fetch(`/_locales/general/${initialLocale}/data.json?v=${i18nConfig.dateBuild}`, { baseURL: i18nConfig.baseURL });
|
|
85
|
-
await i18nHelper.loadTranslations(initialLocale, data ?? {});
|
|
86
|
-
}
|
|
87
81
|
const loadTranslationsIfNeeded = async (locale, routeName) => {
|
|
88
82
|
if (!i18nHelper.hasPageTranslation(locale, routeName)) {
|
|
89
83
|
let fRouteName = routeName;
|
|
@@ -94,18 +88,13 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
94
88
|
await i18nHelper.loadPageTranslations(locale, routeName, data ?? {});
|
|
95
89
|
}
|
|
96
90
|
};
|
|
97
|
-
if (import.meta.server && !i18nConfig.disablePageLocales) {
|
|
98
|
-
const locale = getCurrentLocale(route, i18nConfig);
|
|
99
|
-
const initialRouteName = getRouteName(route, locale);
|
|
100
|
-
await loadTranslationsIfNeeded(locale, initialRouteName);
|
|
101
|
-
}
|
|
102
91
|
useRouter().beforeEach(async (to, from, next) => {
|
|
103
92
|
const locale = getCurrentLocale(to, i18nConfig);
|
|
104
|
-
if (
|
|
93
|
+
if (!i18nHelper.hasGeneralTranslation(locale)) {
|
|
105
94
|
const data = await $fetch(`/_locales/general/${locale}/data.json?v=${i18nConfig.dateBuild}`, { baseURL: i18nConfig.baseURL });
|
|
106
95
|
await i18nHelper.loadTranslations(locale, data ?? {});
|
|
107
96
|
}
|
|
108
|
-
if (
|
|
97
|
+
if (!i18nConfig.disablePageLocales) {
|
|
109
98
|
const routeName = getRouteName(to, locale);
|
|
110
99
|
await loadTranslationsIfNeeded(locale, routeName);
|
|
111
100
|
}
|
|
@@ -132,9 +121,9 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
132
121
|
provide: {
|
|
133
122
|
getLocale: () => getCurrentLocale(useRoute(), i18nConfig),
|
|
134
123
|
getLocales: () => i18nConfig.locales || [],
|
|
135
|
-
getRouteName: (
|
|
124
|
+
getRouteName: (route, locale) => {
|
|
136
125
|
const selectedLocale = locale ?? getCurrentLocale(useRoute(), i18nConfig);
|
|
137
|
-
const selectedRoute =
|
|
126
|
+
const selectedRoute = route ?? useRoute();
|
|
138
127
|
return getRouteName(selectedRoute, selectedLocale);
|
|
139
128
|
},
|
|
140
129
|
t: getTranslation,
|
|
@@ -154,20 +143,21 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
154
143
|
return !!getTranslation(key);
|
|
155
144
|
},
|
|
156
145
|
mergeTranslations: (newTranslations) => {
|
|
157
|
-
const
|
|
158
|
-
const locale = getCurrentLocale(
|
|
159
|
-
const routeName = getRouteName(
|
|
146
|
+
const route = useRoute();
|
|
147
|
+
const locale = getCurrentLocale(route, i18nConfig);
|
|
148
|
+
const routeName = getRouteName(route, locale);
|
|
160
149
|
i18nHelper.mergeTranslation(locale, routeName, newTranslations);
|
|
161
150
|
},
|
|
162
|
-
switchLocale: (
|
|
151
|
+
switchLocale: (toLocale) => {
|
|
163
152
|
const router = useRouter();
|
|
164
|
-
const
|
|
165
|
-
|
|
153
|
+
const route = useRoute();
|
|
154
|
+
const fromLocale = getCurrentLocale(route, i18nConfig);
|
|
155
|
+
switchLocale(fromLocale, toLocale, route, router, i18nConfig);
|
|
166
156
|
},
|
|
167
157
|
localeRoute: (to, locale) => {
|
|
168
158
|
const router = useRouter();
|
|
169
|
-
const
|
|
170
|
-
return getLocalizedRoute(to, router,
|
|
159
|
+
const route = useRoute();
|
|
160
|
+
return getLocalizedRoute(to, router, route, i18nConfig, locale);
|
|
171
161
|
}
|
|
172
162
|
}
|
|
173
163
|
};
|
|
@@ -2,11 +2,11 @@ declare const _default: import("#app").Plugin<{
|
|
|
2
2
|
defineI18nRoute: (routeDefinition: {
|
|
3
3
|
locales?: string[] | Record<string, Record<string, string>>;
|
|
4
4
|
localeRoutes?: Record<string, string>;
|
|
5
|
-
}) => Promise<void>;
|
|
5
|
+
}) => Promise<void | import("vue-router").NavigationFailure>;
|
|
6
6
|
}> & import("#app").ObjectPlugin<{
|
|
7
7
|
defineI18nRoute: (routeDefinition: {
|
|
8
8
|
locales?: string[] | Record<string, Record<string, string>>;
|
|
9
9
|
localeRoutes?: Record<string, string>;
|
|
10
|
-
}) => Promise<void>;
|
|
10
|
+
}) => Promise<void | import("vue-router").NavigationFailure>;
|
|
11
11
|
}>;
|
|
12
12
|
export default _default;
|
|
@@ -38,10 +38,28 @@ export default defineNuxtPlugin((_nuxtApp) => {
|
|
|
38
38
|
const defineI18nRoute = async (routeDefinition) => {
|
|
39
39
|
const currentLocale = (route.params.locale || i18nConfig.defaultLocale).toString();
|
|
40
40
|
const normalizedLocales = normalizeLocales(routeDefinition.locales);
|
|
41
|
-
if (
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
if (Object.values(normalizedLocales).length) {
|
|
42
|
+
if (normalizedLocales[currentLocale]) {
|
|
43
|
+
const translation = normalizedLocales[currentLocale];
|
|
44
|
+
const nuxtApp = useNuxtApp();
|
|
45
|
+
nuxtApp.$mergeTranslations(translation);
|
|
46
|
+
}
|
|
47
|
+
if (!normalizedLocales[currentLocale]) {
|
|
48
|
+
let defaultRouteName = route.name?.toString().replace("localized-", "").replace(new RegExp(`-${currentLocale}$`), "");
|
|
49
|
+
const resolvedRoute = router.resolve({ name: defaultRouteName });
|
|
50
|
+
const newParams = { ...route.params };
|
|
51
|
+
delete newParams.locale;
|
|
52
|
+
if (i18nConfig.includeDefaultLocaleRoute) {
|
|
53
|
+
if (router.hasRoute(`localized-${defaultRouteName}-${currentLocale}`)) {
|
|
54
|
+
defaultRouteName = `localized-${defaultRouteName}-${currentLocale}`;
|
|
55
|
+
} else {
|
|
56
|
+
defaultRouteName = `localized-${defaultRouteName}`;
|
|
57
|
+
}
|
|
58
|
+
newParams.locale = i18nConfig.defaultLocale;
|
|
59
|
+
newParams.name = defaultRouteName;
|
|
60
|
+
}
|
|
61
|
+
return router.push(resolvedRoute);
|
|
62
|
+
}
|
|
45
63
|
}
|
|
46
64
|
};
|
|
47
65
|
return {
|
|
@@ -2,7 +2,7 @@ import { defineNuxtPlugin, useCookie, useRequestHeaders, navigateTo } from "#app
|
|
|
2
2
|
import { useRoute, useRouter } from "#imports";
|
|
3
3
|
export default defineNuxtPlugin(async (nuxtApp) => {
|
|
4
4
|
const i18nConfig = nuxtApp.$config.public.i18nConfig;
|
|
5
|
-
const userLocaleCookie = useCookie("user-locale");
|
|
5
|
+
const userLocaleCookie = useCookie(i18nConfig.localeCookie || "user-locale");
|
|
6
6
|
const headers = useRequestHeaders(["accept-language"]);
|
|
7
7
|
const supportedLocales = i18nConfig.locales?.map((locale) => locale.code) ?? [];
|
|
8
8
|
const defaultLocale = i18nConfig.defaultLocale || "en";
|
|
@@ -29,6 +29,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
29
29
|
const currentPath = router.currentRoute;
|
|
30
30
|
const currentLocale = currentPath.value.params.locale ?? defaultLocale;
|
|
31
31
|
if (detectedLocale === currentLocale) {
|
|
32
|
+
userLocaleCookie.value = detectedLocale;
|
|
32
33
|
return;
|
|
33
34
|
}
|
|
34
35
|
const resolvedRoute = router.resolve(currentPath.value);
|
|
@@ -2,22 +2,47 @@ import { resolve } from "node:path";
|
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
3
|
import { defineEventHandler } from "h3";
|
|
4
4
|
import { useRuntimeConfig } from "#imports";
|
|
5
|
+
function deepMerge(target, source) {
|
|
6
|
+
for (const key of Object.keys(source)) {
|
|
7
|
+
if (source[key] instanceof Object && key in target) {
|
|
8
|
+
Object.assign(source[key], deepMerge(target[key], source[key]));
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return { ...target, ...source };
|
|
12
|
+
}
|
|
13
|
+
function isEmptyObject(obj) {
|
|
14
|
+
for (const _ in obj) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
5
19
|
export default defineEventHandler(async (event) => {
|
|
6
20
|
const { page, locale } = event.context.params;
|
|
7
21
|
const config = useRuntimeConfig();
|
|
8
22
|
const { rootDirs } = config.i18nConfig;
|
|
9
|
-
const { translationDir } = config.public.i18nConfig;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
23
|
+
const { translationDir, fallbackLocale } = config.public.i18nConfig;
|
|
24
|
+
const getTranslationPath = (locale2, page2) => {
|
|
25
|
+
return page2 === "general" ? `${locale2}.json` : `pages/${page2}/${locale2}.json`;
|
|
26
|
+
};
|
|
27
|
+
const paths = [];
|
|
28
|
+
if (fallbackLocale && fallbackLocale !== locale) {
|
|
29
|
+
rootDirs.forEach((dir) => {
|
|
30
|
+
paths.push(resolve(dir, translationDir, getTranslationPath(fallbackLocale, page)));
|
|
31
|
+
});
|
|
13
32
|
}
|
|
33
|
+
rootDirs.forEach((dir) => {
|
|
34
|
+
paths.push(resolve(dir, translationDir, getTranslationPath(locale, page)));
|
|
35
|
+
});
|
|
14
36
|
let translations = {};
|
|
15
|
-
for (const
|
|
16
|
-
const translationPath = resolve(rootDirs[i], translationDir, path);
|
|
37
|
+
for (const translationPath of paths) {
|
|
17
38
|
try {
|
|
18
39
|
const fileContent = await readFile(translationPath, "utf-8");
|
|
19
40
|
const content = JSON.parse(fileContent);
|
|
20
|
-
translations
|
|
41
|
+
if (isEmptyObject(translations)) {
|
|
42
|
+
translations = content;
|
|
43
|
+
} else {
|
|
44
|
+
translations = deepMerge(translations, content);
|
|
45
|
+
}
|
|
21
46
|
} catch {
|
|
22
47
|
}
|
|
23
48
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-i18n-micro",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.15.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",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
63
|
"@nuxt/devtools-kit": "^1.4.1",
|
|
64
|
-
"@nuxt/kit": "^3.13.
|
|
64
|
+
"@nuxt/kit": "^3.13.1",
|
|
65
65
|
"chokidar": "^3.6.0",
|
|
66
66
|
"ps-node": "^0.1.6",
|
|
67
67
|
"sirv": "^2.0.4",
|
|
@@ -70,9 +70,9 @@
|
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@nuxt/devtools": "^1.4.1",
|
|
72
72
|
"@nuxt/devtools-ui-kit": "^1.4.1",
|
|
73
|
-
"@nuxt/eslint-config": "
|
|
73
|
+
"@nuxt/eslint-config": "0.5.5",
|
|
74
74
|
"@nuxt/module-builder": "^0.8.3",
|
|
75
|
-
"@nuxt/schema": "^3.13.
|
|
75
|
+
"@nuxt/schema": "^3.13.1",
|
|
76
76
|
"@nuxt/test-utils": "^3.14.1",
|
|
77
77
|
"@playwright/test": "^1.46.1",
|
|
78
78
|
"@types/node": "^20.14.11",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"changelogen": "^0.5.5",
|
|
83
83
|
"eslint": "^8.56.0",
|
|
84
84
|
"execa": "^9.3.1",
|
|
85
|
-
"nuxt": "^3.13.
|
|
85
|
+
"nuxt": "^3.13.1",
|
|
86
86
|
"pidusage": "^3.0.2",
|
|
87
87
|
"typescript": "latest",
|
|
88
88
|
"vitepress": "^1.3.4",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{_ as a,o as s,c as i,a as e,t as o,b as u,w as c,d,e as l,p,f as h}from"./D1fvHJQV.js";import{u as f}from"./DxMn4SAe.js";const g=t=>(p("data-v-83de2354"),t=t(),h(),t),b={class:"font-sans antialiased bg-white dark:bg-black text-black dark:text-white grid min-h-screen place-content-center overflow-hidden"},x=g(()=>e("div",{class:"fixed left-0 right-0 spotlight z-10"},null,-1)),m={class:"max-w-520px text-center z-20"},y=["textContent"],_=["textContent"],k={class:"w-full flex items-center justify-center"},w={__name:"error-404",props:{appName:{type:String,default:"Nuxt"},version:{type:String,default:""},statusCode:{type:Number,default:404},statusMessage:{type:String,default:"Not Found"},description:{type:String,default:"Sorry, the page you are looking for could not be found."},backHome:{type:String,default:"Go back home"}},setup(t){const n=t;return f({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}a{color:inherit;text-decoration: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: }'}]}),(z,S)=>{const r=l;return s(),i("div",b,[x,e("div",m,[e("h1",{class:"text-8xl sm:text-10xl font-medium mb-8",textContent:o(t.statusCode)},null,8,y),e("p",{class:"text-xl px-8 sm:px-0 sm:text-4xl font-light mb-16 leading-tight",textContent:o(t.description)},null,8,_),e("div",k,[u(r,{to:"/",class:"gradient-border text-md sm:text-xl py-2 px-4 sm:py-3 sm:px-6 cursor-pointer"},{default:c(()=>[d(o(t.backHome),1)]),_:1})])])])}}},N=a(w,[["__scopeId","data-v-83de2354"]]);export{N as default};
|