nuxt-i18n-micro 1.31.9 → 1.32.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 +2 -2
- package/dist/client/404.html +2 -2
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/f1354573-fd79-4f4c-9c07-5367d8c22fba.json +1 -0
- package/dist/client/index.html +2 -2
- package/dist/module.d.mts +2 -0
- package/dist/module.d.ts +2 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +6 -0
- package/dist/runtime/components/i18n-group.vue +20 -0
- package/dist/runtime/components/i18n-switcher.vue +38 -5
- package/dist/runtime/plugins/01.plugin.js +30 -3
- package/package.json +1 -1
- package/dist/client/_nuxt/builds/meta/c81d9b67-6e51-4931-a0b1-9b731a2a5d0c.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/C4eGGOXV.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/BARbCa2g.js">
|
|
11
|
-
<script type="module" src="/__nuxt-i18n-micro/_nuxt/CTiMIQCz.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/CTiMIQCz.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},1731159703712,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"f1354573-fd79-4f4c-9c07-5367d8c22fba",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/C4eGGOXV.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/BARbCa2g.js">
|
|
11
|
-
<script type="module" src="/__nuxt-i18n-micro/_nuxt/CTiMIQCz.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/CTiMIQCz.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},1731159703713,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"f1354573-fd79-4f4c-9c07-5367d8c22fba",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"id":"
|
|
1
|
+
{"id":"f1354573-fd79-4f4c-9c07-5367d8c22fba","timestamp":1731159691759}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"id":"f1354573-fd79-4f4c-9c07-5367d8c22fba","timestamp":1731159691759,"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/C4eGGOXV.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/BARbCa2g.js">
|
|
11
|
-
<script type="module" src="/__nuxt-i18n-micro/_nuxt/CTiMIQCz.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/CTiMIQCz.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},1731159703713,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"f1354573-fd79-4f4c-9c07-5367d8c22fba",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
package/dist/module.d.mts
CHANGED
|
@@ -9,6 +9,8 @@ interface Locale {
|
|
|
9
9
|
iso?: string;
|
|
10
10
|
dir?: 'ltr' | 'rtl' | 'auto';
|
|
11
11
|
displayName?: string;
|
|
12
|
+
baseUrl?: string;
|
|
13
|
+
baseDefault?: boolean;
|
|
12
14
|
}
|
|
13
15
|
type Getter = (key: string, params?: Record<string, string | number | boolean>, defaultValue?: string) => unknown;
|
|
14
16
|
type PluralFunc = (key: string, count: number, locale: string, getter: Getter) => string | null;
|
package/dist/module.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ interface Locale {
|
|
|
9
9
|
iso?: string;
|
|
10
10
|
dir?: 'ltr' | 'rtl' | 'auto';
|
|
11
11
|
displayName?: string;
|
|
12
|
+
baseUrl?: string;
|
|
13
|
+
baseDefault?: boolean;
|
|
12
14
|
}
|
|
13
15
|
type Getter = (key: string, params?: Record<string, string | number | boolean>, defaultValue?: string) => unknown;
|
|
14
16
|
type PluralFunc = (key: string, count: number, locale: string, getter: Getter) => string | null;
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -444,6 +444,12 @@ const module = defineNuxtModule({
|
|
|
444
444
|
throw new Error('Nuxt-i18n-micro: "includeDefaultLocaleRoute" must be set to true when using Cloudflare Pages.');
|
|
445
445
|
}
|
|
446
446
|
const logger = useLogger("nuxt-i18n-micro");
|
|
447
|
+
try {
|
|
448
|
+
const storagePahh = path.join(nuxt.options.rootDir, "./server/assets");
|
|
449
|
+
fs__default.rmdirSync(storagePahh);
|
|
450
|
+
logger.log(`Cleanup storage: ${storagePahh}`);
|
|
451
|
+
} catch {
|
|
452
|
+
}
|
|
447
453
|
const resolver = createResolver(import.meta.url);
|
|
448
454
|
const rootDirs = nuxt.options._layers.map((layer) => layer.config.rootDir).reverse();
|
|
449
455
|
const localeManager = new LocaleManager(options, rootDirs);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div :class="['i18n-group', groupClass]">
|
|
3
|
+
<slot
|
|
4
|
+
:prefix="prefix"
|
|
5
|
+
:t="translate"
|
|
6
|
+
/>
|
|
7
|
+
</div>
|
|
8
|
+
</template>
|
|
9
|
+
|
|
10
|
+
<script setup>
|
|
11
|
+
import { useI18n } from '../composables/useI18n'
|
|
12
|
+
|
|
13
|
+
const props = defineProps({
|
|
14
|
+
prefix: { type: String, required: true },
|
|
15
|
+
groupClass: { type: String, default: '' },
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
const { t } = useI18n()
|
|
19
|
+
const translate = (key, params = {}) => t(`${props.prefix}.${key}`, params)
|
|
20
|
+
</script>
|
|
@@ -1,24 +1,39 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div :style="[wrapperStyle, customWrapperStyle]">
|
|
3
|
+
<slot name="before-button" />
|
|
4
|
+
|
|
3
5
|
<button
|
|
4
6
|
class="language-switcher"
|
|
5
7
|
:style="[buttonStyle, customButtonStyle]"
|
|
6
8
|
@click="toggleDropdown"
|
|
7
9
|
>
|
|
10
|
+
<slot name="before-selected-locale" />
|
|
8
11
|
{{ currentLocaleLabel }}
|
|
12
|
+
<slot name="after-selected-locale" />
|
|
9
13
|
<span :style="[iconStyle, dropdownOpen ? openIconStyle : {}, customIconStyle]">▾</span>
|
|
10
14
|
</button>
|
|
15
|
+
|
|
16
|
+
<slot name="before-dropdown" />
|
|
17
|
+
|
|
11
18
|
<ul
|
|
12
|
-
v-
|
|
19
|
+
v-show="dropdownOpen"
|
|
13
20
|
:style="[dropdownStyle, customDropdownStyle]"
|
|
14
21
|
>
|
|
22
|
+
<slot name="before-dropdown-items" />
|
|
23
|
+
|
|
15
24
|
<li
|
|
16
25
|
v-for="locale in locales"
|
|
17
26
|
:key="locale.code"
|
|
18
27
|
:style="[itemStyle, customItemStyle]"
|
|
19
28
|
>
|
|
29
|
+
<slot
|
|
30
|
+
name="before-item"
|
|
31
|
+
:locale="locale"
|
|
32
|
+
/>
|
|
33
|
+
|
|
20
34
|
<NuxtLink
|
|
21
35
|
:class="`switcher-locale-${locale.code}`"
|
|
36
|
+
:to="$switchLocaleRoute(locale.code)"
|
|
22
37
|
:style="[
|
|
23
38
|
linkStyle,
|
|
24
39
|
locale.code === currentLocale ? activeLinkStyle : {},
|
|
@@ -26,12 +41,29 @@
|
|
|
26
41
|
customLinkStyle,
|
|
27
42
|
]"
|
|
28
43
|
:hreflang="locale.iso || locale.code"
|
|
29
|
-
@click="switchLocale(
|
|
44
|
+
@click="switchLocale()"
|
|
30
45
|
>
|
|
46
|
+
<slot
|
|
47
|
+
name="before-link-content"
|
|
48
|
+
:locale="locale"
|
|
49
|
+
/>
|
|
31
50
|
{{ localeLabel(locale) }}
|
|
51
|
+
<slot
|
|
52
|
+
name="after-link-content"
|
|
53
|
+
:locale="locale"
|
|
54
|
+
/>
|
|
32
55
|
</NuxtLink>
|
|
56
|
+
|
|
57
|
+
<slot
|
|
58
|
+
name="after-item"
|
|
59
|
+
:locale="locale"
|
|
60
|
+
/>
|
|
33
61
|
</li>
|
|
62
|
+
|
|
63
|
+
<slot name="after-dropdown-items" />
|
|
34
64
|
</ul>
|
|
65
|
+
|
|
66
|
+
<slot name="after-dropdown" />
|
|
35
67
|
</div>
|
|
36
68
|
</template>
|
|
37
69
|
|
|
@@ -47,6 +79,8 @@ interface Locale {
|
|
|
47
79
|
iso?: string
|
|
48
80
|
dir?: 'ltr' | 'rtl' | 'auto'
|
|
49
81
|
displayName?: string
|
|
82
|
+
baseUrl?: string
|
|
83
|
+
baseDefault?: boolean
|
|
50
84
|
}
|
|
51
85
|
|
|
52
86
|
interface Props {
|
|
@@ -73,7 +107,7 @@ const props = withDefaults(defineProps<Props>(), {
|
|
|
73
107
|
customIconStyle: () => ({}),
|
|
74
108
|
})
|
|
75
109
|
|
|
76
|
-
const { $
|
|
110
|
+
const { $switchLocaleRoute, $getLocales, $getLocale, $getLocaleName } = useNuxtApp()
|
|
77
111
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
78
112
|
// @ts-ignore
|
|
79
113
|
const locales = ref($getLocales())
|
|
@@ -104,9 +138,8 @@ const currentLocaleLabel = computed(() => localeLabel({
|
|
|
104
138
|
displayName: currentLocaleName.value ?? undefined,
|
|
105
139
|
}))
|
|
106
140
|
|
|
107
|
-
const switchLocale = (
|
|
141
|
+
const switchLocale = () => {
|
|
108
142
|
toggleDropdown()
|
|
109
|
-
return $switchLocale(locale.code)
|
|
110
143
|
}
|
|
111
144
|
|
|
112
145
|
// Default Styles
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useTranslationHelper } from "../translationHelper.js";
|
|
2
2
|
import { defineNuxtPlugin, useRuntimeConfig } from "#app";
|
|
3
|
-
import { useRoute, useRouter, useCookie, useState } from "#imports";
|
|
3
|
+
import { useRoute, useRouter, useCookie, useState, navigateTo } from "#imports";
|
|
4
4
|
import { plural } from "#build/i18n.plural.mjs";
|
|
5
5
|
const i18nHelper = useTranslationHelper();
|
|
6
6
|
const isDev = process.env.NODE_ENV !== "production";
|
|
@@ -29,6 +29,19 @@ function getRouteName(route, locale) {
|
|
|
29
29
|
return (route?.name ?? "").toString().replace("localized-", "").replace(new RegExp(`-${locale}$`), "");
|
|
30
30
|
}
|
|
31
31
|
function switchLocaleRoute(fromLocale, toLocale, route, router, i18nConfig, i18nRouteParams) {
|
|
32
|
+
const currentLocale = i18nConfig.locales?.find((l) => l.code === toLocale);
|
|
33
|
+
function getFullPathWithBaseUrl(route2) {
|
|
34
|
+
const resolvedRoute = router.resolve(route2);
|
|
35
|
+
let fullPath = resolvedRoute.fullPath;
|
|
36
|
+
if (currentLocale?.baseDefault) {
|
|
37
|
+
fullPath = fullPath.replace(new RegExp(`^/${currentLocale.code}`), "");
|
|
38
|
+
}
|
|
39
|
+
let baseUrl = currentLocale.baseUrl;
|
|
40
|
+
if (baseUrl?.endsWith("/")) {
|
|
41
|
+
baseUrl = baseUrl.slice(0, -1);
|
|
42
|
+
}
|
|
43
|
+
return baseUrl + fullPath;
|
|
44
|
+
}
|
|
32
45
|
const routeName = getRouteName(route, fromLocale);
|
|
33
46
|
if (router.hasRoute(`localized-${routeName}-${toLocale}`)) {
|
|
34
47
|
const newParams2 = { ...route.params, ...i18nRouteParams?.[toLocale] };
|
|
@@ -37,10 +50,14 @@ function switchLocaleRoute(fromLocale, toLocale, route, router, i18nConfig, i18n
|
|
|
37
50
|
const userLocaleCookie = useCookie("hash-locale");
|
|
38
51
|
userLocaleCookie.value = toLocale;
|
|
39
52
|
}
|
|
40
|
-
|
|
53
|
+
const newRoute2 = {
|
|
41
54
|
name: `localized-${routeName}-${toLocale}`,
|
|
42
55
|
params: newParams2
|
|
43
56
|
};
|
|
57
|
+
if (currentLocale?.baseUrl) {
|
|
58
|
+
return getFullPathWithBaseUrl(newRoute2);
|
|
59
|
+
}
|
|
60
|
+
return newRoute2;
|
|
44
61
|
}
|
|
45
62
|
const newRouteName = toLocale !== i18nConfig.defaultLocale || i18nConfig.includeDefaultLocaleRoute ? `localized-${routeName}` : routeName;
|
|
46
63
|
const newParams = { ...route.params, ...i18nRouteParams?.[toLocale] };
|
|
@@ -52,7 +69,14 @@ function switchLocaleRoute(fromLocale, toLocale, route, router, i18nConfig, i18n
|
|
|
52
69
|
const userLocaleCookie = useCookie("hash-locale");
|
|
53
70
|
userLocaleCookie.value = toLocale;
|
|
54
71
|
}
|
|
55
|
-
|
|
72
|
+
const newRoute = {
|
|
73
|
+
name: newRouteName,
|
|
74
|
+
params: newParams
|
|
75
|
+
};
|
|
76
|
+
if (currentLocale?.baseUrl) {
|
|
77
|
+
return getFullPathWithBaseUrl(newRoute);
|
|
78
|
+
}
|
|
79
|
+
return newRoute;
|
|
56
80
|
}
|
|
57
81
|
function switchLocale(fromLocale, toLocale, route, router, i18nConfig, i18nRouteParams) {
|
|
58
82
|
const checkLocale = i18nConfig.locales?.find((l) => l.code === toLocale);
|
|
@@ -68,6 +92,9 @@ function switchLocale(fromLocale, toLocale, route, router, i18nConfig, i18nRoute
|
|
|
68
92
|
i18nConfig,
|
|
69
93
|
i18nRouteParams
|
|
70
94
|
);
|
|
95
|
+
if (typeof switchedRoute === "string" && switchedRoute.startsWith("http")) {
|
|
96
|
+
return navigateTo(switchedRoute, { redirectCode: 200, external: true });
|
|
97
|
+
}
|
|
71
98
|
return router.push(switchedRoute);
|
|
72
99
|
}
|
|
73
100
|
function getLocalizedRoute(to, router, route, i18nConfig, locale, hashLocale) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-i18n-micro",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.32.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":"c81d9b67-6e51-4931-a0b1-9b731a2a5d0c","timestamp":1731047980533,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|