@i18n-micro/route-strategy 1.1.30 → 2.0.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.
@@ -0,0 +1,32 @@
1
+ /** `a//b/` -> `a/b`; `''` and `.` -> `''`. */
2
+ export declare function normalizePath(routePath: string): string;
3
+ export declare const removeLeadingSlash: (routePath: string) => string;
4
+ /** Absolute form of a path: `about` -> `/about`, `` -> `/`. */
5
+ export declare const absolute: (routePath: string) => string;
6
+ /** Full path of a child route: an absolute child path stands alone, a relative one is joined. */
7
+ export declare function joinChild(parentFullPath: string, childPath: string): string;
8
+ /**
9
+ * File-path and Nuxt forms of a route path to the vue-router form rules are keyed and written in:
10
+ * `[...slug]` -> `:slug(.*)*`, `[[page]]` -> `:page?`, `[id]` -> `:id`, `:id()` -> `:id`
11
+ * (non-empty matchers such as `:id(\d+)` stay).
12
+ */
13
+ export declare function normalizeRouteKey(key: string): string;
14
+ /** Lookup key of a route path or name: normalized, without the leading slash (`/` for the root). */
15
+ export declare function routeKey(routePathOrName: string): string;
16
+ /**
17
+ * Route path segment of a child from its custom value, relative to the parent's localized path.
18
+ * A relative value is kept as written. An absolute value is a full URL: when it starts with the
19
+ * parent's localized path the rest is the segment (`/konto/bestellungen` under `/konto`), the
20
+ * parent path itself is the empty segment, and any other value keeps what follows the segments it
21
+ * shares with the parent (`/bereich/artikel` under `/bereich/kategorie` is `artikel`).
22
+ */
23
+ export declare function childSegment(parentLocalizedPath: string, customValue: string): string;
24
+ /**
25
+ * A page path as a route rule pattern: `/artikel/:id(\\d+)` -> `/artikel/:id`, `/a/:rest(.*)*` ->
26
+ * `/a/**`. Null when it starts with a param: `/:slug` would match every URL of that depth.
27
+ */
28
+ export declare function rulePattern(routePath: string): string | null;
29
+ /** Whether a child's custom value is its URL: an absolute value elsewhere is nested under the parent anyway. */
30
+ export declare function staysUnderParent(parentLocalizedPath: string, customValue: string): boolean;
31
+ /** Percent-encoded variant of a path with such static segments (vue-router matches either). */
32
+ export declare function encodedVariant(routePath: string): string | undefined;
@@ -0,0 +1,32 @@
1
+ /** `a//b/` -> `a/b`; `''` and `.` -> `''`. */
2
+ export declare function normalizePath(routePath: string): string;
3
+ export declare const removeLeadingSlash: (routePath: string) => string;
4
+ /** Absolute form of a path: `about` -> `/about`, `` -> `/`. */
5
+ export declare const absolute: (routePath: string) => string;
6
+ /** Full path of a child route: an absolute child path stands alone, a relative one is joined. */
7
+ export declare function joinChild(parentFullPath: string, childPath: string): string;
8
+ /**
9
+ * File-path and Nuxt forms of a route path to the vue-router form rules are keyed and written in:
10
+ * `[...slug]` -> `:slug(.*)*`, `[[page]]` -> `:page?`, `[id]` -> `:id`, `:id()` -> `:id`
11
+ * (non-empty matchers such as `:id(\d+)` stay).
12
+ */
13
+ export declare function normalizeRouteKey(key: string): string;
14
+ /** Lookup key of a route path or name: normalized, without the leading slash (`/` for the root). */
15
+ export declare function routeKey(routePathOrName: string): string;
16
+ /**
17
+ * Route path segment of a child from its custom value, relative to the parent's localized path.
18
+ * A relative value is kept as written. An absolute value is a full URL: when it starts with the
19
+ * parent's localized path the rest is the segment (`/konto/bestellungen` under `/konto`), the
20
+ * parent path itself is the empty segment, and any other value keeps what follows the segments it
21
+ * shares with the parent (`/bereich/artikel` under `/bereich/kategorie` is `artikel`).
22
+ */
23
+ export declare function childSegment(parentLocalizedPath: string, customValue: string): string;
24
+ /**
25
+ * A page path as a route rule pattern: `/artikel/:id(\\d+)` -> `/artikel/:id`, `/a/:rest(.*)*` ->
26
+ * `/a/**`. Null when it starts with a param: `/:slug` would match every URL of that depth.
27
+ */
28
+ export declare function rulePattern(routePath: string): string | null;
29
+ /** Whether a child's custom value is its URL: an absolute value elsewhere is nested under the parent anyway. */
30
+ export declare function staysUnderParent(parentLocalizedPath: string, customValue: string): boolean;
31
+ /** Percent-encoded variant of a path with such static segments (vue-router matches either). */
32
+ export declare function encodedVariant(routePath: string): string | undefined;
@@ -0,0 +1,58 @@
1
+ import { GlobalLocaleRoutes, Locale, Strategies } from '@i18n-micro/types';
2
+ import { NuxtPage } from '@nuxt/schema';
3
+ export interface RouteGeneratorOptions {
4
+ locales: Locale[];
5
+ defaultLocaleCode: string;
6
+ strategy: Strategies;
7
+ /** Custom paths by page path or route name, `$defineI18nRoute` ones merged in (config wins). */
8
+ globalLocaleRoutes: GlobalLocaleRoutes;
9
+ routeLocales?: Record<string, string[]>;
10
+ /** `$defineI18nRoute({ disableMeta })` by page path: baked into `meta.i18n.noMeta`. */
11
+ routeDisableMeta?: Record<string, boolean | string[]>;
12
+ noPrefixRedirect: boolean;
13
+ /** `redirects: false` of the module: no redirect records. */
14
+ redirects?: boolean;
15
+ excludePatterns?: (string | RegExp)[];
16
+ /** The translations route (`_locales` by default): pages under it stay unlocalized. */
17
+ apiBaseUrl?: string;
18
+ localizedRouteNamePrefix?: string;
19
+ customRegexMatcher?: string | RegExp;
20
+ /** Paths of the pages that nest others (`blog.vue` next to `blog/`): a relative custom value of a child hangs off them. */
21
+ parentPaths?: string[];
22
+ }
23
+ export declare class RouteGenerator {
24
+ readonly locales: Locale[];
25
+ /** Locales switched off in the config: no routes, but the runtime must know them to answer 404. */
26
+ readonly disabledLocales: Locale[];
27
+ readonly defaultLocale: Locale;
28
+ readonly strategy: Strategies;
29
+ readonly routeLocales: Record<string, string[]>;
30
+ /** Defaults of the domains in this build, besides the build default. */
31
+ private readonly hostDefaults;
32
+ private readonly rules;
33
+ private readonly options;
34
+ private readonly parentKeys;
35
+ /** Localized paths of the pages seen by the last extendPages call. */
36
+ private localizedPaths;
37
+ constructor(options: RouteGeneratorOptions);
38
+ /** Replaces `pages` (in place, as Nuxt's `pages:resolved` hook expects) with the localized routes. */
39
+ extendPages(pages: NuxtPage[]): void;
40
+ /**
41
+ * URL of a page path in a locale (custom path and prefix applied), for nitro routeRules and
42
+ * prerender: `/about` + `de` -> `/de/ueber-uns`. Paths the pages do not have (wildcards, API
43
+ * routes) only get the prefix.
44
+ */
45
+ resolveLocalizedPath(originalPath: string, localeCode: string): string;
46
+ private withPrefix;
47
+ /** A page's path in a locale without its page tree (nitro config runs first), composed as generate.ts composes it. */
48
+ private localizedKey;
49
+ /**
50
+ * Every URL pattern a route rule covers in a locale. A wildcard (`/blog/**`) also reaches the
51
+ * pages under it that moved to a custom path, and only those: `/de/artikel/:slug` for `/artikel/[slug]`.
52
+ */
53
+ resolveLocalizedRulePaths(originalPath: string, localeCode: string): string[];
54
+ /** Creates the global and per-page translation JSON files that do not exist yet. */
55
+ ensureTranslationFilesExist(pagesNames: string[], translationDir: string, rootDir: string, disablePageLocales?: boolean): void;
56
+ /** data.json routes to prerender: index per locale, plus one per named page unless disablePageLocales. */
57
+ generateDataRoutes(pages: NuxtPage[], apiBaseUrl: string, disablePageLocales: boolean): string[];
58
+ }
@@ -1,59 +1,58 @@
1
1
  import { GlobalLocaleRoutes, Locale, Strategies } from '@i18n-micro/types';
