nuxt-i18n-micro 1.13.3 → 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.d.mts +1 -1
- package/dist/module.d.ts +1 -1
- package/dist/module.json +1 -1
- package/dist/runtime/components/i18n-switcher.vue +3 -0
- package/dist/runtime/plugins/01.plugin.d.ts +2 -2
- package/dist/runtime/plugins/01.plugin.js +29 -40
- package/dist/runtime/plugins/03.define.d.ts +2 -2
- package/dist/runtime/plugins/03.define.js +22 -4
- package/dist/runtime/translationHelper.d.ts +2 -2
- package/dist/runtime/translationHelper.js +4 -4
- package/package.json +1 -1
- package/dist/client/_nuxt/builds/meta/5ea89697-ba72-411f-a61a-8d8be203f3a9.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.d.mts
CHANGED
|
@@ -35,7 +35,7 @@ interface ModulePrivateOptionsExtend extends ModuleOptions {
|
|
|
35
35
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
36
36
|
|
|
37
37
|
interface ModuleHooks {
|
|
38
|
-
'i18n:register': (registerModule: (translations: unknown, locale
|
|
38
|
+
'i18n:register': (registerModule: (translations: unknown, locale?: string) => void, locale: string) => HookResult;
|
|
39
39
|
}
|
|
40
40
|
declare module '@nuxt/schema' {
|
|
41
41
|
interface ConfigSchema {
|
package/dist/module.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ interface ModulePrivateOptionsExtend extends ModuleOptions {
|
|
|
35
35
|
declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
|
|
36
36
|
|
|
37
37
|
interface ModuleHooks {
|
|
38
|
-
'i18n:register': (registerModule: (translations: unknown, locale
|
|
38
|
+
'i18n:register': (registerModule: (translations: unknown, locale?: string) => void, locale: string) => HookResult;
|
|
39
39
|
}
|
|
40
40
|
declare module '@nuxt/schema' {
|
|
41
41
|
interface ConfigSchema {
|
package/dist/module.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div :style="[wrapperStyle, customWrapperStyle]">
|
|
3
3
|
<button
|
|
4
|
+
class="language-switcher"
|
|
4
5
|
:style="[buttonStyle, customButtonStyle]"
|
|
5
6
|
@click="toggleDropdown"
|
|
6
7
|
>
|
|
@@ -17,9 +18,11 @@
|
|
|
17
18
|
:style="[itemStyle, customItemStyle]"
|
|
18
19
|
>
|
|
19
20
|
<NuxtLink
|
|
21
|
+
:class="`switcher-locale-${locale.code}`"
|
|
20
22
|
:to="getLocaleLink(locale)"
|
|
21
23
|
:style="[linkStyle, locale.code === currentLocale ? activeLinkStyle : {}, locale.code === currentLocale ? disabledLinkStyle : {}, customLinkStyle]"
|
|
22
24
|
:hreflang="locale.iso || locale.code"
|
|
25
|
+
@click="toggleDropdown"
|
|
23
26
|
>
|
|
24
27
|
{{ localeLabel(locale) }}
|
|
25
28
|
</NuxtLink>
|
|
@@ -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
|
}
|
|
@@ -72,22 +72,12 @@ function formatDate(value, locale, options) {
|
|
|
72
72
|
return new Intl.DateTimeFormat(locale, options).format(new Date(value));
|
|
73
73
|
}
|
|
74
74
|
export default defineNuxtPlugin(async (nuxtApp) => {
|
|
75
|
-
const registerI18nModule = (translations, locale) => {
|
|
76
|
-
i18nHelper.mergeGlobalTranslation(locale, translations);
|
|
77
|
-
};
|
|
78
|
-
await nuxtApp.callHook("i18n:register", registerI18nModule);
|
|
79
75
|
if (!nuxtApp.payload.data.translations) {
|
|
80
76
|
nuxtApp.payload.data.translations = {};
|
|
81
77
|
}
|
|
82
|
-
const route = useRoute();
|
|
83
78
|
const config = useRuntimeConfig();
|
|
84
79
|
const i18nConfig = config.public.i18nConfig;
|
|
85
80
|
const plural = new Function("return " + i18nConfig.plural)();
|
|
86
|
-
const initialLocale = getCurrentLocale(route, i18nConfig);
|
|
87
|
-
if (import.meta.server && !i18nHelper.hasGeneralTranslation(initialLocale)) {
|
|
88
|
-
const data = await $fetch(`/_locales/general/${initialLocale}/data.json?v=${i18nConfig.dateBuild}`, { baseURL: i18nConfig.baseURL });
|
|
89
|
-
await i18nHelper.loadTranslations(initialLocale, data ?? {});
|
|
90
|
-
}
|
|
91
81
|
const loadTranslationsIfNeeded = async (locale, routeName) => {
|
|
92
82
|
if (!i18nHelper.hasPageTranslation(locale, routeName)) {
|
|
93
83
|
let fRouteName = routeName;
|
|
@@ -98,22 +88,20 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
98
88
|
await i18nHelper.loadPageTranslations(locale, routeName, data ?? {});
|
|
99
89
|
}
|
|
100
90
|
};
|
|
101
|
-
if (import.meta.server && !i18nConfig.disablePageLocales) {
|
|
102
|
-
const locale = getCurrentLocale(route, i18nConfig);
|
|
103
|
-
const initialRouteName = getRouteName(route, locale);
|
|
104
|
-
await loadTranslationsIfNeeded(locale, initialRouteName);
|
|
105
|
-
}
|
|
106
91
|
useRouter().beforeEach(async (to, from, next) => {
|
|
107
|
-
|
|
108
|
-
|
|
92
|
+
const locale = getCurrentLocale(to, i18nConfig);
|
|
93
|
+
if (!i18nHelper.hasGeneralTranslation(locale)) {
|
|
109
94
|
const data = await $fetch(`/_locales/general/${locale}/data.json?v=${i18nConfig.dateBuild}`, { baseURL: i18nConfig.baseURL });
|
|
110
95
|
await i18nHelper.loadTranslations(locale, data ?? {});
|
|
111
96
|
}
|
|
112
|
-
if (
|
|
113
|
-
const locale = getCurrentLocale(to, i18nConfig);
|
|
97
|
+
if (!i18nConfig.disablePageLocales) {
|
|
114
98
|
const routeName = getRouteName(to, locale);
|
|
115
99
|
await loadTranslationsIfNeeded(locale, routeName);
|
|
116
100
|
}
|
|
101
|
+
await nuxtApp.callHook("i18n:register", (translations, selectedLocale) => {
|
|
102
|
+
const routeName = getRouteName(to, locale);
|
|
103
|
+
i18nHelper.mergeTranslation(selectedLocale ?? locale, routeName, translations, true);
|
|
104
|
+
}, locale);
|
|
117
105
|
next();
|
|
118
106
|
});
|
|
119
107
|
const getTranslation = (key, params, defaultValue) => {
|
|
@@ -133,9 +121,9 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
133
121
|
provide: {
|
|
134
122
|
getLocale: () => getCurrentLocale(useRoute(), i18nConfig),
|
|
135
123
|
getLocales: () => i18nConfig.locales || [],
|
|
136
|
-
getRouteName: (
|
|
124
|
+
getRouteName: (route, locale) => {
|
|
137
125
|
const selectedLocale = locale ?? getCurrentLocale(useRoute(), i18nConfig);
|
|
138
|
-
const selectedRoute =
|
|
126
|
+
const selectedRoute = route ?? useRoute();
|
|
139
127
|
return getRouteName(selectedRoute, selectedLocale);
|
|
140
128
|
},
|
|
141
129
|
t: getTranslation,
|
|
@@ -155,20 +143,21 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
155
143
|
return !!getTranslation(key);
|
|
156
144
|
},
|
|
157
145
|
mergeTranslations: (newTranslations) => {
|
|
158
|
-
const
|
|
159
|
-
const locale = getCurrentLocale(
|
|
160
|
-
const routeName = getRouteName(
|
|
146
|
+
const route = useRoute();
|
|
147
|
+
const locale = getCurrentLocale(route, i18nConfig);
|
|
148
|
+
const routeName = getRouteName(route, locale);
|
|
161
149
|
i18nHelper.mergeTranslation(locale, routeName, newTranslations);
|
|
162
150
|
},
|
|
163
|
-
switchLocale: (
|
|
151
|
+
switchLocale: (toLocale) => {
|
|
164
152
|
const router = useRouter();
|
|
165
|
-
const
|
|
166
|
-
|
|
153
|
+
const route = useRoute();
|
|
154
|
+
const fromLocale = getCurrentLocale(route, i18nConfig);
|
|
155
|
+
switchLocale(fromLocale, toLocale, route, router, i18nConfig);
|
|
167
156
|
},
|
|
168
157
|
localeRoute: (to, locale) => {
|
|
169
158
|
const router = useRouter();
|
|
170
|
-
const
|
|
171
|
-
return getLocalizedRoute(to, router,
|
|
159
|
+
const route = useRoute();
|
|
160
|
+
return getLocalizedRoute(to, router, route, i18nConfig, locale);
|
|
172
161
|
}
|
|
173
162
|
}
|
|
174
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 {
|
|
@@ -3,8 +3,8 @@ export declare function useTranslationHelper(): {
|
|
|
3
3
|
hasCache(locale: string, page: string): boolean;
|
|
4
4
|
getCache(locale: string, routeName: string): Map<string, unknown>;
|
|
5
5
|
setCache(locale: string, routeName: string, cache: Map<string, Translations | unknown>): void;
|
|
6
|
-
mergeTranslation(locale: string, routeName: string, newTranslations: Translations): void;
|
|
7
|
-
mergeGlobalTranslation(locale: string, newTranslations: Translations): void;
|
|
6
|
+
mergeTranslation(locale: string, routeName: string, newTranslations: Translations, force?: boolean): void;
|
|
7
|
+
mergeGlobalTranslation(locale: string, newTranslations: Translations, force?: boolean): void;
|
|
8
8
|
hasGeneralTranslation(locale: string): boolean;
|
|
9
9
|
hasPageTranslation(locale: string, routeName: string): boolean;
|
|
10
10
|
getTranslation: <T = unknown>(locale: string, routeName: string, key: string) => T | null;
|
|
@@ -39,8 +39,8 @@ export function useTranslationHelper() {
|
|
|
39
39
|
serverTranslationInit[`${locale}:index`] = true;
|
|
40
40
|
serverTranslationInit[cacheKey] = true;
|
|
41
41
|
},
|
|
42
|
-
mergeTranslation(locale, routeName, newTranslations) {
|
|
43
|
-
if (!routeLocaleCache[`${locale}:${routeName}`]) {
|
|
42
|
+
mergeTranslation(locale, routeName, newTranslations, force = false) {
|
|
43
|
+
if (!force && !routeLocaleCache[`${locale}:${routeName}`]) {
|
|
44
44
|
console.error(`marge: route ${locale}:${routeName} not loaded`);
|
|
45
45
|
}
|
|
46
46
|
routeLocaleCache[`${locale}:${routeName}`] = {
|
|
@@ -48,8 +48,8 @@ export function useTranslationHelper() {
|
|
|
48
48
|
...newTranslations
|
|
49
49
|
};
|
|
50
50
|
},
|
|
51
|
-
mergeGlobalTranslation(locale, newTranslations) {
|
|
52
|
-
if (!generalLocaleCache[`${locale}`]) {
|
|
51
|
+
mergeGlobalTranslation(locale, newTranslations, force = false) {
|
|
52
|
+
if (!force && !generalLocaleCache[`${locale}`]) {
|
|
53
53
|
console.error(`marge: route ${locale} not loaded`);
|
|
54
54
|
}
|
|
55
55
|
generalLocaleCache[locale] = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-i18n-micro",
|
|
3
|
-
"version": "1.
|
|
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":"5ea89697-ba72-411f-a61a-8d8be203f3a9","timestamp":1725472070372,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|