nuxt-i18n-micro 3.18.3 → 3.20.0
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/README.md +16 -16
- package/dist/client/200.html +1 -1
- package/dist/client/404.html +1 -1
- package/dist/client/_nuxt/{D6byAye8.js → BA2bGsrZ.js} +1 -1
- package/dist/client/_nuxt/{BNXusRXY.js → C_HK2snF.js} +1 -1
- package/dist/client/_nuxt/{BCTbvRLO.js → Dx6dmpFi.js} +1 -1
- package/dist/client/_nuxt/SDQMalAT.js +14 -0
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/5a55317c-1ad8-41ca-a7f6-2fe58e16b2f6.json +1 -0
- package/dist/client/index.html +1 -1
- package/dist/module.d.mts +1 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +197 -231
- package/dist/runtime/components/i18n-group.vue +1 -4
- package/dist/runtime/components/i18n-link.vue +2 -12
- package/dist/runtime/components/i18n-switcher.vue +7 -30
- package/dist/runtime/composables/useI18n.js +1 -1
- package/dist/runtime/composables/useI18nLocale.js +5 -6
- package/dist/runtime/composables/useLocaleHead.js +2 -2
- package/dist/runtime/middleware/i18n-redirect.global.d.ts +6 -0
- package/dist/runtime/middleware/i18n-redirect.global.js +43 -0
- package/dist/runtime/plugins/01.plugin.d.ts +21 -21
- package/dist/runtime/plugins/01.plugin.js +69 -313
- package/dist/runtime/plugins/02.meta.js +2 -2
- package/dist/runtime/plugins/05.hooks.js +32 -32
- package/dist/runtime/plugins/06.redirect.d.ts +1 -0
- package/dist/runtime/plugins/06.redirect.js +15 -86
- package/dist/runtime/server/middleware/i18n.global.js +17 -5
- package/dist/runtime/server/plugins/watcher.dev.js +36 -66
- package/dist/runtime/server/routes/i18n.js +2 -2
- package/dist/runtime/server/utils/locale-detector.d.ts +9 -12
- package/dist/runtime/server/utils/locale-detector.js +25 -18
- package/dist/runtime/server/utils/locale-server-middleware.js +10 -8
- package/dist/runtime/server/utils/server-loader.d.ts +3 -3
- package/dist/runtime/server/utils/server-loader.js +40 -15
- package/dist/runtime/server/utils/translation-server-middleware.js +10 -8
- package/dist/runtime/utils/nuxt-i18n.d.ts +122 -0
- package/dist/runtime/utils/nuxt-i18n.js +335 -0
- package/dist/runtime/utils/storage.d.ts +11 -12
- package/dist/runtime/utils/storage.js +37 -21
- package/dist/types.d.mts +2 -0
- package/internals.d.mts +1 -0
- package/package.json +21 -15
- package/dist/client/_nuxt/B-cq5x_h.js +0 -14
- package/dist/client/_nuxt/builds/meta/c5d2004e-f981-4363-a9ec-4d72cf7f4a8f.json +0 -1
- package/dist/runtime/utils/accept-language.d.ts +0 -3
- package/dist/runtime/utils/accept-language.js +0 -21
- package/dist/runtime/utils/active-locales.d.ts +0 -4
- package/dist/runtime/utils/active-locales.js +0 -9
- package/dist/runtime/utils/cache-control.d.ts +0 -50
- package/dist/runtime/utils/cache-control.js +0 -88
- package/dist/runtime/utils/cookie.d.ts +0 -24
- package/dist/runtime/utils/cookie.js +0 -22
- package/dist/runtime/utils/deep-merge.d.ts +0 -15
- package/dist/runtime/utils/deep-merge.js +0 -14
- package/dist/runtime/utils/resolve-server-locale.d.ts +0 -21
- package/dist/runtime/utils/resolve-server-locale.js +0 -30
- package/dist/runtime/utils/route-utils.d.ts +0 -33
- package/dist/runtime/utils/route-utils.js +0 -63
- package/dist/runtime/utils/runtime-i18n-config.d.ts +0 -8
- package/dist/runtime/utils/runtime-i18n-config.js +0 -90
|
@@ -1,19 +1,9 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<a
|
|
3
|
-
v-if="isExternalLink"
|
|
4
|
-
:href="externalHref"
|
|
5
|
-
:style="computedStyle"
|
|
6
|
-
target="_blank"
|
|
7
|
-
rel="noopener noreferrer"
|
|
8
|
-
>
|
|
2
|
+
<a v-if="isExternalLink" :href="externalHref" :style="computedStyle" target="_blank" rel="noopener noreferrer">
|
|
9
3
|
<slot />
|
|
10
4
|
</a>
|
|
11
5
|
|
|
12
|
-
<NuxtLink
|
|
13
|
-
v-else
|
|
14
|
-
:to="$localePath(to)"
|
|
15
|
-
:style="computedStyle"
|
|
16
|
-
>
|
|
6
|
+
<NuxtLink v-else :to="$localePath(to)" :style="computedStyle">
|
|
17
7
|
<slot />
|
|
18
8
|
</NuxtLink>
|
|
19
9
|
</template>
|
|
@@ -2,11 +2,7 @@
|
|
|
2
2
|
<div :style="[wrapperStyle, customWrapperStyle]">
|
|
3
3
|
<slot name="before-button" />
|
|
4
4
|
|
|
5
|
-
<button
|
|
6
|
-
class="language-switcher"
|
|
7
|
-
:style="[buttonStyle, customButtonStyle]"
|
|
8
|
-
@click="toggleDropdown"
|
|
9
|
-
>
|
|
5
|
+
<button class="language-switcher" :style="[buttonStyle, customButtonStyle]" @click="toggleDropdown">
|
|
10
6
|
<slot name="before-selected-locale" />
|
|
11
7
|
{{ currentLocaleLabel }}
|
|
12
8
|
<slot name="after-selected-locale" />
|
|
@@ -15,21 +11,11 @@
|
|
|
15
11
|
|
|
16
12
|
<slot name="before-dropdown" />
|
|
17
13
|
|
|
18
|
-
<ul
|
|
19
|
-
v-show="dropdownOpen"
|
|
20
|
-
:style="[dropdownStyle, customDropdownStyle]"
|
|
21
|
-
>
|
|
14
|
+
<ul v-show="dropdownOpen" :style="[dropdownStyle, customDropdownStyle]">
|
|
22
15
|
<slot name="before-dropdown-items" />
|
|
23
16
|
|
|
24
|
-
<li
|
|
25
|
-
|
|
26
|
-
:key="locale.code"
|
|
27
|
-
:style="[itemStyle, customItemStyle]"
|
|
28
|
-
>
|
|
29
|
-
<slot
|
|
30
|
-
name="before-item"
|
|
31
|
-
:locale="locale"
|
|
32
|
-
/>
|
|
17
|
+
<li v-for="locale in locales" :key="locale.code" :style="[itemStyle, customItemStyle]">
|
|
18
|
+
<slot name="before-item" :locale="locale" />
|
|
33
19
|
|
|
34
20
|
<NuxtLink
|
|
35
21
|
:class="`switcher-locale-${locale.code}`"
|
|
@@ -43,21 +29,12 @@
|
|
|
43
29
|
:hreflang="locale.iso || locale.code"
|
|
44
30
|
@click="switchLocale(locale.code)"
|
|
45
31
|
>
|
|
46
|
-
<slot
|
|
47
|
-
name="before-link-content"
|
|
48
|
-
:locale="locale"
|
|
49
|
-
/>
|
|
32
|
+
<slot name="before-link-content" :locale="locale" />
|
|
50
33
|
{{ localeLabel(locale) }}
|
|
51
|
-
<slot
|
|
52
|
-
name="after-link-content"
|
|
53
|
-
:locale="locale"
|
|
54
|
-
/>
|
|
34
|
+
<slot name="after-link-content" :locale="locale" />
|
|
55
35
|
</NuxtLink>
|
|
56
36
|
|
|
57
|
-
<slot
|
|
58
|
-
name="after-item"
|
|
59
|
-
:locale="locale"
|
|
60
|
-
/>
|
|
37
|
+
<slot name="after-item" :locale="locale" />
|
|
61
38
|
</li>
|
|
62
39
|
|
|
63
40
|
<slot name="after-dropdown-items" />
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getEnabledLocaleCodes } from "@i18n-micro/utils/active-locales";
|
|
2
|
+
import { getHashCookieName, getLocaleCookieName, getLocaleCookieOptions } from "@i18n-micro/utils/cookie";
|
|
3
|
+
import { resolveI18nConfigWithRuntimeOverrides } from "@i18n-micro/utils/runtime-config";
|
|
4
|
+
import { useCookie, useNuxtApp, useState } from "#app";
|
|
2
5
|
import { getI18nConfig } from "#build/i18n.strategy.mjs";
|
|
3
|
-
import { useCookie } from "#imports";
|
|
4
|
-
import { getEnabledLocaleCodes } from "../utils/active-locales.js";
|
|
5
|
-
import { getHashCookieName, getLocaleCookieName, getLocaleCookieOptions } from "../utils/cookie.js";
|
|
6
|
-
import { resolveI18nConfigWithRuntimeOverrides } from "../utils/runtime-i18n-config.js";
|
|
7
6
|
export function useI18nLocale() {
|
|
8
7
|
const nuxtApp = useNuxtApp();
|
|
9
8
|
const i18nConfig = resolveI18nConfigWithRuntimeOverrides(nuxtApp.$getI18nConfig?.() ?? getI18nConfig());
|
|
@@ -35,7 +34,7 @@ export function useI18nLocale() {
|
|
|
35
34
|
return localeState.value ?? localeCookie.value ?? serverLocale ?? null;
|
|
36
35
|
};
|
|
37
36
|
const getEffectiveLocale = (route, getLocaleFromRoute) => {
|
|
38
|
-
if (i18nConfig.hashMode && localeState.value
|
|
37
|
+
if (i18nConfig.hashMode && localeState.value !== null && localeState.value !== void 0) return localeState.value;
|
|
39
38
|
return getLocaleFromRoute(route);
|
|
40
39
|
};
|
|
41
40
|
const resolveInitialLocale = (options) => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { isNoPrefixStrategy } from "@i18n-micro/core";
|
|
2
|
+
import { findAllowedLocalesForRoute } from "@i18n-micro/utils/route";
|
|
2
3
|
import { joinURL, parseURL, withQuery } from "ufo";
|
|
3
4
|
import { ref, unref, watch } from "vue";
|
|
4
|
-
import { useNuxtApp, useRoute } from "#
|
|
5
|
-
import { findAllowedLocalesForRoute } from "../utils/route-utils.js";
|
|
5
|
+
import { useNuxtApp, useRoute } from "#app";
|
|
6
6
|
export const useLocaleHead = ({
|
|
7
7
|
addDirAttribute = true,
|
|
8
8
|
identifierAttribute = "id",
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { getEnabledLocaleCodes } from "@i18n-micro/utils/active-locales";
|
|
2
|
+
import { defineNuxtRouteMiddleware, navigateTo, useNuxtApp } from "#imports";
|
|
3
|
+
import { useI18nLocale } from "../composables/useI18nLocale.js";
|
|
4
|
+
function redirectTo(path, to) {
|
|
5
|
+
return navigateTo({ path, query: to.query, hash: to.hash }, { replace: true, redirectCode: 302 });
|
|
6
|
+
}
|
|
7
|
+
export default defineNuxtRouteMiddleware((to, from) => {
|
|
8
|
+
if (import.meta.server) return;
|
|
9
|
+
const nuxtApp = useNuxtApp();
|
|
10
|
+
const getRuntimeConfig = nuxtApp.$getI18nConfig;
|
|
11
|
+
const i18nStrategy = nuxtApp.$i18nStrategy;
|
|
12
|
+
if (typeof getRuntimeConfig !== "function" || !i18nStrategy) return;
|
|
13
|
+
const i18nConfig = getRuntimeConfig();
|
|
14
|
+
if (i18nConfig.redirects === false) return;
|
|
15
|
+
if (to.path === from.path) return;
|
|
16
|
+
const validLocales = getEnabledLocaleCodes(i18nConfig.locales);
|
|
17
|
+
const defaultLocale = i18nConfig.defaultLocale || "en";
|
|
18
|
+
const autoDetectPath = i18nConfig.autoDetectPath || "/";
|
|
19
|
+
const { getPreferredLocale } = useI18nLocale();
|
|
20
|
+
const routeLocale = i18nStrategy.getCurrentLocale(to, getPreferredLocale());
|
|
21
|
+
let preferredLocale = routeLocale || getPreferredLocale() || defaultLocale;
|
|
22
|
+
const path = to.path || "/";
|
|
23
|
+
const pathSegments = path.replace(/^\//, "").split("/").filter(Boolean);
|
|
24
|
+
const firstSegment = pathSegments[0];
|
|
25
|
+
const hasLocalePrefix = Boolean(firstSegment && validLocales.includes(firstSegment));
|
|
26
|
+
if (autoDetectPath === "*" && !hasLocalePrefix) {
|
|
27
|
+
preferredLocale = defaultLocale;
|
|
28
|
+
}
|
|
29
|
+
if (autoDetectPath === "*" && hasLocalePrefix && firstSegment !== preferredLocale) {
|
|
30
|
+
const rest = pathSegments.slice(1).join("/");
|
|
31
|
+
let targetPath;
|
|
32
|
+
if (preferredLocale === defaultLocale && i18nConfig.strategy === "prefix_except_default") {
|
|
33
|
+
targetPath = rest ? `/${rest}` : "/";
|
|
34
|
+
} else {
|
|
35
|
+
targetPath = rest ? `/${preferredLocale}/${rest}` : `/${preferredLocale}`;
|
|
36
|
+
}
|
|
37
|
+
return redirectTo(targetPath, to);
|
|
38
|
+
}
|
|
39
|
+
const redirectPath = i18nStrategy.getClientRedirect(path, preferredLocale);
|
|
40
|
+
if (redirectPath) {
|
|
41
|
+
return redirectTo(redirectPath, to);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
@@ -3,32 +3,32 @@ import type { CleanTranslation, I18nRouteParams, Locale, MissingHandler, ModuleO
|
|
|
3
3
|
import type { RouteLocationNamedRaw, RouteLocationNormalizedLoaded, RouteLocationRaw, RouteLocationResolved, RouteLocationResolvedGeneric } from 'vue-router';
|
|
4
4
|
declare const _default: import("nuxt/app").Plugin<{
|
|
5
5
|
getI18nConfig: () => ModuleOptionsExtend;
|
|
6
|
-
i18n: undefined;
|
|
7
|
-
__micro: boolean;
|
|
8
6
|
helper: {
|
|
9
7
|
mergeTranslation(locale: string, routeName: string, newTranslations: Translations, _force?: boolean): Promise<void>;
|
|
10
8
|
};
|
|
11
|
-
|
|
9
|
+
i18n: unknown;
|
|
10
|
+
__micro: boolean;
|
|
11
|
+
i18nStrategy: PathStrategy;
|
|
12
12
|
getLocale: (route?: RouteLocationNormalizedLoaded | RouteLocationResolvedGeneric) => string;
|
|
13
|
-
getLocaleName: () =>
|
|
13
|
+
getLocaleName: () => string | null;
|
|
14
14
|
defaultLocale: () => string | undefined;
|
|
15
15
|
getLocales: () => Locale[];
|
|
16
|
-
getRouteName: (route?: RouteLocationNormalizedLoaded | RouteLocationResolvedGeneric, locale?: string) =>
|
|
17
|
-
t: (key:
|
|
16
|
+
getRouteName: (route?: RouteLocationNormalizedLoaded | RouteLocationResolvedGeneric, locale?: string) => string;
|
|
17
|
+
t: (key: import("@i18n-micro/types").TranslationKey, params?: Params, defaultValue?: string | null, routeContext?: unknown) => CleanTranslation;
|
|
18
18
|
ts: (key: string, params?: Params, defaultValue?: string, route?: RouteLocationNormalizedLoaded) => string;
|
|
19
19
|
_t: (route: RouteLocationNormalizedLoaded) => (key: string, params?: Params, defaultValue?: string | null) => CleanTranslation;
|
|
20
20
|
_ts: (route: RouteLocationNormalizedLoaded) => (key: string, params?: Params, defaultValue?: string) => string;
|
|
21
|
-
tc: (key:
|
|
21
|
+
tc: (key: import("@i18n-micro/types").TranslationKey, count: number | Params, defaultValue?: string) => string;
|
|
22
22
|
tn: (value: number, options?: Intl.NumberFormatOptions) => string;
|
|
23
23
|
td: (value: Date | number | string, options?: Intl.DateTimeFormatOptions) => string;
|
|
24
24
|
tdr: (value: Date | number | string, options?: Intl.RelativeTimeFormatOptions) => string;
|
|
25
|
-
has: (key:
|
|
25
|
+
has: (key: import("@i18n-micro/types").TranslationKey, routeContext?: unknown) => boolean;
|
|
26
26
|
mergeTranslations: (newTranslations: Translations) => void;
|
|
27
27
|
switchLocaleRoute: (toLocale: string) => RouteLocationRaw;
|
|
28
28
|
clearCache: () => void;
|
|
29
29
|
switchLocalePath: (toLocale: string) => string;
|
|
30
|
-
switchLocale: (toLocale: string) => Promise<
|
|
31
|
-
switchRoute: (route: RouteLocationNamedRaw | RouteLocationResolvedGeneric | string, toLocale?: string) =>
|
|
30
|
+
switchLocale: (toLocale: string) => Promise<unknown>;
|
|
31
|
+
switchRoute: (route: RouteLocationNamedRaw | RouteLocationResolvedGeneric | string, toLocale?: string) => unknown;
|
|
32
32
|
localeRoute(to: RouteLocationNamedRaw | RouteLocationResolvedGeneric | string, locale?: string): RouteLocationResolved;
|
|
33
33
|
localePath(to: RouteLocationNamedRaw | RouteLocationResolvedGeneric | string, locale?: string): string;
|
|
34
34
|
setI18nRouteParams: (value: I18nRouteParams) => I18nRouteParams;
|
|
@@ -36,32 +36,32 @@ declare const _default: import("nuxt/app").Plugin<{
|
|
|
36
36
|
setMissingHandler: (handler: MissingHandler | null) => void;
|
|
37
37
|
}> & import("nuxt/app").ObjectPlugin<{
|
|
38
38
|
getI18nConfig: () => ModuleOptionsExtend;
|
|
39
|
-
i18n: undefined;
|
|
40
|
-
__micro: boolean;
|
|
41
39
|
helper: {
|
|
42
40
|
mergeTranslation(locale: string, routeName: string, newTranslations: Translations, _force?: boolean): Promise<void>;
|
|
43
41
|
};
|
|
44
|
-
|
|
42
|
+
i18n: unknown;
|
|
43
|
+
__micro: boolean;
|
|
44
|
+
i18nStrategy: PathStrategy;
|
|
45
45
|
getLocale: (route?: RouteLocationNormalizedLoaded | RouteLocationResolvedGeneric) => string;
|
|
46
|
-
getLocaleName: () =>
|
|
46
|
+
getLocaleName: () => string | null;
|
|
47
47
|
defaultLocale: () => string | undefined;
|
|
48
48
|
getLocales: () => Locale[];
|
|
49
|
-
getRouteName: (route?: RouteLocationNormalizedLoaded | RouteLocationResolvedGeneric, locale?: string) =>
|
|
50
|
-
t: (key:
|
|
49
|
+
getRouteName: (route?: RouteLocationNormalizedLoaded | RouteLocationResolvedGeneric, locale?: string) => string;
|
|
50
|
+
t: (key: import("@i18n-micro/types").TranslationKey, params?: Params, defaultValue?: string | null, routeContext?: unknown) => CleanTranslation;
|
|
51
51
|
ts: (key: string, params?: Params, defaultValue?: string, route?: RouteLocationNormalizedLoaded) => string;
|
|
52
52
|
_t: (route: RouteLocationNormalizedLoaded) => (key: string, params?: Params, defaultValue?: string | null) => CleanTranslation;
|
|
53
53
|
_ts: (route: RouteLocationNormalizedLoaded) => (key: string, params?: Params, defaultValue?: string) => string;
|
|
54
|
-
tc: (key:
|
|
54
|
+
tc: (key: import("@i18n-micro/types").TranslationKey, count: number | Params, defaultValue?: string) => string;
|
|
55
55
|
tn: (value: number, options?: Intl.NumberFormatOptions) => string;
|
|
56
56
|
td: (value: Date | number | string, options?: Intl.DateTimeFormatOptions) => string;
|
|
57
57
|
tdr: (value: Date | number | string, options?: Intl.RelativeTimeFormatOptions) => string;
|
|
58
|
-
has: (key:
|
|
58
|
+
has: (key: import("@i18n-micro/types").TranslationKey, routeContext?: unknown) => boolean;
|
|
59
59
|
mergeTranslations: (newTranslations: Translations) => void;
|
|
60
60
|
switchLocaleRoute: (toLocale: string) => RouteLocationRaw;
|
|
61
61
|
clearCache: () => void;
|
|
62
62
|
switchLocalePath: (toLocale: string) => string;
|
|
63
|
-
switchLocale: (toLocale: string) => Promise<
|
|
64
|
-
switchRoute: (route: RouteLocationNamedRaw | RouteLocationResolvedGeneric | string, toLocale?: string) =>
|
|
63
|
+
switchLocale: (toLocale: string) => Promise<unknown>;
|
|
64
|
+
switchRoute: (route: RouteLocationNamedRaw | RouteLocationResolvedGeneric | string, toLocale?: string) => unknown;
|
|
65
65
|
localeRoute(to: RouteLocationNamedRaw | RouteLocationResolvedGeneric | string, locale?: string): RouteLocationResolved;
|
|
66
66
|
localePath(to: RouteLocationNamedRaw | RouteLocationResolvedGeneric | string, locale?: string): string;
|
|
67
67
|
setI18nRouteParams: (value: I18nRouteParams) => I18nRouteParams;
|
|
@@ -74,8 +74,8 @@ export interface PluginsInjections {
|
|
|
74
74
|
$getI18nConfig: () => ModuleOptionsExtend;
|
|
75
75
|
$getLocale: (route?: RouteLocationNormalizedLoaded | RouteLocationResolvedGeneric) => string;
|
|
76
76
|
$getLocaleName: () => string | null;
|
|
77
|
-
$getLocales: () => Locale[];
|
|
78
77
|
$defaultLocale: () => string | undefined;
|
|
78
|
+
$getLocales: () => Locale[];
|
|
79
79
|
$getRouteName: (route?: RouteLocationNamedRaw | RouteLocationResolvedGeneric, locale?: string) => string;
|
|
80
80
|
$t: (key: string, params?: Params, defaultValue?: string | null) => CleanTranslation;
|
|
81
81
|
$_t: (route: RouteLocationNormalizedLoaded) => (key: string, params?: Params, defaultValue?: string | null) => CleanTranslation;
|