2
2
  import { NuxtPage } from '@nuxt/schema';
3
- import { LocalizedPathsMap } from './core/localized-paths';
4
- import { LocaleRoutesConfig } from './strategies/types';
5
3
  export interface RouteGeneratorOptions {
6
4
  locales: Locale[];
7
5
  defaultLocaleCode: string;
8
6
  strategy: Strategies;
7
+ /** Custom paths by page path or route name, `$defineI18nRoute` ones merged in (config wins). */
9
8
  globalLocaleRoutes: GlobalLocaleRoutes;
10
- filesLocaleRoutes?: GlobalLocaleRoutes;
11
9
  routeLocales?: Record<string, string[]>;
10
+ /** `$defineI18nRoute({ disableMeta })` by page path: baked into `meta.i18n.noMeta`. */
11
+ routeDisableMeta?: Record<string, boolean | string[]>;
12
12
  noPrefixRedirect: boolean;
13
+ /** `redirects: false` of the module: no redirect records. */
14
+ redirects?: boolean;
13
15
  excludePatterns?: (string | RegExp)[];
16
+ /** The translations route (`_locales` by default): pages under it stay unlocalized. */
17
+ apiBaseUrl?: string;
14
18
  localizedRouteNamePrefix?: string;
15
19
  customRegexMatcher?: string | RegExp;
16
- fallbackRedirectComponentPath?: string;
20
+ /** Paths of the pages that nest others (`blog.vue` next to `blog/`): a relative custom value of a child hangs off them. */
21
+ parentPaths?: string[];
17
22
  }
