@nuxtjs/i18n-edge 10.4.1-29732659.cb28c19 → 10.4.1-29734085.45d4b0e

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/module.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "nuxt": ">=3.0.0-rc.11",
6
6
  "bridge": false
7
7
  },
8
- "version": "10.4.1-29732659.cb28c19",
8
+ "version": "10.4.1-29734085.45d4b0e",
9
9
  "builder": {
10
10
  "@nuxt/module-builder": "1.0.2",
11
11
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -1276,7 +1276,7 @@ const HeistPlugin = (options, ctx, nuxt = useNuxt()) => {
1276
1276
  }));
1277
1277
  };
1278
1278
 
1279
- const version = "10.4.1-29732659.cb28c19";
1279
+ const version = "10.4.1-29734085.45d4b0e";
1280
1280
 
1281
1281
  async function extendBundler(ctx, nuxt) {
1282
1282
  const pluginOptions = {
@@ -1,17 +1,17 @@
1
1
  import type { NuxtApp } from '#app';
2
- import type { RouteLocationPathRaw, RouteRecordNameGeneric, Router } from 'vue-router';
3
- import type { I18nHeadMetaInfo, I18nHeadOptions, LocaleObject } from '#internal-i18n-types';
2
+ import type { I18nHeadMetaInfo, I18nHeadOptions } from '#internal-i18n-types';
4
3
  import type { NuxtI18nContext } from './context.js';
5
- import type { RouteLike } from './routing/routing.js';
6
- import type { I18nRouteMeta, RouteLocationGenericPath } from './types.js';
4
+ import type { RoutingContext } from './routing/context.js';
7
5
  /**
8
6
  * Common options used internally by composable functions, these
9
7
  * are initialized on request at the start of i18n:plugin.
10
8
  *
9
+ * Extends the platform-neutral {@link RoutingContext} with Nuxt-specific
10
+ * head/SEO state and the client hydration payload.
11
+ *
11
12
  * @internal
12
13
  */
13
- export type ComposableContext = {
14
- router: Router;
14
+ export type ComposableContext = RoutingContext & {
15
15
  routingOptions: {
16
16
  defaultLocale: string;
17
17
  /** Use `canonicalQueries` for alternate links */
@@ -24,20 +24,7 @@ export type ComposableContext = {
24
24
  metaState: Required<I18nHeadMetaInfo>;
25
25
  seoSettings: I18nHeadOptions;
26
26
  localePathPayload: Record<string, Record<string, string> | false>;
27
- getLocale: () => string;
28
- getLocales: () => LocaleObject[];
29
- getBaseUrl: () => string;
30
- /** Extracts the route base name (without locale suffix) */
31
- getRouteBaseName: (route: RouteRecordNameGeneric | RouteLocationGenericPath | null) => string | undefined;
32
- /** Modifies the resolved localized path. Middleware for `switchLocalePath` */
33
- afterSwitchLocalePath: (path: string, locale: string) => string;
34
- /** Provides localized dynamic parameters for the current route */
35
- getLocalizedDynamicParams: (locale: string) => Record<string, unknown> | false | undefined;
36
- /** Prepares a route object to be resolved as a localized route */
37
- resolveLocalizedRouteObject: (route: RouteLike, locale: string) => RouteLike;
38
- getRouteLocalizedParams: () => Partial<I18nRouteMeta>;
39
27
  };
40
- export declare const isRouteLocationPathRaw: (val: RouteLike) => val is RouteLocationPathRaw;
41
28
  export declare function useComposableContext(nuxtApp: NuxtApp): ComposableContext;
42
29
  export declare function createComposableContext(ctx: NuxtI18nContext, nuxtApp?: NuxtApp): ComposableContext;
43
30
  declare global {
@@ -1,11 +1,5 @@
1
- import { joinURL } from "ufo";
2
- import { useHead, useNuxtApp, useRequestEvent, useRequestURL, useRouter } from "#imports";
3
- import { createLocaleRouteNameGetter, createLocalizedRouteByPathResolver } from "./routing/utils.js";
4
- import { formatTrailingSlash, getRouteBaseName, prefixable } from "#i18n-kit/routing";
5
- import { getDefaultLocaleForDomain, isSupportedLocale } from "./shared/locales.js";
6
- import { useDetectors } from "./shared/detection.js";
7
- import { useI18nDetection } from "./shared/utils.js";
8
- export const isRouteLocationPathRaw = (val) => !!val.path && !val.name;
1
+ import { useHead, useNuxtApp, useRequestURL, useRouter } from "#imports";
2
+ import { createRoutingContext } from "./routing/context.js";
9
3
  export function useComposableContext(nuxtApp) {
10
4
  const context = nuxtApp?._nuxtI18n?.composableCtx;
11
5
  if (!context) {
@@ -16,71 +10,18 @@ export function useComposableContext(nuxtApp) {
16
10
  return context;
17
11
  }
18
12
  export function createComposableContext(ctx, nuxtApp = useNuxtApp()) {
19
- const router = useRouter();
20
- const detectors = useDetectors(useRequestEvent(), useI18nDetection(nuxtApp), nuxtApp);
21
- const defaultLocale = ctx.getDefaultLocale();
22
- const getLocalizedRouteName = createLocaleRouteNameGetter(defaultLocale);
23
- function resolveLocalizedRouteByName(route, locale) {
24
- route.name = getRouteBaseName(route.name || router.currentRoute.value);
25
- const localizedName = getLocalizedRouteName(route.name, locale);
26
- if (router.hasRoute(localizedName)) {
27
- route.name = localizedName;
28
- if (__I18N_COMPACT_ROUTES__ && route.params) {
29
- delete route.params.locale;
30
- }
31
- } else if (__I18N_COMPACT_ROUTES__ && isSupportedLocale(locale) && getCompactRouteNames().has(route.name)) {
32
- route.params = { ...route.params || {}, locale };
33
- return route;
34
- }
35
- route.name = localizedName;
36
- return route;
37
- }
38
- const routeByPathResolver = createLocalizedRouteByPathResolver(router);
39
- let compactRouteRecords;
40
- function getCompactRouteNames() {
41
- if (compactRouteRecords) {
42
- return compactRouteRecords;
43
- }
44
- compactRouteRecords = /* @__PURE__ */ new Set();
45
- if (__I18N_COMPACT_ROUTES__) {
46
- for (const r of router.getRoutes()) {
47
- if (r.name != null && /^\/:locale\(/.test(r.path)) {
48
- compactRouteRecords.add(String(r.name));
49
- }
50
- }
51
- }
52
- return compactRouteRecords;
53
- }
54
- function resolveLocalizedRouteByPath(input, locale) {
55
- const route = routeByPathResolver(input, locale);
56
- const baseName = getRouteBaseName(route);
57
- if (baseName) {
58
- const localizedName = getLocalizedRouteName(baseName, locale);
59
- if (router.hasRoute(localizedName)) {
60
- route.name = localizedName;
61
- const named = route;
62
- if (__I18N_COMPACT_ROUTES__ && named.params) {
63
- delete named.params.locale;
64
- }
65
- return route;
66
- }
67
- if (__I18N_COMPACT_ROUTES__ && getCompactRouteNames().has(baseName)) {
68
- const compacted = route;
69
- compacted.name = baseName;
70
- compacted.params = { ...compacted.params || {}, locale };
71
- return compacted;
72
- }
73
- route.name = localizedName;
74
- return route;
75
- }
76
- if (prefixable(locale, defaultLocale)) {
77
- route.path = "/" + locale + route.path;
78
- }
79
- route.path = formatTrailingSlash(route.path, true);
80
- return route;
81
- }
82
- const composableCtx = {
83
- router,
13
+ const localePathPayload = getLocalePathPayload(nuxtApp);
14
+ const routingCtx = createRoutingContext({
15
+ router: useRouter(),
16
+ defaultLocale: ctx.getDefaultLocale(),
17
+ getLocale: ctx.getLocale,
18
+ getLocales: ctx.getLocales,
19
+ getBaseUrl: ctx.getBaseUrl,
20
+ getHost: () => useRequestURL({ xForwardedHost: true }).host,
21
+ getLocalePathPayload: () => __I18N_STRICT_SEO__ && import.meta.client && nuxtApp.isHydrating && localePathPayload
22
+ });
23
+ return {
24
+ ...routingCtx,
84
25
  _head: void 0,
85
26
  get head() {
86
27
  this._head ??= useHead({});
@@ -93,45 +34,13 @@ export function createComposableContext(ctx, nuxtApp = useNuxtApp()) {
93
34
  // the object form carries `canonicalQueries`, `__I18N_STRICT_SEO__` only compiles its truthiness
94
35
  seo: typeof ctx.config.experimental.strictSeo === "object" && ctx.config.experimental.strictSeo || __I18N_STRICT_SEO__
95
36
  },
96
- localePathPayload: getLocalePathPayload(),
37
+ localePathPayload,
97
38
  routingOptions: {
98
- defaultLocale,
39
+ defaultLocale: ctx.getDefaultLocale(),
99
40
  strictCanonicals: ctx.config.experimental.alternateLinkCanonicalQueries ?? true,
100
41
  hreflangLinks: !(!__I18N_ROUTING__ && !__DIFFERENT_DOMAINS__)
101
- },
102
- getLocale: ctx.getLocale,
103
- getLocales: ctx.getLocales,
104
- getBaseUrl: ctx.getBaseUrl,
105
- getRouteBaseName,
106
- getRouteLocalizedParams: () => router.currentRoute.value.meta[__DYNAMIC_PARAMS_KEY__] ?? {},
107
- getLocalizedDynamicParams: (locale) => {
108
- if (__I18N_STRICT_SEO__ && import.meta.client && nuxtApp.isHydrating && composableCtx.localePathPayload) {
109
- return composableCtx.localePathPayload[locale] || {};
110
- }
111
- return composableCtx.getRouteLocalizedParams()?.[locale];
112
- },
113
- afterSwitchLocalePath: (path, locale) => {
114
- const params = composableCtx.getRouteLocalizedParams();
115
- if (__I18N_STRICT_SEO__ && locale && Object.keys(params).length && !params[locale]) {
116
- return "";
117
- }
118
- if (__MULTI_DOMAIN_LOCALES__ && __I18N_STRATEGY__ === "prefix_except_default") {
119
- const defaultLocale2 = getDefaultLocaleForDomain(useRequestURL({ xForwardedHost: true }).host);
120
- if (locale !== defaultLocale2 || detectors.route(path) !== defaultLocale2) {
121
- return path;
122
- }
123
- return path.slice(locale.length + 1);
124
- }
125
- if (__DIFFERENT_DOMAINS__) {
126
- return joinURL(ctx.getBaseUrl(locale), path);
127
- }
128
- return path;
129
- },
130
- resolveLocalizedRouteObject: (route, locale) => {
131
- return isRouteLocationPathRaw(route) ? resolveLocalizedRouteByPath(route, locale) : resolveLocalizedRouteByName(route, locale);
132
42
  }
133
43
  };
134
- return composableCtx;
135
44
  }
136
45
  function getLocalePathPayload(nuxtApp = useNuxtApp()) {
137
46
  const payload = import.meta.client && document.querySelector(`[data-nuxt-i18n-slp="${nuxtApp._id}"]`)?.textContent;
@@ -0,0 +1,48 @@
1
+ import type { RouteLocationPathRaw, RouteRecordNameGeneric, Router } from 'vue-router';
2
+ import type { LocaleObject } from '#internal-i18n-types';
3
+ import type { RouteLike } from './routing.js';
4
+ import type { I18nRouteMeta, RouteLocationGenericPath } from '../types.js';
5
+ /**
6
+ * Platform-neutral context used by the routing functions (`localePath`,
7
+ * `localeRoute`, `switchLocalePath`, `getRouteBaseName`).
8
+ *
9
+ * @internal
10
+ */
11
+ export type RoutingContext = {
12
+ router: Router;
13
+ getLocale: () => string;
14
+ getLocales: () => LocaleObject[];
15
+ getBaseUrl: (locale?: string) => string;
16
+ /** Extracts the route base name (without locale suffix) */
17
+ getRouteBaseName: (route: RouteRecordNameGeneric | RouteLocationGenericPath | null) => string | undefined;
18
+ /** Modifies the resolved localized path. Middleware for `switchLocalePath` */
19
+ afterSwitchLocalePath: (path: string, locale: string) => string;
20
+ /** Provides localized dynamic parameters for the current route */
21
+ getLocalizedDynamicParams: (locale: string) => Record<string, unknown> | false | undefined;
22
+ /** Prepares a route object to be resolved as a localized route */
23
+ resolveLocalizedRouteObject: (route: RouteLike, locale: string) => RouteLike;
24
+ getRouteLocalizedParams: () => Partial<I18nRouteMeta>;
25
+ };
26
+ /**
27
+ * Explicit inputs from which a {@link RoutingContext} is constructed, so the
28
+ * context can be created without a Nuxt app (e.g. in unit tests with a
29
+ * memory-history router).
30
+ *
31
+ * @internal
32
+ */
33
+ export interface RoutingContextOptions {
34
+ router: Router;
35
+ defaultLocale: string;
36
+ getLocale: () => string;
37
+ getLocales: () => LocaleObject[];
38
+ getBaseUrl: (locale?: string) => string;
39
+ /** Host of the current request/page, used for domain-based behavior */
40
+ getHost: () => string | undefined;
41
+ /**
42
+ * Returns the `switchLocalePath` payload when it takes precedence over route
43
+ * meta (strict SEO client-side hydration), a falsy value otherwise.
44
+ */
45
+ getLocalePathPayload?: () => Record<string, Record<string, string> | false> | false | undefined;
46
+ }
47
+ export declare const isRouteLocationPathRaw: (val: RouteLike) => val is RouteLocationPathRaw;
48
+ export declare function createRoutingContext(options: RoutingContextOptions): RoutingContext;
@@ -0,0 +1,104 @@
1
+ import { joinURL } from "ufo";
2
+ import { createLocaleRouteNameGetter, createLocalizedRouteByPathResolver } from "./utils.js";
3
+ import { formatTrailingSlash, getLocaleFromRoutePath, getRouteBaseName, prefixable } from "#i18n-kit/routing";
4
+ import { getDefaultLocaleForDomain, isSupportedLocale } from "../shared/locales.js";
5
+ export const isRouteLocationPathRaw = (val) => !!val.path && !val.name;
6
+ export function createRoutingContext(options) {
7
+ const { router, defaultLocale } = options;
8
+ const getLocalizedRouteName = createLocaleRouteNameGetter(defaultLocale);
9
+ function resolveLocalizedRouteByName(route, locale) {
10
+ route.name = getRouteBaseName(route.name || router.currentRoute.value);
11
+ const localizedName = getLocalizedRouteName(route.name, locale);
12
+ if (router.hasRoute(localizedName)) {
13
+ route.name = localizedName;
14
+ if (__I18N_COMPACT_ROUTES__ && route.params) {
15
+ delete route.params.locale;
16
+ }
17
+ } else if (__I18N_COMPACT_ROUTES__ && isSupportedLocale(locale) && getCompactRouteNames().has(route.name)) {
18
+ route.params = { ...route.params || {}, locale };
19
+ return route;
20
+ }
21
+ route.name = localizedName;
22
+ return route;
23
+ }
24
+ const routeByPathResolver = createLocalizedRouteByPathResolver(router);
25
+ let compactRouteRecords;
26
+ function getCompactRouteNames() {
27
+ if (compactRouteRecords) {
28
+ return compactRouteRecords;
29
+ }
30
+ compactRouteRecords = /* @__PURE__ */ new Set();
31
+ if (__I18N_COMPACT_ROUTES__) {
32
+ for (const r of router.getRoutes()) {
33
+ if (r.name != null && /^\/:locale\(/.test(r.path)) {
34
+ compactRouteRecords.add(String(r.name));
35
+ }
36
+ }
37
+ }
38
+ return compactRouteRecords;
39
+ }
40
+ function resolveLocalizedRouteByPath(input, locale) {
41
+ const route = routeByPathResolver(input, locale);
42
+ const baseName = getRouteBaseName(route);
43
+ if (baseName) {
44
+ const localizedName = getLocalizedRouteName(baseName, locale);
45
+ if (router.hasRoute(localizedName)) {
46
+ route.name = localizedName;
47
+ const named = route;
48
+ if (__I18N_COMPACT_ROUTES__ && named.params) {
49
+ delete named.params.locale;
50
+ }
51
+ return route;
52
+ }
53
+ if (__I18N_COMPACT_ROUTES__ && getCompactRouteNames().has(baseName)) {
54
+ const compacted = route;
55
+ compacted.name = baseName;
56
+ compacted.params = { ...compacted.params || {}, locale };
57
+ return compacted;
58
+ }
59
+ route.name = localizedName;
60
+ return route;
61
+ }
62
+ if (prefixable(locale, defaultLocale)) {
63
+ route.path = "/" + locale + route.path;
64
+ }
65
+ route.path = formatTrailingSlash(route.path, true);
66
+ return route;
67
+ }
68
+ const getRouteLocalizedParams = () => router.currentRoute.value.meta[__DYNAMIC_PARAMS_KEY__] ?? {};
69
+ return {
70
+ router,
71
+ getLocale: options.getLocale,
72
+ getLocales: options.getLocales,
73
+ getBaseUrl: options.getBaseUrl,
74
+ getRouteBaseName,
75
+ getRouteLocalizedParams,
76
+ getLocalizedDynamicParams: (locale) => {
77
+ const payload = options.getLocalePathPayload?.();
78
+ if (payload) {
79
+ return payload[locale] || {};
80
+ }
81
+ return getRouteLocalizedParams()?.[locale];
82
+ },
83
+ afterSwitchLocalePath: (path, locale) => {
84
+ const params = getRouteLocalizedParams();
85
+ if (__I18N_STRICT_SEO__ && locale && Object.keys(params).length && !params[locale]) {
86
+ return "";
87
+ }
88
+ if (__MULTI_DOMAIN_LOCALES__ && __I18N_STRATEGY__ === "prefix_except_default") {
89
+ const domainDefaultLocale = getDefaultLocaleForDomain(options.getHost() ?? "");
90
+ if (locale !== domainDefaultLocale || getLocaleFromRoutePath(path) !== domainDefaultLocale) {
91
+ return path;
92
+ }
93
+ return path.slice(locale.length + 1);
94
+ }
95
+ if (__DIFFERENT_DOMAINS__) {
96
+ return joinURL(options.getBaseUrl(locale), path);
97
+ }
98
+ return path;
99
+ },
100
+ resolveLocalizedRouteObject: (route, locale) => {
101
+ return isRouteLocationPathRaw(route) ? resolveLocalizedRouteByPath(route, locale) : resolveLocalizedRouteByName(route, locale);
102
+ }
103
+ };
104
+ }
@@ -1,7 +1,7 @@
1
1
  import type { Locale } from 'vue-i18n';
2
2
  import type { RouteLocationNamedRaw, RouteLocationPathRaw, RouteLocationRaw } from 'vue-router';
3
3
  import type { CompatRoute } from '../types.js';
4
- import type { ComposableContext } from '../composable-context.js';
4
+ import type { RoutingContext } from './context.js';
5
5
  export type RouteLikeWithPath = RouteLocationPathRaw & {
6
6
  name?: string;
7
7
  };
@@ -12,12 +12,12 @@ export type RouteLike = RouteLikeWithPath | RouteLikeWithName;
12
12
  /**
13
13
  * Resolves a localized path of the passed in route.
14
14
  */
15
- export declare function localePath(ctx: ComposableContext, route: RouteLocationRaw, locale?: Locale): string;
15
+ export declare function localePath(ctx: RoutingContext, route: RouteLocationRaw, locale?: Locale): string;
16
16
  /**
17
17
  * Resolves a localized variant of the passed route.
18
18
  */
19
- export declare function localeRoute(ctx: ComposableContext, route: RouteLocationRaw, locale?: Locale): import("vue-router").RouteLocationResolvedGeneric | undefined;
19
+ export declare function localeRoute(ctx: RoutingContext, route: RouteLocationRaw, locale?: Locale): import("vue-router").RouteLocationResolvedGeneric | undefined;
20
20
  /**
21
21
  * Resolve the localized path of the current route.
22
22
  */
23
- export declare function switchLocalePath(ctx: ComposableContext, locale: Locale, route?: CompatRoute): string;
23
+ export declare function switchLocalePath(ctx: RoutingContext, locale: Locale, route?: CompatRoute): string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nuxtjs/i18n-edge",
3
3
  "type": "module",
4
- "version": "10.4.1-29732659.cb28c19",
4
+ "version": "10.4.1-29734085.45d4b0e",
5
5
  "description": "Internationalization for Nuxt",
6
6
  "contributors": [
7
7
  {
@@ -51,10 +51,10 @@
51
51
  "@nuxtjs/i18n": "workspace:*"
52
52
  },
53
53
  "dependencies": {
54
- "@intlify/core": "^11.4.0",
54
+ "@intlify/core": "^11.4.6",
55
55
  "@intlify/h3": "^0.7.4",
56
- "@intlify/shared": "^11.4.0",
57
- "@intlify/unplugin-vue-i18n": "^11.1.2",
56
+ "@intlify/shared": "^11.4.6",
57
+ "@intlify/unplugin-vue-i18n": "^11.2.4",
58
58
  "@intlify/utils": "^0.14.1",
59
59
  "@miyaneee/rollup-plugin-json5": "^1.2.0",
60
60
  "@nuxt/kit": "^4.4.8",
@@ -75,7 +75,7 @@
75
75
  "unplugin": "^3.0.0",
76
76
  "unrouting": "^0.1.5",
77
77
  "unstorage": "^1.16.1",
78
- "vue-i18n": "^11.4.0",
78
+ "vue-i18n": "^11.4.6",
79
79
  "vue-router": "^5.1.0"
80
80
  },
81
81
  "devDependencies": {