nuxt-i18n-micro 1.16.1 → 1.17.0-1726909148.4207cd6
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/{DaLmbeLo.js → C-3exr1n.js} +1 -1
- package/dist/client/_nuxt/{Bii0Cy7X.js → C1JBbjFJ.js} +1 -1
- package/dist/client/_nuxt/{Dvj3Ou8K.js → CtWyte3o.js} +1 -1
- package/dist/client/_nuxt/DLyXNYo2.js +119 -0
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/8c5651b7-8282-4881-9c94-76b6a4976d1f.json +1 -0
- package/dist/client/index.html +6 -6
- package/dist/module.d.mts +1 -0
- package/dist/module.d.ts +1 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +2 -1
- package/dist/runtime/plugins/01.plugin.js +34 -26
- package/dist/runtime/plugins/04.auto-detect.js +10 -0
- package/package.json +2 -1
- package/dist/client/_nuxt/C9hrmmtp.js +0 -119
- package/dist/client/_nuxt/builds/meta/b6e0dab7-be9e-4ee6-8148-cf61da244e79.json +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"id":"
|
|
1
|
+
{"id":"8c5651b7-8282-4881-9c94-76b6a4976d1f","timestamp":1726909154862}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"id":"8c5651b7-8282-4881-9c94-76b6a4976d1f","timestamp":1726909154862,"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/DLyXNYo2.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/C1JBbjFJ.js">
|
|
8
|
+
<link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/C-3exr1n.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/CtWyte3o.js">
|
|
11
|
+
<script type="module" src="/__nuxt-i18n-micro/_nuxt/DLyXNYo2.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:"8c5651b7-8282-4881-9c94-76b6a4976d1f",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
package/dist/module.d.mts
CHANGED
package/dist/module.d.ts
CHANGED
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -390,7 +390,8 @@ const module = defineNuxtModule({
|
|
|
390
390
|
routesLocaleLinks: options.routesLocaleLinks ?? {},
|
|
391
391
|
fallbackLocale: options.fallbackLocale ?? void 0,
|
|
392
392
|
dateBuild: Date.now(),
|
|
393
|
-
baseURL: nuxt.options.app.baseURL
|
|
393
|
+
baseURL: nuxt.options.app.baseURL,
|
|
394
|
+
hashMode: nuxt.options?.router?.options?.hashMode ?? false
|
|
394
395
|
};
|
|
395
396
|
nuxt.options.runtimeConfig.i18nConfig = {
|
|
396
397
|
rootDir: nuxt.options.rootDir,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useTranslationHelper } from "../translationHelper.js";
|
|
2
|
-
import { defineNuxtPlugin,
|
|
3
|
-
import { useRoute, useRouter } from "#imports";
|
|
2
|
+
import { defineNuxtPlugin, useRuntimeConfig } from "#app";
|
|
3
|
+
import { useRoute, useRouter, useCookie } from "#imports";
|
|
4
4
|
const i18nHelper = useTranslationHelper();
|
|
5
5
|
const isDev = process.env.NODE_ENV !== "production";
|
|
6
6
|
function interpolate(template, params) {
|
|
@@ -10,7 +10,10 @@ function interpolate(template, params) {
|
|
|
10
10
|
}
|
|
11
11
|
return result;
|
|
12
12
|
}
|
|
13
|
-
function getCurrentLocale(route, i18nConfig) {
|
|
13
|
+
function getCurrentLocale(route, i18nConfig, hashLocale) {
|
|
14
|
+
if (i18nConfig.hashMode && hashLocale) {
|
|
15
|
+
return hashLocale;
|
|
16
|
+
}
|
|
14
17
|
return (route.params?.locale ?? i18nConfig.defaultLocale).toString();
|
|
15
18
|
}
|
|
16
19
|
function getRouteName(route, locale) {
|
|
@@ -23,15 +26,12 @@ function switchLocale(fromLocale, toLocale, route, router, i18nConfig) {
|
|
|
23
26
|
return Promise.reject(`Locale ${toLocale} is not available`);
|
|
24
27
|
}
|
|
25
28
|
const routeName = getRouteName(route, fromLocale);
|
|
26
|
-
const isHashMode = router.options?.hashMode;
|
|
27
29
|
if (router.hasRoute(`localized-${routeName}-${toLocale}`)) {
|
|
28
30
|
const newParams2 = { ...route.params };
|
|
29
31
|
newParams2.locale = toLocale;
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
{ redirectCode: 200, external: true }
|
|
34
|
-
);
|
|
32
|
+
if (i18nConfig.hashMode) {
|
|
33
|
+
const userLocaleCookie = useCookie("hash-locale");
|
|
34
|
+
userLocaleCookie.value = toLocale;
|
|
35
35
|
}
|
|
36
36
|
return router.push({
|
|
37
37
|
params: newParams2,
|
|
@@ -44,16 +44,14 @@ function switchLocale(fromLocale, toLocale, route, router, i18nConfig) {
|
|
|
44
44
|
if (toLocale !== i18nConfig.defaultLocale || i18nConfig.includeDefaultLocaleRoute) {
|
|
45
45
|
newParams.locale = toLocale;
|
|
46
46
|
}
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
{ redirectCode: 200, external: true }
|
|
51
|
-
);
|
|
47
|
+
if (i18nConfig.hashMode) {
|
|
48
|
+
const userLocaleCookie = useCookie("hash-locale");
|
|
49
|
+
userLocaleCookie.value = toLocale;
|
|
52
50
|
}
|
|
53
51
|
return router.push({ name: newRouteName, params: newParams });
|
|
54
52
|
}
|
|
55
|
-
function getLocalizedRoute(to, router, route, i18nConfig, locale) {
|
|
56
|
-
const currentLocale = locale || getCurrentLocale(route, i18nConfig);
|
|
53
|
+
function getLocalizedRoute(to, router, route, i18nConfig, locale, hashLocale) {
|
|
54
|
+
const currentLocale = locale || getCurrentLocale(route, i18nConfig, hashLocale);
|
|
57
55
|
const selectRoute = router.resolve(to);
|
|
58
56
|
const routeName = getRouteName(selectRoute, currentLocale);
|
|
59
57
|
const resolveParams = (to2) => {
|
|
@@ -106,7 +104,8 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
106
104
|
}
|
|
107
105
|
};
|
|
108
106
|
useRouter().beforeEach(async (to, from, next) => {
|
|
109
|
-
const
|
|
107
|
+
const hashLocale2 = i18nConfig.hashMode ? nuxtApp.runWithContext(() => (useCookie("hash-locale").value ?? i18nConfig.defaultLocale).toString()).toString() : null;
|
|
108
|
+
const locale = getCurrentLocale(to, i18nConfig, hashLocale2);
|
|
110
109
|
if (!i18nHelper.hasGeneralTranslation(locale)) {
|
|
111
110
|
const data = await $fetch(`/_locales/general/${locale}/data.json?v=${i18nConfig.dateBuild}`, { baseURL: i18nConfig.baseURL });
|
|
112
111
|
await i18nHelper.loadTranslations(locale, data ?? {});
|
|
@@ -123,7 +122,8 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
123
122
|
});
|
|
124
123
|
const getTranslation = (key, params, defaultValue) => {
|
|
125
124
|
if (!key) return "";
|
|
126
|
-
const
|
|
125
|
+
const hashLocale2 = i18nConfig.hashMode ? (useCookie("hash-locale").value ?? i18nConfig.defaultLocale).toString() : null;
|
|
126
|
+
const locale = getCurrentLocale(useRoute(), i18nConfig, hashLocale2);
|
|
127
127
|
const routeName = getRouteName(useRoute(), locale);
|
|
128
128
|
let value = i18nHelper.getTranslation(locale, routeName, key);
|
|
129
129
|
if (!value) {
|
|
@@ -134,26 +134,31 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
134
134
|
}
|
|
135
135
|
return typeof value === "string" && params ? interpolate(value, params) : value;
|
|
136
136
|
};
|
|
137
|
+
let hashLocale = null;
|
|
138
|
+
if (i18nConfig.hashMode) {
|
|
139
|
+
hashLocale = useCookie("hash-locale").value ?? i18nConfig.defaultLocale;
|
|
140
|
+
}
|
|
137
141
|
return {
|
|
138
142
|
provide: {
|
|
139
|
-
getLocale: () => getCurrentLocale(useRoute(), i18nConfig),
|
|
143
|
+
getLocale: () => getCurrentLocale(useRoute(), i18nConfig, hashLocale),
|
|
144
|
+
// getLocale: () => getCurrentLocale(useRoute(), i18nConfig, i18nConfig.hashMode ? (hashLocale.value ?? i18nConfig.defaultLocale!).toString() : null),
|
|
140
145
|
getLocales: () => i18nConfig.locales || [],
|
|
141
146
|
getRouteName: (route, locale) => {
|
|
142
|
-
const selectedLocale = locale ?? getCurrentLocale(useRoute(), i18nConfig);
|
|
147
|
+
const selectedLocale = locale ?? getCurrentLocale(useRoute(), i18nConfig, hashLocale);
|
|
143
148
|
const selectedRoute = route ?? useRoute();
|
|
144
149
|
return getRouteName(selectedRoute, selectedLocale);
|
|
145
150
|
},
|
|
146
151
|
t: getTranslation,
|
|
147
152
|
tc: (key, count, defaultValue) => {
|
|
148
|
-
const currentLocale = getCurrentLocale(useRoute(), i18nConfig);
|
|
153
|
+
const currentLocale = getCurrentLocale(useRoute(), i18nConfig, hashLocale);
|
|
149
154
|
return plural(key, count, currentLocale, getTranslation) ?? defaultValue ?? key;
|
|
150
155
|
},
|
|
151
156
|
tn: (value, options) => {
|
|
152
|
-
const locale = getCurrentLocale(useRoute(), i18nConfig);
|
|
157
|
+
const locale = getCurrentLocale(useRoute(), i18nConfig, hashLocale);
|
|
153
158
|
return formatNumber(value, locale, options);
|
|
154
159
|
},
|
|
155
160
|
td: (value, options) => {
|
|
156
|
-
const locale = getCurrentLocale(useRoute(), i18nConfig);
|
|
161
|
+
const locale = getCurrentLocale(useRoute(), i18nConfig, hashLocale);
|
|
157
162
|
return formatDate(value, locale, options);
|
|
158
163
|
},
|
|
159
164
|
has: (key) => {
|
|
@@ -161,20 +166,23 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
161
166
|
},
|
|
162
167
|
mergeTranslations: (newTranslations) => {
|
|
163
168
|
const route = useRoute();
|
|
164
|
-
const locale = getCurrentLocale(route, i18nConfig);
|
|
169
|
+
const locale = getCurrentLocale(route, i18nConfig, hashLocale);
|
|
165
170
|
const routeName = getRouteName(route, locale);
|
|
166
171
|
i18nHelper.mergeTranslation(locale, routeName, newTranslations);
|
|
167
172
|
},
|
|
168
173
|
switchLocale: (toLocale) => {
|
|
169
174
|
const router = useRouter();
|
|
170
175
|
const route = useRoute();
|
|
171
|
-
const fromLocale = getCurrentLocale(route, i18nConfig);
|
|
176
|
+
const fromLocale = getCurrentLocale(route, i18nConfig, hashLocale);
|
|
177
|
+
if (i18nConfig.hashMode) {
|
|
178
|
+
hashLocale = toLocale;
|
|
179
|
+
}
|
|
172
180
|
switchLocale(fromLocale, toLocale, route, router, i18nConfig);
|
|
173
181
|
},
|
|
174
182
|
localeRoute: (to, locale) => {
|
|
175
183
|
const router = useRouter();
|
|
176
184
|
const route = useRoute();
|
|
177
|
-
return getLocalizedRoute(to, router, route, i18nConfig, locale);
|
|
185
|
+
return getLocalizedRoute(to, router, route, i18nConfig, locale, hashLocale);
|
|
178
186
|
}
|
|
179
187
|
}
|
|
180
188
|
};
|
|
@@ -3,6 +3,7 @@ import { useRoute, useRouter } from "#imports";
|
|
|
3
3
|
export default defineNuxtPlugin(async (nuxtApp) => {
|
|
4
4
|
const i18nConfig = nuxtApp.$config.public.i18nConfig;
|
|
5
5
|
const userLocaleCookie = useCookie(i18nConfig.localeCookie || "user-locale");
|
|
6
|
+
const hashCookie = useCookie("hash-locale");
|
|
6
7
|
const headers = useRequestHeaders(["accept-language"]);
|
|
7
8
|
const supportedLocales = i18nConfig.locales?.map((locale) => locale.code) ?? [];
|
|
8
9
|
const defaultLocale = i18nConfig.defaultLocale || "en";
|
|
@@ -30,6 +31,9 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
30
31
|
const currentLocale = currentPath.value.params.locale ?? defaultLocale;
|
|
31
32
|
if (detectedLocale === currentLocale) {
|
|
32
33
|
userLocaleCookie.value = detectedLocale;
|
|
34
|
+
if (i18nConfig.hashMode) {
|
|
35
|
+
hashCookie.value = detectedLocale;
|
|
36
|
+
}
|
|
33
37
|
return;
|
|
34
38
|
}
|
|
35
39
|
const resolvedRoute = router.resolve(currentPath.value);
|
|
@@ -41,8 +45,14 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
41
45
|
newParams.locale = detectedLocale;
|
|
42
46
|
}
|
|
43
47
|
userLocaleCookie.value = detectedLocale;
|
|
48
|
+
if (i18nConfig.hashMode) {
|
|
49
|
+
hashCookie.value = detectedLocale;
|
|
50
|
+
}
|
|
44
51
|
await navigateTo(router.resolve({ name: newRouteName, params: newParams }).href, { redirectCode: 301, external: true });
|
|
45
52
|
} else {
|
|
46
53
|
userLocaleCookie.value = defaultLocale;
|
|
54
|
+
if (i18nConfig.hashMode) {
|
|
55
|
+
hashCookie.value = detectedLocale;
|
|
56
|
+
}
|
|
47
57
|
}
|
|
48
58
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-i18n-micro",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.0-1726909148.4207cd6",
|
|
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",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
|
|
46
46
|
"dev:generate": "nuxi generate playground",
|
|
47
47
|
"release": "npm run lint && npm run test && npm run prepack && changelogen --release && npm publish && git push --follow-tags",
|
|
48
|
+
"prerelease": "npm run lint && npm run test && npm run prepack && changelogen --canary --publish && npm publish --tag next && git push --follow-tags",
|
|
48
49
|
"lint": "eslint .",
|
|
49
50
|
"lint:fix": "eslint . --fix",
|
|
50
51
|
"test": "playwright test --grep-invert \"test/performance\\.test\\.ts\"",
|