18
23
  export declare class RouteGenerator {
19
- locales: Locale[];
20
- defaultLocale: Locale;
21
- strategy: Strategies;
22
- localizedPaths: LocalizedPathsMap;
23
- activeLocaleCodes: string[];
24
- globalLocaleRoutes: LocaleRoutesConfig;
25
- rawGlobalLocaleRoutes: GlobalLocaleRoutes;
26
- filesLocaleRoutes: LocaleRoutesConfig;
27
- routeLocales: Record<string, string[]>;
28
- noPrefixRedirect: boolean;
29
- excludePatterns: (string | RegExp)[] | undefined;
30
- localizedRouteNamePrefix: string;
31
- customRegex: string | RegExp | undefined;
32
- fallbackRedirectComponentPath: string | undefined;
24
+ readonly locales: Locale[];
25
+ /** Locales switched off in the config: no routes, but the runtime must know them to answer 404. */
26
+ readonly disabledLocales: Locale[];
27
+ readonly defaultLocale: Locale;
28
+ readonly strategy: Strategies;
29
+ readonly routeLocales: Record<string, string[]>;
30
+ /** Defaults of the domains in this build, besides the build default. */
31
+ private readonly hostDefaults;
32
+ private readonly rules;
33
+ private readonly options;
34
+ private readonly parentKeys;
35
+ /** Localized paths of the pages seen by the last extendPages call. */
36
+ private localizedPaths;
33
37
  constructor(options: RouteGeneratorOptions);
34
- private computeActiveLocaleCodes;
38
+ /** Replaces `pages` (in place, as Nuxt's `pages:resolved` hook expects) with the localized routes. */
35
39
  extendPages(pages: NuxtPage[]): void;
36
- extractLocalizedPaths(pages: NuxtPage[], parentPath?: string): {
37
- [key: string]: {
38
- [locale: string]: string;
39
- };
40
- };
41
40
  /**
42
- * Creates global and per-page translation JSON files for the current resolved locales.
43
- */
44
- ensureTranslationFilesExist(pagesNames: string[], translationDir: string, rootDir: string, disablePageLocales?: boolean): void;
45
- private ensureFileExists;
46
- /**
47
- * Returns the localized path for a given URL and locale,
48
- * respecting strategy and globalLocaleRoutes (custom paths).
49
- * Used by nitro:config and prerender so route rules work with custom paths (e.g. /de/ueber-uns).
41
+ * URL of a page path in a locale (custom path and prefix applied), for nitro routeRules and
42
+ * prerender: `/about` + `de` -> `/de/ueber-uns`. Paths the pages do not have (wildcards, API
43
+ * routes) only get the prefix.
50
44
  */
51
45
  resolveLocalizedPath(originalPath: string, localeCode: string): string;
46
+ private withPrefix;
47
+ /** A page's path in a locale without its page tree (nitro config runs first), composed as generate.ts composes it. */
48
+ private localizedKey;
52
49
  /**
53
- * Generates the list of data.json routes for prerender.
54
- * When disablePageLocales is true, only index routes are generated (all pages share root translations).
55
- * Otherwise, generates index + per-page routes for each locale.
50
+ * Every URL pattern a route rule covers in a locale. A wildcard (`/blog/**`) also reaches the
51
+ * pages under it that moved to a custom path, and only those: `/de/artikel/:slug` for `/artikel/[slug]`.
56
52
  */
53
+ resolveLocalizedRulePaths(originalPath: string, localeCode: string): string[];
54
+ /** Creates the global and per-page translation JSON files that do not exist yet. */
55
+ ensureTranslationFilesExist(pagesNames: string[], translationDir: string, rootDir: string, disablePageLocales?: boolean): void;
56
+ /** data.json routes to prerender: index per locale, plus one per named page unless disablePageLocales. */
57
57
  generateDataRoutes(pages: NuxtPage[], apiBaseUrl: string, disablePageLocales: boolean): string[];
58
- private collectPageNames;
59
58
  }
