nuxt-i18n-micro 1.20.4 → 1.21.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/91148555-077c-470f-876f-bd605cf5c7ae.json +1 -0
- package/dist/client/index.html +2 -2
- package/dist/module.d.mts +3 -2
- package/dist/module.d.ts +3 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +1 -1
- package/dist/runtime/composables/useI18n.js +5 -0
- package/dist/runtime/plugins/01.plugin.d.ts +17 -5
- package/dist/runtime/plugins/01.plugin.js +91 -26
- package/dist/runtime/plugins/03.define.js +6 -9
- package/package.json +1 -1
- package/dist/client/_nuxt/builds/meta/7e0eb619-2ce4-4c24-a4f8-76cedd547d1a.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/CnNUpwZL.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/BKcmVa-6.js">
|
|
11
|
-
<script type="module" src="/__nuxt-i18n-micro/_nuxt/CeFL7aT9.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/CeFL7aT9.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},1727601284872,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"91148555-077c-470f-876f-bd605cf5c7ae",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/CnNUpwZL.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/BKcmVa-6.js">
|
|
11
|
-
<script type="module" src="/__nuxt-i18n-micro/_nuxt/CeFL7aT9.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/CeFL7aT9.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},1727601284872,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"91148555-077c-470f-876f-bd605cf5c7ae",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"id":"
|
|
1
|
+
{"id":"91148555-077c-470f-876f-bd605cf5c7ae","timestamp":1727601274705}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"id":"91148555-077c-470f-876f-bd605cf5c7ae","timestamp":1727601274705,"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/CnNUpwZL.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/BKcmVa-6.js">
|
|
11
|
-
<script type="module" src="/__nuxt-i18n-micro/_nuxt/CeFL7aT9.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/CeFL7aT9.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},1727601284872,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"91148555-077c-470f-876f-bd605cf5c7ae",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
package/dist/module.d.mts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
2
|
import { HookResult } from '@nuxt/schema';
|
|
3
3
|
|
|
4
|
+
type LocaleCode = string;
|
|
4
5
|
interface Locale {
|
|
5
|
-
code:
|
|
6
|
+
code: LocaleCode;
|
|
6
7
|
disabled?: boolean;
|
|
7
8
|
iso?: string;
|
|
8
9
|
dir?: 'ltr' | 'rtl' | 'auto';
|
|
9
10
|
}
|
|
10
11
|
type Getter = (key: string, params?: Record<string, string | number | boolean>, defaultValue?: string) => unknown;
|
|
11
12
|
type PluralFunc = (key: string, count: number, locale: string, getter: Getter) => string | null;
|
|
12
|
-
type GlobalLocaleRoutes = Record<string, Record<
|
|
13
|
+
type GlobalLocaleRoutes = Record<string, Record<LocaleCode, string> | false | boolean> | null | undefined;
|
|
13
14
|
interface ModuleOptions {
|
|
14
15
|
locales?: Locale[];
|
|
15
16
|
meta?: boolean;
|
package/dist/module.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
2
|
import { HookResult } from '@nuxt/schema';
|
|
3
3
|
|
|
4
|
+
type LocaleCode = string;
|
|
4
5
|
interface Locale {
|
|
5
|
-
code:
|
|
6
|
+
code: LocaleCode;
|
|
6
7
|
disabled?: boolean;
|
|
7
8
|
iso?: string;
|
|
8
9
|
dir?: 'ltr' | 'rtl' | 'auto';
|
|
9
10
|
}
|
|
10
11
|
type Getter = (key: string, params?: Record<string, string | number | boolean>, defaultValue?: string) => unknown;
|
|
11
12
|
type PluralFunc = (key: string, count: number, locale: string, getter: Getter) => string | null;
|
|
12
|
-
type GlobalLocaleRoutes = Record<string, Record<
|
|
13
|
+
type GlobalLocaleRoutes = Record<string, Record<LocaleCode, string> | false | boolean> | null | undefined;
|
|
13
14
|
interface ModuleOptions {
|
|
14
15
|
locales?: Locale[];
|
|
15
16
|
meta?: boolean;
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -436,7 +436,7 @@ const module = defineNuxtModule({
|
|
|
436
436
|
dateBuild: Date.now(),
|
|
437
437
|
baseURL: nuxt.options.app.baseURL,
|
|
438
438
|
hashMode: nuxt.options?.router?.options?.hashMode ?? false,
|
|
439
|
-
globalLocaleRoutes:
|
|
439
|
+
globalLocaleRoutes: void 0
|
|
440
440
|
};
|
|
441
441
|
nuxt.options.runtimeConfig.i18nConfig = {
|
|
442
442
|
rootDir: nuxt.options.rootDir,
|
|
@@ -2,6 +2,7 @@ import { useNuxtApp } from "#imports";
|
|
|
2
2
|
export function useI18n() {
|
|
3
3
|
const nuxtApp = useNuxtApp();
|
|
4
4
|
return {
|
|
5
|
+
$defaultLocale: nuxtApp.$defaultLocale,
|
|
5
6
|
$getLocale: nuxtApp.$getLocale,
|
|
6
7
|
$getLocales: nuxtApp.$getLocales,
|
|
7
8
|
$getRouteName: nuxtApp.$getRouteName,
|
|
@@ -11,8 +12,12 @@ export function useI18n() {
|
|
|
11
12
|
$has: nuxtApp.$has,
|
|
12
13
|
$tc: nuxtApp.$tc,
|
|
13
14
|
$mergeTranslations: nuxtApp.$mergeTranslations,
|
|
15
|
+
$setI18nRouteParams: nuxtApp.$setI18nRouteParams,
|
|
16
|
+
$switchLocaleRoute: nuxtApp.$switchLocaleRoute,
|
|
17
|
+
$switchLocalePath: nuxtApp.$switchLocalePath,
|
|
14
18
|
$switchLocale: nuxtApp.$switchLocale,
|
|
15
19
|
$localeRoute: nuxtApp.$localeRoute,
|
|
20
|
+
$localePath: nuxtApp.$localePath,
|
|
16
21
|
$loadPageTranslations: nuxtApp.$loadPageTranslations
|
|
17
22
|
};
|
|
18
23
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { RouteLocationNormalizedLoaded, RouteLocationRaw, RouteLocationResolvedGeneric } from 'vue-router';
|
|
2
|
-
import type { Locale } from '../../types.js';
|
|
1
|
+
import type { RouteLocationNormalizedLoaded, RouteLocationRaw, RouteLocationResolved, RouteLocationResolvedGeneric } from 'vue-router';
|
|
2
|
+
import type { Locale, I18nRouteParams } from '../../types.js';
|
|
3
3
|
export interface Translations {
|
|
4
4
|
[key: string]: string | number | boolean | Translations | PluralTranslations | unknown[] | null;
|
|
5
5
|
}
|
|
@@ -20,8 +20,12 @@ declare const _default: import("#app").Plugin<{
|
|
|
20
20
|
td: (value: Date | number | string, options?: Intl.DateTimeFormatOptions) => string;
|
|
21
21
|
has: (key: string) => boolean;
|
|
22
22
|
mergeTranslations: (newTranslations: Translations) => void;
|
|
23
|
+
switchLocaleRoute: (toLocale: string) => string | import("vue-router").RouteLocationAsRelativeGeneric | import("vue-router").RouteLocationAsPathGeneric;
|
|
24
|
+
switchLocalePath: (toLocale: string) => string;
|
|
23
25
|
switchLocale: (toLocale: string) => void;
|
|
24
|
-
localeRoute: (to: RouteLocationRaw, locale?: string) =>
|
|
26
|
+
localeRoute: (to: RouteLocationRaw, locale?: string) => RouteLocationResolved;
|
|
27
|
+
localePath: (to: RouteLocationRaw, locale?: string) => string;
|
|
28
|
+
setI18nRouteParams: (value: I18nRouteParams) => I18nRouteParams;
|
|
25
29
|
}> & import("#app").ObjectPlugin<{
|
|
26
30
|
i18n: undefined;
|
|
27
31
|
__micro: boolean;
|
|
@@ -35,8 +39,12 @@ declare const _default: import("#app").Plugin<{
|
|
|
35
39
|
td: (value: Date | number | string, options?: Intl.DateTimeFormatOptions) => string;
|
|
36
40
|
has: (key: string) => boolean;
|
|
37
41
|
mergeTranslations: (newTranslations: Translations) => void;
|
|
42
|
+
switchLocaleRoute: (toLocale: string) => string | import("vue-router").RouteLocationAsRelativeGeneric | import("vue-router").RouteLocationAsPathGeneric;
|
|
43
|
+
switchLocalePath: (toLocale: string) => string;
|
|
38
44
|
switchLocale: (toLocale: string) => void;
|
|
39
|
-
localeRoute: (to: RouteLocationRaw, locale?: string) =>
|
|
45
|
+
localeRoute: (to: RouteLocationRaw, locale?: string) => RouteLocationResolved;
|
|
46
|
+
localePath: (to: RouteLocationRaw, locale?: string) => string;
|
|
47
|
+
setI18nRouteParams: (value: I18nRouteParams) => I18nRouteParams;
|
|
40
48
|
}>;
|
|
41
49
|
export default _default;
|
|
42
50
|
export interface PluginsInjections {
|
|
@@ -50,9 +58,13 @@ export interface PluginsInjections {
|
|
|
50
58
|
$td: (value: Date | number | string, options?: Intl.DateTimeFormatOptions) => string;
|
|
51
59
|
$has: (key: string) => boolean;
|
|
52
60
|
$mergeTranslations: (newTranslations: Translations) => void;
|
|
61
|
+
$switchLocaleRoute: (locale: string) => RouteLocationRaw;
|
|
62
|
+
$switchLocalePath: (locale: string) => string;
|
|
53
63
|
$switchLocale: (locale: string) => void;
|
|
54
|
-
$localeRoute: (to: RouteLocationRaw, locale?: string) =>
|
|
64
|
+
$localeRoute: (to: RouteLocationRaw, locale?: string) => RouteLocationResolved;
|
|
65
|
+
$localePath: (to: RouteLocationRaw, locale?: string) => string;
|
|
55
66
|
$loadPageTranslations: (locale: string, routeName: string) => Promise<void>;
|
|
67
|
+
$setI18nRouteParams: (value: I18nRouteParams) => I18nRouteParams;
|
|
56
68
|
}
|
|
57
69
|
declare module '#app' {
|
|
58
70
|
interface NuxtApp extends PluginsInjections {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useTranslationHelper } from "../translationHelper.js";
|
|
2
2
|
import { defineNuxtPlugin, useRuntimeConfig } from "#app";
|
|
3
|
-
import { useRoute, useRouter, useCookie } from "#imports";
|
|
3
|
+
import { useRoute, useRouter, useCookie, useState } from "#imports";
|
|
4
4
|
const i18nHelper = useTranslationHelper();
|
|
5
5
|
const isDev = process.env.NODE_ENV !== "production";
|
|
6
6
|
function interpolate(template, params) {
|
|
@@ -19,27 +19,22 @@ function getCurrentLocale(route, i18nConfig, hashLocale) {
|
|
|
19
19
|
function getRouteName(route, locale) {
|
|
20
20
|
return (route?.name ?? "").toString().replace("localized-", "").replace(new RegExp(`-${locale}$`), "");
|
|
21
21
|
}
|
|
22
|
-
function
|
|
23
|
-
const checkLocale = i18nConfig.locales?.find((l) => l.code === toLocale);
|
|
24
|
-
if (!checkLocale) {
|
|
25
|
-
console.warn(`Locale ${toLocale} is not available`);
|
|
26
|
-
return Promise.reject(`Locale ${toLocale} is not available`);
|
|
27
|
-
}
|
|
22
|
+
function switchLocaleRoute(fromLocale, toLocale, route, router, i18nConfig, i18nRouteParams) {
|
|
28
23
|
const routeName = getRouteName(route, fromLocale);
|
|
29
24
|
if (router.hasRoute(`localized-${routeName}-${toLocale}`)) {
|
|
30
|
-
const newParams2 = { ...route.params };
|
|
25
|
+
const newParams2 = { ...route.params, ...i18nRouteParams?.[toLocale] };
|
|
31
26
|
newParams2.locale = toLocale;
|
|
32
27
|
if (i18nConfig.hashMode) {
|
|
33
28
|
const userLocaleCookie = useCookie("hash-locale");
|
|
34
29
|
userLocaleCookie.value = toLocale;
|
|
35
30
|
}
|
|
36
|
-
return
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
31
|
+
return {
|
|
32
|
+
name: `localized-${routeName}-${toLocale}`,
|
|
33
|
+
params: newParams2
|
|
34
|
+
};
|
|
40
35
|
}
|
|
41
36
|
const newRouteName = toLocale !== i18nConfig.defaultLocale || i18nConfig.includeDefaultLocaleRoute ? `localized-${routeName}` : routeName;
|
|
42
|
-
const newParams = { ...route.params };
|
|
37
|
+
const newParams = { ...route.params, ...i18nRouteParams?.[toLocale] };
|
|
43
38
|
delete newParams.locale;
|
|
44
39
|
if (toLocale !== i18nConfig.defaultLocale || i18nConfig.includeDefaultLocaleRoute) {
|
|
45
40
|
newParams.locale = toLocale;
|
|
@@ -48,7 +43,23 @@ function switchLocale(fromLocale, toLocale, route, router, i18nConfig) {
|
|
|
48
43
|
const userLocaleCookie = useCookie("hash-locale");
|
|
49
44
|
userLocaleCookie.value = toLocale;
|
|
50
45
|
}
|
|
51
|
-
return
|
|
46
|
+
return { name: newRouteName, params: newParams };
|
|
47
|
+
}
|
|
48
|
+
function switchLocale(fromLocale, toLocale, route, router, i18nConfig, i18nRouteParams) {
|
|
49
|
+
const checkLocale = i18nConfig.locales?.find((l) => l.code === toLocale);
|
|
50
|
+
if (!checkLocale) {
|
|
51
|
+
console.warn(`Locale ${toLocale} is not available`);
|
|
52
|
+
return Promise.reject(`Locale ${toLocale} is not available`);
|
|
53
|
+
}
|
|
54
|
+
const switchedRoute = switchLocaleRoute(
|
|
55
|
+
fromLocale,
|
|
56
|
+
toLocale,
|
|
57
|
+
route,
|
|
58
|
+
router,
|
|
59
|
+
i18nConfig,
|
|
60
|
+
i18nRouteParams
|
|
61
|
+
);
|
|
62
|
+
return router.push(switchedRoute);
|
|
52
63
|
}
|
|
53
64
|
function getLocalizedRoute(to, router, route, i18nConfig, locale, hashLocale) {
|
|
54
65
|
const currentLocale = locale || getCurrentLocale(route, i18nConfig, hashLocale);
|
|
@@ -65,28 +76,37 @@ function getLocalizedRoute(to, router, route, i18nConfig, locale, hashLocale) {
|
|
|
65
76
|
return params;
|
|
66
77
|
};
|
|
67
78
|
if (router.hasRoute(`localized-${routeName}-${currentLocale}`)) {
|
|
68
|
-
const newParams2 = resolveParams(
|
|
79
|
+
const newParams2 = resolveParams(selectRoute);
|
|
69
80
|
newParams2.locale = currentLocale;
|
|
70
81
|
return router.resolve({
|
|
82
|
+
name: `localized-${routeName}-${currentLocale}`,
|
|
71
83
|
params: newParams2,
|
|
72
|
-
|
|
84
|
+
query: selectRoute.query,
|
|
85
|
+
hash: selectRoute.hash
|
|
73
86
|
});
|
|
74
87
|
}
|
|
75
|
-
if (i18nConfig.includeDefaultLocaleRoute) {
|
|
76
|
-
const globalLocaleRoutes = i18nConfig.globalLocaleRoutes ?? {};
|
|
77
|
-
if (globalLocaleRoutes[routeName] == false) {
|
|
78
|
-
const newParams2 = resolveParams(to);
|
|
79
|
-
delete newParams2.locale;
|
|
80
|
-
return router.resolve({ name: routeName, params: newParams2 });
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
88
|
const newRouteName = currentLocale !== i18nConfig.defaultLocale || i18nConfig.includeDefaultLocaleRoute ? `localized-${routeName}` : routeName;
|
|
89
|
+
if (!router.hasRoute(newRouteName)) {
|
|
90
|
+
const newParams2 = resolveParams(to);
|
|
91
|
+
delete newParams2.locale;
|
|
92
|
+
return router.resolve({
|
|
93
|
+
name: routeName,
|
|
94
|
+
params: newParams2,
|
|
95
|
+
query: selectRoute.query,
|
|
96
|
+
hash: selectRoute.hash
|
|
97
|
+
});
|
|
98
|
+
}
|
|
84
99
|
const newParams = resolveParams(to);
|
|
85
100
|
delete newParams.locale;
|
|
86
101
|
if (currentLocale !== i18nConfig.defaultLocale || i18nConfig.includeDefaultLocaleRoute) {
|
|
87
102
|
newParams.locale = currentLocale;
|
|
88
103
|
}
|
|
89
|
-
return router.resolve({
|
|
104
|
+
return router.resolve({
|
|
105
|
+
name: newRouteName,
|
|
106
|
+
params: newParams,
|
|
107
|
+
query: selectRoute.query,
|
|
108
|
+
hash: selectRoute.hash
|
|
109
|
+
});
|
|
90
110
|
}
|
|
91
111
|
function formatNumber(value, locale, options) {
|
|
92
112
|
return new Intl.NumberFormat(locale, options).format(value);
|
|
@@ -149,6 +169,10 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
149
169
|
if (i18nConfig.hashMode) {
|
|
150
170
|
hashLocale = useCookie("hash-locale").value ?? i18nConfig.defaultLocale;
|
|
151
171
|
}
|
|
172
|
+
const i18nRouteParams = useState("i18n-route-params");
|
|
173
|
+
nuxtApp.hook("page:start", () => {
|
|
174
|
+
i18nRouteParams.value = null;
|
|
175
|
+
});
|
|
152
176
|
const provideData = {
|
|
153
177
|
i18n: void 0,
|
|
154
178
|
__micro: true,
|
|
@@ -182,6 +206,31 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
182
206
|
const routeName = getRouteName(route, locale);
|
|
183
207
|
i18nHelper.mergeTranslation(locale, routeName, newTranslations);
|
|
184
208
|
},
|
|
209
|
+
switchLocaleRoute: (toLocale) => {
|
|
210
|
+
const router = useRouter();
|
|
211
|
+
const route = useRoute();
|
|
212
|
+
const fromLocale = getCurrentLocale(route, i18nConfig, hashLocale);
|
|
213
|
+
if (i18nConfig.hashMode) {
|
|
214
|
+
hashLocale = toLocale;
|
|
215
|
+
}
|
|
216
|
+
return switchLocaleRoute(fromLocale, toLocale, route, router, i18nConfig, i18nRouteParams.value);
|
|
217
|
+
},
|
|
218
|
+
switchLocalePath: (toLocale) => {
|
|
219
|
+
const router = useRouter();
|
|
220
|
+
const route = useRoute();
|
|
221
|
+
const fromLocale = getCurrentLocale(route, i18nConfig, hashLocale);
|
|
222
|
+
if (i18nConfig.hashMode) {
|
|
223
|
+
hashLocale = toLocale;
|
|
224
|
+
}
|
|
225
|
+
const localeRoute = switchLocaleRoute(fromLocale, toLocale, route, router, i18nConfig, i18nRouteParams.value);
|
|
226
|
+
if (typeof localeRoute === "string") {
|
|
227
|
+
return localeRoute;
|
|
228
|
+
}
|
|
229
|
+
if ("fullPath" in localeRoute) {
|
|
230
|
+
return localeRoute.fullPath;
|
|
231
|
+
}
|
|
232
|
+
return "";
|
|
233
|
+
},
|
|
185
234
|
switchLocale: (toLocale) => {
|
|
186
235
|
const router = useRouter();
|
|
187
236
|
const route = useRoute();
|
|
@@ -189,12 +238,28 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
189
238
|
if (i18nConfig.hashMode) {
|
|
190
239
|
hashLocale = toLocale;
|
|
191
240
|
}
|
|
192
|
-
switchLocale(fromLocale, toLocale, route, router, i18nConfig);
|
|
241
|
+
switchLocale(fromLocale, toLocale, route, router, i18nConfig, i18nRouteParams.value);
|
|
193
242
|
},
|
|
194
243
|
localeRoute: (to, locale) => {
|
|
195
244
|
const router = useRouter();
|
|
196
245
|
const route = useRoute();
|
|
197
246
|
return getLocalizedRoute(to, router, route, i18nConfig, locale, hashLocale);
|
|
247
|
+
},
|
|
248
|
+
localePath: (to, locale) => {
|
|
249
|
+
const router = useRouter();
|
|
250
|
+
const route = useRoute();
|
|
251
|
+
const localeRoute = getLocalizedRoute(to, router, route, i18nConfig, locale, hashLocale);
|
|
252
|
+
if (typeof localeRoute === "string") {
|
|
253
|
+
return localeRoute;
|
|
254
|
+
}
|
|
255
|
+
if ("fullPath" in localeRoute) {
|
|
256
|
+
return localeRoute.fullPath;
|
|
257
|
+
}
|
|
258
|
+
return "";
|
|
259
|
+
},
|
|
260
|
+
setI18nRouteParams: (value) => {
|
|
261
|
+
i18nRouteParams.value = value;
|
|
262
|
+
return i18nRouteParams.value;
|
|
198
263
|
}
|
|
199
264
|
};
|
|
200
265
|
provideData.i18n = provideData;
|
|
@@ -5,7 +5,6 @@ export default defineNuxtPlugin(async (_nuxtApp) => {
|
|
|
5
5
|
const route = useRoute();
|
|
6
6
|
const router = useRouter();
|
|
7
7
|
const i18nConfig = config.public.i18nConfig;
|
|
8
|
-
const globalLocaleRoutes = i18nConfig.globalLocaleRoutes ?? {};
|
|
9
8
|
const normalizeLocales = (locales) => {
|
|
10
9
|
if (Array.isArray(locales)) {
|
|
11
10
|
return locales.reduce((acc, locale) => {
|
|
@@ -22,15 +21,14 @@ export default defineNuxtPlugin(async (_nuxtApp) => {
|
|
|
22
21
|
const { name } = to;
|
|
23
22
|
let defaultRouteName = name?.toString().replace("localized-", "").replace(new RegExp(`-${currentLocale}$`), "");
|
|
24
23
|
if (!to.params.locale) {
|
|
25
|
-
const name2 = to.name?.toString() ?? "";
|
|
26
|
-
if (globalLocaleRoutes[name2] === false) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
24
|
if (router.hasRoute(`localized-${to.name?.toString()}-${currentLocale}`)) {
|
|
30
25
|
defaultRouteName = `localized-${to.name?.toString()}-${currentLocale}`;
|
|
31
26
|
} else {
|
|
32
27
|
defaultRouteName = `localized-${to.name?.toString()}`;
|
|
33
28
|
}
|
|
29
|
+
if (!router.hasRoute(defaultRouteName)) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
34
32
|
const newParams = { ...to.params };
|
|
35
33
|
newParams.locale = i18nConfig.defaultLocale;
|
|
36
34
|
return navigateTo({ name: defaultRouteName, params: newParams }, { redirectCode: 301, external: true });
|
|
@@ -62,15 +60,14 @@ export default defineNuxtPlugin(async (_nuxtApp) => {
|
|
|
62
60
|
const newParams = { ...route.params };
|
|
63
61
|
delete newParams.locale;
|
|
64
62
|
if (i18nConfig.includeDefaultLocaleRoute) {
|
|
65
|
-
const name = route.name?.toString() ?? "";
|
|
66
|
-
if (globalLocaleRoutes[name] === false) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
63
|
if (router.hasRoute(`localized-${defaultRouteName}-${currentLocale}`)) {
|
|
70
64
|
defaultRouteName = `localized-${defaultRouteName}-${currentLocale}`;
|
|
71
65
|
} else {
|
|
72
66
|
defaultRouteName = `localized-${defaultRouteName}`;
|
|
73
67
|
}
|
|
68
|
+
if (!router.hasRoute(defaultRouteName)) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
74
71
|
newParams.locale = i18nConfig.defaultLocale;
|
|
75
72
|
newParams.name = defaultRouteName;
|
|
76
73
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-i18n-micro",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.21.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",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"id":"7e0eb619-2ce4-4c24-a4f8-76cedd547d1a","timestamp":1727445410428,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|