nuxt-i18n-micro 3.18.2 → 3.19.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.
Files changed (39) hide show
  1. package/dist/client/200.html +1 -1
  2. package/dist/client/404.html +1 -1
  3. package/dist/client/_nuxt/builds/latest.json +1 -1
  4. package/dist/client/_nuxt/builds/meta/bbe443af-4371-4ec3-b41c-7a5e9deb9b9b.json +1 -0
  5. package/dist/client/index.html +1 -1
  6. package/dist/module.d.mts +1 -0
  7. package/dist/module.json +1 -1
  8. package/dist/module.mjs +57 -149
  9. package/dist/runtime/composables/useI18nLocale.js +3 -3
  10. package/dist/runtime/composables/useLocaleHead.js +1 -1
  11. package/dist/runtime/plugins/01.plugin.js +6 -3
  12. package/dist/runtime/plugins/02.meta.js +2 -2
  13. package/dist/runtime/plugins/05.hooks.js +1 -1
  14. package/dist/runtime/plugins/06.redirect.js +14 -36
  15. package/dist/runtime/server/middleware/i18n.global.js +17 -35
  16. package/dist/runtime/server/plugins/watcher.dev.js +36 -66
  17. package/dist/runtime/server/routes/i18n.js +2 -2
  18. package/dist/runtime/server/utils/locale-detector.js +11 -1
  19. package/dist/runtime/server/utils/locale-server-middleware.js +2 -2
  20. package/dist/runtime/server/utils/server-loader.d.ts +3 -3
  21. package/dist/runtime/server/utils/server-loader.js +32 -8
  22. package/dist/runtime/server/utils/translation-server-middleware.js +2 -2
  23. package/dist/runtime/utils/storage.d.ts +4 -6
  24. package/dist/runtime/utils/storage.js +20 -11
  25. package/dist/types.d.mts +2 -0
  26. package/package.json +11 -8
  27. package/dist/client/_nuxt/builds/meta/a653a17d-86f7-440a-a09c-9871b01bc761.json +0 -1
  28. package/dist/runtime/utils/active-locales.d.ts +0 -4
  29. package/dist/runtime/utils/active-locales.js +0 -9
  30. package/dist/runtime/utils/cache-control.d.ts +0 -50
  31. package/dist/runtime/utils/cache-control.js +0 -88
  32. package/dist/runtime/utils/cookie.d.ts +0 -24
  33. package/dist/runtime/utils/cookie.js +0 -22
  34. package/dist/runtime/utils/deep-merge.d.ts +0 -15
  35. package/dist/runtime/utils/deep-merge.js +0 -14
  36. package/dist/runtime/utils/route-utils.d.ts +0 -33
  37. package/dist/runtime/utils/route-utils.js +0 -63
  38. package/dist/runtime/utils/runtime-i18n-config.d.ts +0 -8
  39. package/dist/runtime/utils/runtime-i18n-config.js +0 -90