@@ -0,0 +1,35 @@
1
+ import { GlobalLocaleRoutes, Locale } from '@i18n-micro/types';
2
+ /** Custom paths of one page per locale, or `false` for a page that is not localized. */
3
+ export type Rule = Record<string, string> | false;
4
+ /** `true` (every locale) or the locales whose SEO tags are off. */
5
+ export type NoMeta = boolean | string[];
6
+ /**
7
+ * globalLocaleRoutes / $defineI18nRoute rules and routeLocales restrictions, keyed once by
8
+ * routeKey so `about/team` and `/about/team` are looked up the same way everywhere. A page is
9
+ * looked up by its full original path first (`about-team` / `/about-team` for a top-level page,
10
+ * the form without the slash winning), then by its route name, which only keys written without a
11
+ * leading slash can be.
12
+ */
13
+ export declare class Rules {
14
+ private readonly rules;
15
+ private readonly byName;
16
+ private readonly restrictions;
17
+ private readonly restrictionsByName;
18
+ private readonly noMeta;
19
+ private readonly noMetaByName;
20
+ constructor(globalLocaleRoutes?: GlobalLocaleRoutes, routeLocales?: Record<string, string[]>, locales?: Locale[], routeDisableMeta?: Record<string, NoMeta>);
21
+ get(fullPath: string, name: string | undefined): Rule | undefined;
22
+ /** Locales a page may be served in, or undefined when it is not restricted. */
23
+ allowedLocales(fullPath: string, name: string | undefined): string[] | undefined;
24
+ /** `$defineI18nRoute({ disableMeta })`: SEO tags off for the page (every locale, or the listed ones). */
25
+ disableMeta(fullPath: string, name: string | undefined): NoMeta | undefined;
26
+ /** Keys of the pages at or under `base` (a route key) with a custom path in `locale`: where a wildcard rule's pages live. */
27
+ customKeysUnder(base: string, locale: string): string[];
28
+ /** Custom path of a top-level path for a locale (nitro: prerender and routeRules). */
29
+ customPath(fullPath: string, locale: string): string | undefined;
30
+ }
31
+ /**
32
+ * Whether `localeCode` may serve this path given `$defineI18nRoute` locales / routeLocales.
33
+ * Unrestricted paths (and restrictions naming no known locale) allow every locale.
34
+ */
35
+ export declare function isLocaleAllowedForUnlocalizedRoute(routeLocales: Record<string, string[]>, locales: Locale[], routePath: string, localeCode: string): boolean;
@@ -0,0 +1,35 @@
1
+ import { GlobalLocaleRoutes, Locale } from '@i18n-micro/types';
2
+ /** Custom paths of one page per locale, or `false` for a page that is not localized. */
3
+ export type Rule = Record<string, string> | false;
4
+ /** `true` (every locale) or the locales whose SEO tags are off. */
5
+ export type NoMeta = boolean | string[];
6
+ /**
7
+ * globalLocaleRoutes / $defineI18nRoute rules and routeLocales restrictions, keyed once by
8
+ * routeKey so `about/team` and `/about/team` are looked up the same way everywhere. A page is
9
+ * looked up by its full original path first (`about-team` / `/about-team` for a top-level page,
10
+ * the form without the slash winning), then by its route name, which only keys written without a
11
+ * leading slash can be.
12
+ */
13
+ export declare class Rules {
14
+ private readonly rules;
15
+ private readonly byName;
16
+ private readonly restrictions;
17
+ private readonly restrictionsByName;
18
+ private readonly noMeta;
19
+ private readonly noMetaByName;
20
+ constructor(globalLocaleRoutes?: GlobalLocaleRoutes, routeLocales?: Record<string, string[]>, locales?: Locale[], routeDisableMeta?: Record<string, NoMeta>);
21
+ get(fullPath: string, name: string | undefined): Rule | undefined;
22
+ /** Locales a page may be served in, or undefined when it is not restricted. */
23
+ allowedLocales(fullPath: string, name: string | undefined): string[] | undefined;
24
+ /** `$defineI18nRoute({ disableMeta })`: SEO tags off for the page (every locale, or the listed ones). */
25
+ disableMeta(fullPath: string, name: string | undefined): NoMeta | undefined;
26
+ /** Keys of the pages at or under `base` (a route key) with a custom path in `locale`: where a wildcard rule's pages live. */
27
+ customKeysUnder(base: string, locale: string): string[];
28
+ /** Custom path of a top-level path for a locale (nitro: prerender and routeRules). */
29
+ customPath(fullPath: string, locale: string): string | undefined;
30
+ }
31
+ /**
32
+ * Whether `localeCode` may serve this path given `$defineI18nRoute` locales / routeLocales.
33
+ * Unrestricted paths (and restrictions naming no known locale) allow every locale.
34
+ */
35
+ export declare function isLocaleAllowedForUnlocalizedRoute(routeLocales: Record<string, string[]>, locales: Locale[], routePath: string, localeCode: string): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@i18n-micro/route-strategy",
3
- "version": "1.1.30",
3
+ "version": "2.0.1",
4
4
  "description": "Locale-aware route generator for Nuxt i18n micro",
