nuxt-i18n-micro 1.31.0 → 1.31.2
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/c76c859a-63e2-40c2-8269-b10f451a1598.json +1 -0
- package/dist/client/index.html +2 -2
- package/dist/module.json +1 -1
- package/dist/runtime/components/i18n-switcher.vue +5 -15
- package/dist/runtime/plugins/01.plugin.js +2 -0
- package/dist/runtime/plugins/04.auto-detect.js +29 -31
- package/package.json +1 -1
- package/dist/client/_nuxt/builds/meta/905aebfb-7659-4ec4-86aa-8f4e4ded54d9.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/0GmYR_kR.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/2C6ahHCU.js">
|
|
11
|
-
<script type="module" src="/__nuxt-i18n-micro/_nuxt/Czi4MokJ.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/Czi4MokJ.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},1730358568434,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"c76c859a-63e2-40c2-8269-b10f451a1598",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/0GmYR_kR.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/2C6ahHCU.js">
|
|
11
|
-
<script type="module" src="/__nuxt-i18n-micro/_nuxt/Czi4MokJ.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/Czi4MokJ.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},1730358568435,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"c76c859a-63e2-40c2-8269-b10f451a1598",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"id":"
|
|
1
|
+
{"id":"c76c859a-63e2-40c2-8269-b10f451a1598","timestamp":1730358555401}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"id":"c76c859a-63e2-40c2-8269-b10f451a1598","timestamp":1730358555401,"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/0GmYR_kR.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/2C6ahHCU.js">
|
|
11
|
-
<script type="module" src="/__nuxt-i18n-micro/_nuxt/Czi4MokJ.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/Czi4MokJ.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},1730358568435,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"c76c859a-63e2-40c2-8269-b10f451a1598",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
package/dist/module.json
CHANGED
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
>
|
|
20
20
|
<NuxtLink
|
|
21
21
|
:class="`switcher-locale-${locale.code}`"
|
|
22
|
-
:to="getLocaleLink(locale)"
|
|
23
22
|
:style="[
|
|
24
23
|
linkStyle,
|
|
25
24
|
locale.code === currentLocale ? activeLinkStyle : {},
|
|
@@ -27,7 +26,7 @@
|
|
|
27
26
|
customLinkStyle,
|
|
28
27
|
]"
|
|
29
28
|
:hreflang="locale.iso || locale.code"
|
|
30
|
-
@click="
|
|
29
|
+
@click="switchLocale(locale)"
|
|
31
30
|
>
|
|
32
31
|
{{ localeLabel(locale) }}
|
|
33
32
|
</NuxtLink>
|
|
@@ -40,7 +39,6 @@
|
|
|
40
39
|
import { ref, computed } from 'vue'
|
|
41
40
|
import type { CSSProperties } from 'vue'
|
|
42
41
|
import { useNuxtApp } from '#app'
|
|
43
|
-
import { useRoute } from '#imports'
|
|
44
42
|
|
|
45
43
|
type LocaleCode = string
|
|
46
44
|
interface Locale {
|
|
@@ -75,7 +73,7 @@ const props = withDefaults(defineProps<Props>(), {
|
|
|
75
73
|
customIconStyle: () => ({}),
|
|
76
74
|
})
|
|
77
75
|
|
|
78
|
-
const { $
|
|
76
|
+
const { $switchLocale, $getLocales, $getLocale, $getLocaleName } = useNuxtApp()
|
|
79
77
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
80
78
|
// @ts-ignore
|
|
81
79
|
const locales = ref($getLocales())
|
|
@@ -106,17 +104,9 @@ const currentLocaleLabel = computed(() => localeLabel({
|
|
|
106
104
|
displayName: currentLocaleName.value ?? undefined,
|
|
107
105
|
}))
|
|
108
106
|
|
|
109
|
-
const
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
.toString()
|
|
113
|
-
.replace(`localized-`, '')
|
|
114
|
-
.replace(new RegExp(`-${currentLocale.value}$`), '')
|
|
115
|
-
.replace(new RegExp(`-${locale}$`), '')
|
|
116
|
-
|
|
117
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
118
|
-
// @ts-ignore
|
|
119
|
-
return $localeRoute({ name: routeName }, locale.code)
|
|
107
|
+
const switchLocale = (locale: Locale) => {
|
|
108
|
+
toggleDropdown()
|
|
109
|
+
return $switchLocale(locale.code)
|
|
120
110
|
}
|
|
121
111
|
|
|
122
112
|
// Default Styles
|
|
@@ -92,11 +92,13 @@ function getLocalizedRoute(to, router, route, i18nConfig, locale, hashLocale) {
|
|
|
92
92
|
if (router.hasRoute(`localized-${defaultRouteName}`)) {
|
|
93
93
|
to = router.resolve({
|
|
94
94
|
name: `localized-${defaultRouteName}`,
|
|
95
|
+
query: resolvedTo.query,
|
|
95
96
|
params: newParams2
|
|
96
97
|
});
|
|
97
98
|
} else if (router.hasRoute(`localized-${defaultRouteName}-${defaultLocale}`)) {
|
|
98
99
|
to = router.resolve({
|
|
99
100
|
name: `localized-${defaultRouteName}-${defaultLocale}`,
|
|
101
|
+
query: resolvedTo.query,
|
|
100
102
|
params: newParams2
|
|
101
103
|
});
|
|
102
104
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { defineNuxtPlugin, useCookie, useRequestHeaders, navigateTo } from "#app";
|
|
2
2
|
import { useRoute, useRouter } from "#imports";
|
|
3
|
+
const parseAcceptLanguage = (acceptLanguage) => acceptLanguage.split(",").map((entry) => entry.split(";")[0].trim());
|
|
3
4
|
export default defineNuxtPlugin(async (nuxtApp) => {
|
|
4
5
|
const i18nConfig = nuxtApp.$config.public.i18nConfig;
|
|
5
6
|
const userLocaleCookie = useCookie(i18nConfig.localeCookie || "user-locale");
|
|
@@ -8,16 +9,35 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
8
9
|
const supportedLocales = i18nConfig.locales?.map((locale) => locale.code) ?? [];
|
|
9
10
|
const defaultLocale = i18nConfig.defaultLocale || "en";
|
|
10
11
|
const autoDetectPath = i18nConfig.autoDetectPath || "*";
|
|
12
|
+
const router = useRouter();
|
|
13
|
+
const route = useRoute();
|
|
14
|
+
async function switchLocale(newLocale) {
|
|
15
|
+
const currentPath = router.currentRoute;
|
|
16
|
+
const resolvedRoute = router.resolve(currentPath.value);
|
|
17
|
+
const routeName = resolvedRoute.name.replace(`localized-`, "");
|
|
18
|
+
const newRouteName = i18nConfig.includeDefaultLocaleRoute || newLocale !== defaultLocale ? `localized-${routeName}` : routeName;
|
|
19
|
+
const newParams = { ...route.params };
|
|
20
|
+
delete newParams.locale;
|
|
21
|
+
if (i18nConfig.includeDefaultLocaleRoute || newLocale !== defaultLocale) {
|
|
22
|
+
newParams.locale = newLocale;
|
|
23
|
+
}
|
|
24
|
+
const newRoute = router.resolve({
|
|
25
|
+
name: newRouteName,
|
|
26
|
+
params: newParams
|
|
27
|
+
});
|
|
28
|
+
await navigateTo(newRoute.href, {
|
|
29
|
+
redirectCode: 302,
|
|
30
|
+
external: true
|
|
31
|
+
});
|
|
32
|
+
}
|
|
11
33
|
if (userLocaleCookie.value) {
|
|
12
34
|
return;
|
|
13
35
|
}
|
|
14
|
-
const router = useRouter();
|
|
15
|
-
const route = useRoute();
|
|
16
36
|
if (autoDetectPath !== "*" && route.path !== autoDetectPath) {
|
|
17
37
|
return;
|
|
18
38
|
}
|
|
19
39
|
const acceptLanguage = headers?.["accept-language"] ?? "";
|
|
20
|
-
const browserLanguages = acceptLanguage ? acceptLanguage
|
|
40
|
+
const browserLanguages = acceptLanguage ? parseAcceptLanguage(acceptLanguage) : [defaultLocale];
|
|
21
41
|
let detectedLocale = defaultLocale;
|
|
22
42
|
for (const language of browserLanguages) {
|
|
23
43
|
const primaryLanguage = language.split("-")[0];
|
|
@@ -26,33 +46,11 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
26
46
|
break;
|
|
27
47
|
}
|
|
28
48
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
hashCookie.value = detectedLocale;
|
|
36
|
-
}
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
const resolvedRoute = router.resolve(currentPath.value);
|
|
40
|
-
const routeName = resolvedRoute.name.replace(`localized-`, "");
|
|
41
|
-
const newRouteName = detectedLocale === defaultLocale ? routeName : `localized-${routeName}`;
|
|
42
|
-
const newParams = { ...route.params };
|
|
43
|
-
delete newParams.locale;
|
|
44
|
-
if (detectedLocale !== defaultLocale) {
|
|
45
|
-
newParams.locale = detectedLocale;
|
|
46
|
-
}
|
|
47
|
-
userLocaleCookie.value = detectedLocale;
|
|
48
|
-
if (i18nConfig.hashMode) {
|
|
49
|
-
hashCookie.value = detectedLocale;
|
|
50
|
-
}
|
|
51
|
-
await navigateTo(router.resolve({ name: newRouteName, params: newParams }).href, { redirectCode: 302, external: true });
|
|
52
|
-
} else {
|
|
53
|
-
userLocaleCookie.value = defaultLocale;
|
|
54
|
-
if (i18nConfig.hashMode) {
|
|
55
|
-
hashCookie.value = detectedLocale;
|
|
56
|
-
}
|
|
49
|
+
userLocaleCookie.value = detectedLocale;
|
|
50
|
+
if (i18nConfig.hashMode) {
|
|
51
|
+
hashCookie.value = detectedLocale;
|
|
52
|
+
}
|
|
53
|
+
if (detectedLocale !== route.params.locale) {
|
|
54
|
+
await switchLocale(detectedLocale);
|
|
57
55
|
}
|
|
58
56
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-i18n-micro",
|
|
3
|
-
"version": "1.31.
|
|
3
|
+
"version": "1.31.2",
|
|
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":"905aebfb-7659-4ec4-86aa-8f4e4ded54d9","timestamp":1729794403479,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|