nuxt-i18n-micro 1.14.0 → 1.14.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 +1 -1
- package/dist/client/404.html +1 -1
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/fac332f5-ba87-4ce6-a934-08ead1d48099.json +1 -0
- package/dist/client/index.html +1 -1
- package/dist/module.json +1 -1
- 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/package.json +1 -1
- package/dist/client/_nuxt/builds/meta/cef9112f-2f86-40b3-9815-286383780fe2.json +0 -1
package/dist/client/200.html
CHANGED
|
@@ -9,4 +9,4 @@
|
|
|
9
9
|
<link rel="prefetch" as="style" href="/__nuxt-i18n-micro/_nuxt/error-500.21ZDxC33.css">
|
|
10
10
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/DzdJBprQ.js">
|
|
11
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:"
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"fac332f5-ba87-4ce6-a934-08ead1d48099",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
package/dist/client/404.html
CHANGED
|
@@ -9,4 +9,4 @@
|
|
|
9
9
|
<link rel="prefetch" as="style" href="/__nuxt-i18n-micro/_nuxt/error-500.21ZDxC33.css">
|
|
10
10
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/DzdJBprQ.js">
|
|
11
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:"
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"fac332f5-ba87-4ce6-a934-08ead1d48099",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"id":"
|
|
1
|
+
{"id":"fac332f5-ba87-4ce6-a934-08ead1d48099","timestamp":1725567796588}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"id":"fac332f5-ba87-4ce6-a934-08ead1d48099","timestamp":1725567796588,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|
package/dist/client/index.html
CHANGED
|
@@ -9,4 +9,4 @@
|
|
|
9
9
|
<link rel="prefetch" as="style" href="/__nuxt-i18n-micro/_nuxt/error-500.21ZDxC33.css">
|
|
10
10
|
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/DzdJBprQ.js">
|
|
11
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:"
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"fac332f5-ba87-4ce6-a934-08ead1d48099",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
package/dist/module.json
CHANGED
|
@@ -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 {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-i18n-micro",
|
|
3
|
-
"version": "1.14.
|
|
3
|
+
"version": "1.14.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",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"id":"cef9112f-2f86-40b3-9815-286383780fe2","timestamp":1725543893300,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|