5
5
  "keywords": [
6
6
  "i18n",
@@ -27,20 +27,13 @@
27
27
  },
28
28
  "files": [
29
29
  "dist",
30
- "LICENSE",
31
- "README.md"
30
+ "README.md",
31
+ "LICENSE"
32
32
  ],
33
33
  "type": "module",
34
34
  "sideEffects": false,
35
- "main": "dist/index.cjs",
36
- "types": "dist/index.d.ts",
37
- "typesVersions": {
38
- "*": {
39
- ".": [
40
- "./dist/index.d.ts"
41
- ]
42
- }
43
- },
35
+ "main": "./dist/index.cjs",
36
+ "types": "./dist/index.d.ts",
44
37
  "exports": {
45
38
  ".": {
46
39
  "production": {
@@ -62,19 +55,26 @@
62
55
  "access": "public"
63
56
  },
64
57
  "dependencies": {
65
- "@nuxt/schema": "^3.18.1 || ^4.5.2",
66
- "@i18n-micro/utils": "^1.0.27",
67
- "@i18n-micro/core": "^1.3.22",
68
- "@i18n-micro/types": "^1.2.18"
58
+ "@i18n-micro/utils": "^2.0.1",
59
+ "@i18n-micro/types": "^2.0.1"
69
60
  },
70
61
  "devDependencies": {
71
- "publint": "^0.3.24",
72
- "vite": "^8.3.1",
73
- "vite-plugin-dts": "^5.1.1",
74
- "vitest": "^5.0.2"
62
+ "@nuxt/schema": "^3.18.0 || ^4.0.0",
63
+ "publint": "^0.3.25",
64
+ "vite": "^8.3.5",
65
+ "vite-plugin-dts": "^5.1.2",
66
+ "vitest": "^5.1.0"
67
+ },
68
+ "peerDependencies": {
69
+ "@nuxt/schema": "^3.18.0 || ^4.0.0"
70
+ },
71
+ "peerDependenciesMeta": {
72
+ "@nuxt/schema": {
73
+ "optional": true
74
+ }
75
75
  },
76
76
  "engines": {
77
- "node": ">=18"
77
+ "node": ">=20"
78
78
  },
79
79
  "scripts": {
80
80
  "build": "vite build",
@@ -1,31 +0,0 @@
1
- import { NuxtPage } from '@nuxt/schema';
2
- /**
3
- * Joins parent path and child segment.
4
- * If childSegment is absolute (starts with `/`) — returns it (normalized).
5
- * Otherwise, performs join(parentPath, childSegment) with normalization.
6
- */
7
- export declare function resolveChildPath(parentPath: string, childSegment: string): string;
8
- /**
9
- * Route path segment of a child from its custom value. Child values are relative to the
10
- * parent (`book-activity/skiing` under `/activity`); a value that already starts with the
11
- * parent's localized path is a full URL and is taken from there (`/bereich/kategorie` under
12
- * `/bereich` is `kategorie`, `/bereich` itself is the parent's own path) — the same rule the
13
- * runtime applies (joinNestedCustomPath). A full URL that leaves the parent's path below a
14
- * shared ancestor cannot be nested; what follows the shared part is kept instead of
15
- * doubling it (`/bereich/artikel` under `/bereich/kategorie` is `artikel`). Only absolute
16
- * values can be full URLs: a relative value (`bereich/artikel`) is always kept as written.
17
- */
18
- export declare function childSegment(parentLocalizedPath: string, customValue: string): string;
19
- export interface CreateRouteOptions {
20
- path: string;
21
- name?: string;
22
- children?: NuxtPage[];
23
- meta?: Record<string, unknown>;
24
- /** When undefined, alias is cleared (for the main localized route when alias routes are created separately). */
25
- alias?: string[] | undefined;
26
- }
27
- /**
28
- * Creates a new NuxtPage object from the original page and provided options.
29
- * Copies meta, component, file, etc.; provided options override the respective fields.
30
- */
31
- export declare function createRoute(page: NuxtPage, options: CreateRouteOptions): NuxtPage;
@@ -1,53 +0,0 @@
1
- import { GlobalLocaleRoutes, Locale, Strategies } from '@i18n-micro/types';
2
- import { NuxtPage } from '@nuxt/schema';
3
- import { LocaleRoutesConfig } from '../strategies/types';
4
- import { LocalizedPathsMap } from './localized-paths';
5
- export interface GeneratorContextOptions {
6
- locales: Locale[];
7
- defaultLocaleCode: string;
8
- strategy: Strategies;
9
- globalLocaleRoutes: GlobalLocaleRoutes;
10
- filesLocaleRoutes: LocaleRoutesConfig;
11
- routeLocales: Record<string, string[]>;
12
- pages: NuxtPage[];
13
- excludePatterns?: (string | RegExp)[];
14
- customRegex?: string | RegExp;
15
- noPrefixRedirect?: boolean;
16
- localizedRouteNamePrefix?: string;
17
- /** Resolved path to the locale-redirect component for prefix strategy fallback route. */
18
- fallbackRedirectComponentPath?: string;
19
- /** Raw globalLocaleRoutes for fallback route meta (locale-redirect component). */
20
- rawGlobalLocaleRoutes?: GlobalLocaleRoutes;
21
- }
22
- export declare class GeneratorContext {
23
- readonly locales: Locale[];
24
- readonly defaultLocale: Locale;
25
- readonly strategy: Strategies;
26
- readonly globalLocaleRoutes: LocaleRoutesConfig;
27
- readonly filesLocaleRoutes: LocaleRoutesConfig;
28
- readonly routeLocales: Record<string, string[]>;
29
- readonly localizedPaths: LocalizedPathsMap;
30
- readonly activeLocaleCodes: string[];
31
- readonly excludePatterns: (string | RegExp)[] | undefined;
32
- readonly customRegex: string | RegExp | undefined;
33
- readonly noPrefixRedirect: boolean;
34
- readonly localizedRouteNamePrefix: string;
35
- readonly fallbackRedirectComponentPath: string | undefined;
36
- readonly rawGlobalLocaleRoutes: GlobalLocaleRoutes | undefined;
37
- constructor(options: GeneratorContextOptions);
38
- private findLocaleByCode;
39
- /**
40
- * Returns the list of locale codes allowed for a page (respecting routeLocales).
41
- */
42
- getAllowedLocales(pagePath: string, pageName: string): string[];
43
- /**
44
- * Returns a custom path for a given locale by original page path, if any.
45
- */
46
- getCustomPath(originalPath: string, localeCode: string): string | undefined;
47
- /**
48
- * Returns a map of custom paths (locale → path) for a page by path key or name.
49
- */
50
- getCustomPathsForPage(originalPath: string, pageName: string): Record<string, string> | undefined;
51
- hasLocaleRestrictions(pagePath: string, pageName: string): boolean;
52
- filterLocaleCodesWithoutCustomPaths(fullPath: string): string[];
53
- }
@@ -1,3 +0,0 @@
1
- import { LocaleRoutesConfig } from '../strategies/types';
2
- /** True when localization is disabled via `globalLocaleRoutes[key] === false`. */
3
- export declare function isLocalizationDisabledForPage(globalLocaleRoutes: LocaleRoutesConfig, originalPath: string, pageName: string): boolean;
@@ -1,20 +0,0 @@
1
- import { NuxtPage } from '@nuxt/schema';
2
- import { LocaleRoutesConfig } from '../strategies/types';
3
- export type LocalizedPathsMap = Record<string, Record<string, string>>;
4
- /**
5
- * Single key format for localizedPaths: without a leading slash so that it
6
- * matches:
7
- * - keys from the Nuxt module (routePath from page files),
8
- * - and lookups from strategies (resolveChildPath results).
9
- */
10
- export declare function pathKeyForLocalizedPaths(fullPath: string): string;
11
- /**
12
- * Extracts a map of custom paths (path key → locale → path) from:
13
- * - pages,
14
- * - globalLocaleRoutes,
15
- * - filesLocaleRoutes.
16
- *
17
- * Walks children recursively. Keys are stored without a leading slash for
18
- * compatibility with the Nuxt module and strategies.
19
- */
20
- export declare function extractLocalizedPaths(pages: NuxtPage[], globalLocaleRoutes: LocaleRoutesConfig, filesLocaleRoutes: LocaleRoutesConfig, parentPath?: string): LocalizedPathsMap;
@@ -1,6 +0,0 @@
1
- import { Locale } from '@i18n-micro/types';
2
- /**
3
- * Whether `localeCode` may serve this path given `$defineI18nRoute` / `routeLocales`.
4
- * When no restriction applies for the path, returns true for every locale (matches runtime path-strategy).
5
- */
6
- export declare function isLocaleAllowedForUnlocalizedRoute(routeLocales: Record<string, string[]>, locales: Locale[], unlocalizedPath: string, localeCode: string): boolean;
@@ -1,47 +0,0 @@
1
- import { NuxtPage } from '@nuxt/schema';
2
- import { GeneratorContext } from '../core/context';
3
- import { RouteStrategy } from './types';
4
- export declare abstract class BaseStrategy implements RouteStrategy {
5
- processPage(page: NuxtPage, context: GeneratorContext): NuxtPage[];
6
- postProcess(pages: NuxtPage[], _context: GeneratorContext): NuxtPage[];
7
- protected abstract generateVariants(page: NuxtPage, context: GeneratorContext): NuxtPage[];
8
- /**
9
- * Recursive localization for children: for a given locale, builds:
10
- * - parentOriginalPath used for Context lookups,
11
- * - parentLocalizedPath used for the final path,
12
- * and returns an array of localized child routes.
13
- */
14
- protected localizeChildren(children: NuxtPage[], parentLocalizedPath: string, parentOriginalPath: string, locale: string, context: GeneratorContext, addPrefix: boolean): NuxtPage[];
15
- /**
16
- * Variant for a single route with :locale(locale1|locale2) — without custom paths.
17
- * Returns a single child route with a relative path and recursively localized children.
18
- */
19
- protected localizeChildrenAllLocales(children: NuxtPage[], parentPath: string, parentOriginalPath: string, localeCodes: string[], context: GeneratorContext): NuxtPage[];
20
- private localizeChildAllLocales;
21
- private localizeChild;
22
- /** The page's declared aliases as a list: vue-router accepts a single string as well. */
23
- protected declaredAliases(page: NuxtPage): string[];
24
- /**
25
- * vue-router record aliases of a generated route: the page's own aliases (`alias` /
26
- * `definePageMeta({ alias })`) localized like the route path — under the route's `:locale(...)`
27
- * param (`localeCodes`), or as written for an unprefixed route (`null`) — plus percent-encoded
28
- * variants of non-ASCII paths. vue-router applies record aliases to the children and an alias
29
- * shares the record's name, so alias URLs follow the localized child tree and names stay
30
- * unique (separate alias routes duplicated both).
31
- */
32
- protected routeAliases(page: NuxtPage, routePath: string, localeCodes: string[] | null, context: GeneratorContext): string[];
33
- /**
34
- * Children of an unprefixed route with `locale`'s custom paths applied, keeping their own
35
- * names (the localized names belong to the prefixed variant). Unchanged when no descendant
36
- * has a custom path.
37
- */
38
- protected localizeChildPathsKeepNames(children: NuxtPage[], parentLocalizedPath: string, parentOriginalPath: string, locale: string, context: GeneratorContext): NuxtPage[];
39
- /**
40
- * Shared helper for strategies that build prefix-based paths (:locale(...)):
41
- * - for custom paths, decides whether a prefix is required,
42
- * - for regular paths, always uses buildFullPath.
43
- *
44
- * The logic matches what used to be duplicated in each strategy's buildRoutePath.
45
- */
46
- protected buildRoutePathForLocales(localeCodes: string[], originalPath: string, customPath: string, isCustom: boolean, customRegex: string | RegExp | undefined, force: boolean, defaultLocaleCode: string): string;
47
- }
@@ -1,3 +0,0 @@
1
- import { Strategies } from '@i18n-micro/types';
2
- import { RouteStrategy } from './types';
3
- export declare function getStrategy(name: Strategies): RouteStrategy;
@@ -1,13 +0,0 @@
1
- import { NuxtPage } from '@nuxt/schema';
2
- import { GeneratorContext } from '../core/context';
3
- import { BaseStrategy } from './abstract';
4
- export declare class NoPrefixStrategy extends BaseStrategy {
5
- protected generateVariants(page: NuxtPage, context: GeneratorContext): NuxtPage[];
6
- /** Whether a descendant has a custom path for `locale` that differs from its own path. */
7
- private hasChangedChildPath;
8
- /**
9
- * Localizes the children tree for the no_prefix strategy: custom paths
10
- * (globalLocaleRoutes/filesLocaleRoutes) apply at every level.
11
- */
12
- private localizeChildrenForNoPrefix;
13
- }
@@ -1,8 +0,0 @@
1
- import { NuxtPage } from '@nuxt/schema';
2
- import { GeneratorContext } from '../core/context';
3
- import { BaseStrategy } from './abstract';
4
- export declare class PrefixAndDefaultStrategy extends BaseStrategy {
5
- protected generateVariants(page: NuxtPage, context: GeneratorContext): NuxtPage[];
6
- postProcess(pages: NuxtPage[], context: GeneratorContext): NuxtPage[];
7
- private createLocalizedRoute;
8
- }
@@ -1,12 +0,0 @@
1
- import { NuxtPage } from '@nuxt/schema';
2
- import { GeneratorContext } from '../core/context';
3
- import { BaseStrategy } from './abstract';
4
- export declare class PrefixExceptDefaultStrategy extends BaseStrategy {
5
- protected generateVariants(page: NuxtPage, context: GeneratorContext): NuxtPage[];
6
- postProcess(pages: NuxtPage[], context: GeneratorContext): NuxtPage[];
7
- private createLocalizedChildren;
8
- private createLocalizedVariants;
9
- private buildChildRouteName;
10
- private createLocalizedRoute;
11
- private buildLocalizedRouteName;
12
- }
@@ -1,7 +0,0 @@
1
- import { NuxtPage } from '@nuxt/schema';
2
- import { GeneratorContext } from '../core/context';
3
- import { BaseStrategy } from './abstract';
4
- export declare class PrefixStrategy extends BaseStrategy {
5
- protected generateVariants(page: NuxtPage, context: GeneratorContext): NuxtPage[];
6
- postProcess(pages: NuxtPage[], context: GeneratorContext): NuxtPage[];
7
- }
@@ -1,17 +0,0 @@
1
- import { NuxtPage } from '@nuxt/schema';
2
- import { GeneratorContext } from '../core/context';
3
- export interface RouteStrategy {
4
- /**
5
- * Processes a page and returns an array of routes (base + aliases, etc.).
6
- */
7
- processPage(page: NuxtPage, context: GeneratorContext): NuxtPage[];
8
- /**
9
- * Post-processes the full pages array (e.g. removing unprefixed routes).
10
- */
11
- postProcess(pages: NuxtPage[], context: GeneratorContext): NuxtPage[];
12
- }
13
- /**
14
- * Shared type for global/files-level locale routes configuration.
15
- * Used in Context and RouteGenerator to avoid repeating the same signature.
16
- */
17
- export type LocaleRoutesConfig = Record<string, Record<string, string> | false | boolean>;
@@ -1,9 +0,0 @@
1
- import { Locale } from '@i18n-micro/types';
2
- import { NuxtPage } from '@nuxt/schema';
3
- export { isInternalPath } from '@i18n-micro/utils/app-path';
4
- export declare const cloneArray: <T extends object>(array: T[]) => T[];
5
- export declare const isPageRedirectOnly: (page: NuxtPage) => boolean;
6
- export declare const buildRouteName: (baseName: string, localeCode: string, isCustom: boolean, prefix?: string) => string;
7
- export declare const buildRouteNameFromRoute: (name: string | null | undefined, routePath: string | null | undefined) => string;
8
- export declare const shouldAddLocalePrefix: (locale: string, defaultLocale: Locale, addLocalePrefix: boolean) => boolean;
9
- export declare const isLocaleDefault: (locale: string | Locale, defaultLocale: Locale) => boolean;
@@ -1,3 +0,0 @@
1
- export { buildRouteName, buildRouteNameFromRoute, cloneArray, isInternalPath, isLocaleDefault, isPageRedirectOnly, shouldAddLocalePrefix, } from './common';
2
- export { type ResolvedLocales, resolveLocales } from './locales';
3
- export { buildEncodedPathAliases, buildFullPath, buildFullPathNoPrefix, joinPath, normalizePath, normalizeRouteKey, removeLeadingSlash } from './path';
@@ -1,3 +0,0 @@
1
- export { buildRouteName, buildRouteNameFromRoute, cloneArray, isInternalPath, isLocaleDefault, isPageRedirectOnly, shouldAddLocalePrefix, } from './common';
2
- export { type ResolvedLocales, resolveLocales } from './locales';
3
- export { buildEncodedPathAliases, buildFullPath, buildFullPathNoPrefix, joinPath, normalizePath, normalizeRouteKey, removeLeadingSlash } from './path';
@@ -1,9 +0,0 @@
1
- import { Locale } from '@i18n-micro/types';
2
- export interface ResolvedLocales {
3
- locales: Locale[];
4
- defaultLocale: Locale;
5
- }
6
- /**
7
- * Merges locale list (dedupe by code, merge props) and filters out disabled locales.
8
- */
9
- export declare function resolveLocales(locales: Locale[], defaultLocaleCode: string): ResolvedLocales;