@@ -1,33 +0,0 @@
1
- import type { RouteLocationNormalizedLoaded } from 'vue-router';
2
- /**
3
- * Extracts the base route pattern from a matched route path
4
- * Converts Vue Router dynamic route patterns to file-based route patterns
5
- *
6
- * @param matchedPath - The matched route path from route.matched[0].path
7
- * @returns The base route pattern (e.g., "/test/[param]")
8
- *
9
- * @example
10
- * extractBaseRoutePattern('/:locale(es)/test/:param()') // Returns '/test/[param]'
11
- * extractBaseRoutePattern('/:locale(en)/static') // Returns '/static'
12
- * extractBaseRoutePattern('/:locale(fr)/about/:id') // Returns '/about/[id]'
13
- */
14
- export declare function extractBaseRoutePattern(matchedPath: string): string;
15
- /**
16
- * Finds allowed locales for a route using various matching strategies
17
- *
18
- * @param route - The route object
19
- * @param routeLocales - The routeLocales configuration object
20
- * @param localizedRouteNamePrefix - Prefix for localized route names
21
- * @param localeCodes - Optional list of locale codes; when provided, path like /es/test is also looked up as routeLocales['test']/['/test']
22
- * @returns Array of allowed locale codes or null if no restrictions
23
- */
24
- export declare function findAllowedLocalesForRoute(route: RouteLocationNormalizedLoaded, routeLocales: Record<string, string[]> | undefined, localizedRouteNamePrefix?: string, localeCodes?: string[]): string[] | null;
25
- /**
26
- * Checks if meta tags should be disabled for a route
27
- *
28
- * @param route - The route object
29
- * @param routeDisableMeta - The routeDisableMeta configuration object
30
- * @param currentLocale - The current locale code
31
- * @returns True if meta tags should be disabled, false otherwise
32
- */
33
- export declare function isMetaDisabledForRoute(route: RouteLocationNormalizedLoaded, routeDisableMeta: Record<string, boolean | string[]> | undefined, currentLocale?: string, localizedRouteNamePrefix?: string): boolean;
@@ -1,63 +0,0 @@
1
- export function extractBaseRoutePattern(matchedPath) {
2
- return matchedPath.replace(/\/:locale\([^)]+\)/g, "").replace(/\/:([^()]+)\(\)/g, "/[$1]").replace(/\/:([^()]+)/g, "/[$1]");
3
- }
4
- export function findAllowedLocalesForRoute(route, routeLocales, localizedRouteNamePrefix = "localized-", localeCodes) {
5
- const routePath = route.path;
6
- const routeName = route.name?.toString();
7
- const normalizedRouteName = routeName?.replace(localizedRouteNamePrefix, "");
8
- const normalizedRoutePath = normalizedRouteName ? `/${normalizedRouteName}` : void 0;
9
- let allowedLocales = routeName && routeLocales?.[routeName] || normalizedRouteName && routeLocales?.[normalizedRouteName] || normalizedRoutePath && routeLocales?.[normalizedRoutePath] || normalizedRoutePath && routeLocales?.[normalizedRoutePath.replace(/^\//, "")] || routeLocales?.[routePath] || routePath && routeLocales?.[routePath.replace(/^\//, "")];
10
- if (!allowedLocales && routeLocales && localeCodes?.length) {
11
- const segments = routePath.split("/").filter(Boolean);
12
- const first = segments[0];
13
- if (first && localeCodes.includes(first) && segments.length > 1) {
14
- const pathWithoutLocale = `/${segments.slice(1).join("/")}`;
15
- const pathKey = pathWithoutLocale === "/" ? "/" : pathWithoutLocale.replace(/^\//, "");
16
- allowedLocales = routeLocales[pathWithoutLocale] ?? routeLocales[pathKey] ?? void 0;
17
- }
18
- }
19
- if (!allowedLocales && route.matched && route.matched.length > 0) {
20
- const matchedRoute = route.matched[0];
21
- if (!matchedRoute) return null;
22
- const matchedPath = matchedRoute.path;
23
- const baseRoutePattern = extractBaseRoutePattern(matchedPath);
24
- if (routeLocales?.[baseRoutePattern]) {
25
- allowedLocales = routeLocales[baseRoutePattern];
26
- }
27
- }
28
- return allowedLocales || null;
29
- }
30
- export function isMetaDisabledForRoute(route, routeDisableMeta, currentLocale, localizedRouteNamePrefix = "localized-") {
31
- if (!routeDisableMeta) {
32
- return false;
33
- }
34
- const routePath = route.path;
35
- const routeName = route.name?.toString();
36
- const normalizedRouteName = routeName?.replace(localizedRouteNamePrefix, "");
37
- const normalizedRoutePath = normalizedRouteName ? `/${normalizedRouteName}` : void 0;
38
- const checkDisableMeta = (disableMetaValue) => {
39
- if (disableMetaValue === void 0) {
40
- return false;
41
- }
42
- if (typeof disableMetaValue === "boolean") {
43
- return disableMetaValue;
44
- }
45
- if (Array.isArray(disableMetaValue)) {
46
- return currentLocale ? disableMetaValue.includes(currentLocale) : false;
47
- }
48
- return false;
49
- };
50
- if (checkDisableMeta(routeDisableMeta[routePath]) || routeName && checkDisableMeta(routeDisableMeta[routeName]) || normalizedRouteName && checkDisableMeta(routeDisableMeta[normalizedRouteName]) || normalizedRoutePath && checkDisableMeta(routeDisableMeta[normalizedRoutePath])) {
51
- return true;
52
- }
53
- if (route.matched && route.matched.length > 0) {
54
- const matchedRoute = route.matched[0];
55
- if (!matchedRoute) return false;
56
- const matchedPath = matchedRoute.path;
57
- const baseRoutePattern = extractBaseRoutePattern(matchedPath);
58
- if (checkDisableMeta(routeDisableMeta[baseRoutePattern])) {
59
- return true;
60
- }
61
- }
62
- return false;
63
- }
@@ -1,8 +0,0 @@
1
- import type { ModuleOptionsExtend } from '@i18n-micro/types';
2
- export interface RuntimeI18nOverrides {
3
- defaultLocale?: string;
4
- fallbackLocale?: string;
5
- disabledLocales?: string[];
6
- strategy?: string;
7
- }
8
- export declare function resolveI18nConfigWithRuntimeOverrides(baseConfig: ModuleOptionsExtend, runtimePublic?: Record<string, unknown>, warn?: (message: string) => void): ModuleOptionsExtend;
@@ -1,90 +0,0 @@
1
- function toNonEmptyString(value) {
2
- if (typeof value !== "string") return void 0;
3
- const normalized = value.trim();
4
- return normalized.length > 0 ? normalized : void 0;
5
- }
6
- function parseLocalesList(value) {
7
- if (Array.isArray(value)) {
8
- const items = value.map((entry) => toNonEmptyString(entry)).filter((entry) => Boolean(entry));
9
- return items.length > 0 ? items : void 0;
10
- }
11
- if (typeof value === "string") {
12
- const items = value.split(",").map((entry) => entry.trim()).filter((entry) => entry.length > 0);
13
- return items.length > 0 ? items : void 0;
14
- }
15
- return void 0;
16
- }
17
- function readEnvOverrides() {
18
- return {
19
- defaultLocale: toNonEmptyString(process.env.NUXT_I18N_DEFAULT_LOCALE) ?? toNonEmptyString(process.env.NUXT_PUBLIC_I18N_RUNTIME_DEFAULT_LOCALE),
20
- fallbackLocale: toNonEmptyString(process.env.NUXT_I18N_FALLBACK_LOCALE) ?? toNonEmptyString(process.env.NUXT_PUBLIC_I18N_RUNTIME_FALLBACK_LOCALE),
21
- disabledLocales: parseLocalesList(process.env.NUXT_I18N_DISABLED_LOCALES) ?? parseLocalesList(process.env.NUXT_PUBLIC_I18N_RUNTIME_DISABLED_LOCALES),
22
- strategy: toNonEmptyString(process.env.NUXT_I18N_STRATEGY) ?? toNonEmptyString(process.env.NUXT_PUBLIC_I18N_RUNTIME_STRATEGY)
23
- };
24
- }
25
- function readRuntimeOverrides(runtimePublic) {
26
- const raw = runtimePublic?.i18nRuntime;
27
- if (!raw || typeof raw !== "object") return {};
28
- const runtime = raw;
29
- return {
30
- defaultLocale: toNonEmptyString(runtime.defaultLocale),
31
- fallbackLocale: toNonEmptyString(runtime.fallbackLocale),
32
- disabledLocales: parseLocalesList(runtime.disabledLocales),
33
- strategy: toNonEmptyString(runtime.strategy)
34
- };
35
- }
36
- function mergeOverrides(runtimePublic) {
37
- const env = readEnvOverrides();
38
- const runtime = readRuntimeOverrides(runtimePublic);
39
- return {
40
- defaultLocale: runtime.defaultLocale ?? env.defaultLocale,
41
- fallbackLocale: runtime.fallbackLocale ?? env.fallbackLocale,
42
- disabledLocales: runtime.disabledLocales ?? env.disabledLocales,
43
- strategy: runtime.strategy ?? env.strategy
44
- };
45
- }
46
- export function resolveI18nConfigWithRuntimeOverrides(baseConfig, runtimePublic, warn = (message) => console.warn(message)) {
47
- const overrides = mergeOverrides(runtimePublic);
48
- const locales = (baseConfig.locales ?? []).map((locale) => ({ ...locale }));
49
- if (overrides.strategy && overrides.strategy !== baseConfig.strategy) {
50
- warn(
51
- `[nuxt-i18n-micro] runtime i18n strategy override is ignored: "${overrides.strategy}" (build strategy: "${baseConfig.strategy}"). Build a separate artifact for each strategy.`
52
- );
53
- }
54
- if (overrides.disabledLocales && overrides.disabledLocales.length > 0) {
55
- const disabledSet = new Set(overrides.disabledLocales);
56
- for (const locale of locales) {
57
- locale.disabled = disabledSet.has(locale.code);
58
- }
59
- }
60
- const enabledLocales = locales.filter((locale) => !locale.disabled);
61
- if (enabledLocales.length === 0) {
62
- if (overrides.disabledLocales && overrides.disabledLocales.length > 0) {
63
- warn("[nuxt-i18n-micro] runtime disabledLocales override would disable all locales; override ignored.");
64
- }
65
- return { ...baseConfig, locales: (baseConfig.locales ?? []).map((locale) => ({ ...locale })) };
66
- }
67
- const allLocaleCodes = new Set(locales.map((locale) => locale.code));
68
- let defaultLocale = overrides.defaultLocale ?? baseConfig.defaultLocale;
69
- let fallbackLocale = overrides.fallbackLocale ?? baseConfig.fallbackLocale;
70
- if (fallbackLocale && !allLocaleCodes.has(fallbackLocale)) {
71
- warn(`[nuxt-i18n-micro] runtime fallbackLocale "${fallbackLocale}" is not defined in locales; override ignored.`);
72
- fallbackLocale = baseConfig.fallbackLocale;
73
- }
74
- const enabledLocaleCodes = new Set(enabledLocales.map((locale) => locale.code));
75
- const firstEnabledLocale = enabledLocales[0]?.code ?? baseConfig.defaultLocale ?? "en";
76
- if (!defaultLocale || !enabledLocaleCodes.has(defaultLocale)) {
77
- if (overrides.defaultLocale) {
78
- warn(`[nuxt-i18n-micro] runtime defaultLocale "${overrides.defaultLocale}" is not enabled; falling back to "${firstEnabledLocale}".`);
79
- } else if (defaultLocale && !enabledLocaleCodes.has(defaultLocale)) {
80
- warn(`[nuxt-i18n-micro] defaultLocale "${defaultLocale}" is disabled by runtime overrides; falling back to "${firstEnabledLocale}".`);
81
- }
82
- defaultLocale = firstEnabledLocale;
83
- }
84
- return {
85
- ...baseConfig,
86
- locales,
87
- defaultLocale,
88
- fallbackLocale
89
- };
90
- }