@i18n-micro/route-strategy 1.1.29 → 2.0.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 +66 -190
- package/dist/generate.d.cts +33 -0
- package/dist/generate.d.ts +33 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +5 -6
- package/dist/index.d.ts +5 -6
- package/dist/index.mjs +403 -517
- package/dist/paths.d.cts +32 -0
- package/dist/paths.d.ts +32 -0
- package/dist/route-generator.d.cts +58 -0
- package/dist/route-generator.d.ts +35 -36
- package/dist/rules.d.cts +35 -0
- package/dist/rules.d.ts +35 -0
- package/package.json +21 -21
- package/dist/core/alias.d.ts +0 -6
- package/dist/core/builder.d.ts +0 -20
- package/dist/core/context.d.ts +0 -53
- package/dist/core/localization-disabled.d.ts +0 -3
- package/dist/core/localized-paths.d.ts +0 -20
- package/dist/locale-route-access.d.ts +0 -6
- package/dist/strategies/abstract.d.ts +0 -30
- package/dist/strategies/factory.d.ts +0 -3
- package/dist/strategies/no-prefix.d.ts +0 -13
- package/dist/strategies/prefix-and-default.d.ts +0 -8
- package/dist/strategies/prefix-except-default.d.ts +0 -12
- package/dist/strategies/prefix.d.ts +0 -7
- package/dist/strategies/types.d.ts +0 -17
- package/dist/utils/common.d.ts +0 -9
- package/dist/utils/index.d.cts +0 -3
- package/dist/utils/index.d.ts +0 -3
- package/dist/utils/locales.d.ts +0 -9
- package/dist/utils/path.d.ts +0 -8
package/dist/paths.d.cts
ADDED
|
@@ -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;
|
package/dist/paths.d.ts
ADDED
|
@@ -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
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
*
|
|
54
|
-
*
|
|
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
|
}
|
package/dist/rules.d.cts
ADDED
|
@@ -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/dist/rules.d.ts
ADDED
|
@@ -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": "
|
|
3
|
+
"version": "2.0.0",
|
|
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
|
-
"
|
|
31
|
-
"
|
|
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
|
-
"@
|
|
66
|
-
"@i18n-micro/
|
|
67
|
-
"@i18n-micro/types": "^1.2.18",
|
|
68
|
-
"@i18n-micro/utils": "^1.0.27"
|
|
58
|
+
"@i18n-micro/utils": "^2.0.0",
|
|
59
|
+
"@i18n-micro/types": "^2.0.0"
|
|
69
60
|
},
|
|
70
61
|
"devDependencies": {
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"vite
|
|
74
|
-
"
|
|
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": ">=
|
|
77
|
+
"node": ">=20"
|
|
78
78
|
},
|
|
79
79
|
"scripts": {
|
|
80
80
|
"build": "vite build",
|
package/dist/core/alias.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { NuxtPage } from '@nuxt/schema';
|
|
2
|
-
/**
|
|
3
|
-
* Generates dedicated routes for page aliases.
|
|
4
|
-
* Mirrors the legacy handleAliasRoutes behavior in the original RouteGenerator.
|
|
5
|
-
*/
|
|
6
|
-
export declare function generateAliasRoutes(page: NuxtPage, localeCodes: string[], customRegex?: string | RegExp, localizedRouteNamePrefix?: string): NuxtPage[];
|
package/dist/core/builder.d.ts
DELETED
|
@@ -1,20 +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
|
-
export interface CreateRouteOptions {
|
|
9
|
-
path: string;
|
|
10
|
-
name?: string;
|
|
11
|
-
children?: NuxtPage[];
|
|
12
|
-
meta?: Record<string, unknown>;
|
|
13
|
-
/** When undefined, alias is cleared (for the main localized route when alias routes are created separately). */
|
|
14
|
-
alias?: string[] | undefined;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Creates a new NuxtPage object from the original page and provided options.
|
|
18
|
-
* Copies meta, component, file, etc.; provided options override the respective fields.
|
|
19
|
-
*/
|
|
20
|
-
export declare function createRoute(page: NuxtPage, options: CreateRouteOptions): NuxtPage;
|
package/dist/core/context.d.ts
DELETED
|
@@ -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,30 +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
|
-
/**
|
|
23
|
-
* Shared helper for strategies that build prefix-based paths (:locale(...)):
|
|
24
|
-
* - for custom paths, decides whether a prefix is required,
|
|
25
|
-
* - for regular paths, always uses buildFullPath.
|
|
26
|
-
*
|
|
27
|
-
* The logic matches what used to be duplicated in each strategy's buildRoutePath.
|
|
28
|
-
*/
|
|
29
|
-
protected buildRoutePathForLocales(localeCodes: string[], originalPath: string, customPath: string, isCustom: boolean, customRegex: string | RegExp | undefined, force: boolean, defaultLocaleCode: string): string;
|
|
30
|
-
}
|
|
@@ -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
|
-
/**
|
|
7
|
-
* Localizes the children tree for the no_prefix strategy.
|
|
8
|
-
* Mirrors the behavior of the legacy RouteGenerator:
|
|
9
|
-
* - on the first level, custom paths (globalLocaleRoutes/filesLocaleRoutes) are applied;
|
|
10
|
-
* - on deeper levels, path stays as a segment (item, detail, etc.).
|
|
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>;
|
package/dist/utils/common.d.ts
DELETED
|
@@ -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;
|
package/dist/utils/index.d.cts
DELETED
|
@@ -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';
|
package/dist/utils/index.d.ts
DELETED
|
@@ -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';
|
package/dist/utils/locales.d.ts
DELETED
|
@@ -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;
|
package/dist/utils/path.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export declare function normalizeRouteKey(key: string): string;
|
|
2
|
-
export declare const normalizePath: (routePath: string) => string;
|
|
3
|
-
export declare const removeLeadingSlash: (routePath: string) => string;
|
|
4
|
-
export declare function joinPath(...segments: string[]): string;
|
|
5
|
-
/** Alias paths for percent-encoded variants of non-ASCII localized routes. */
|
|
6
|
-
export declare function buildEncodedPathAliases(routePath: string): string[];
|
|
7
|
-
export declare function buildFullPath(locale: string | string[], basePath: string, customRegex?: string | RegExp): string;
|
|
8
|
-
export declare function buildFullPathNoPrefix(basePath: string): string;
|