intor 2.4.8 → 2.4.10

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 CHANGED
@@ -21,11 +21,6 @@ The i18n library for modern JavaScript
21
21
  </div>
22
22
 
23
23
  > [!NOTE]
24
- > Intor began as an internal i18n tool.
25
- >
26
- > After multiple private iterations, it evolved into a minimal,
27
- > framework-agnostic translation system.
28
- >
29
- > **v3 marks its first intentional public release.**
30
- >
31
- > _Currently available as v2.x. v3 is in active development._
24
+ > Intor is evolving toward long-term stability.
25
+ > **v3 will be the first fully stable release.**
26
+ > _Current: v2.x · v3 in development._
@@ -17,40 +17,42 @@ import { getLocaleFromAcceptLanguage } from '../../routing/locale/get-locale-fro
17
17
  *
18
18
  * @platform Next.js
19
19
  */
20
- const createIntorHandler = async (config, request) => {
21
- const { host, searchParams, pathname: rawPathname } = request.nextUrl;
22
- // Locale from Accept-Language header
23
- const acceptLanguageHeader = request.headers.get("accept-language");
24
- const localeFromAcceptLanguage = getLocaleFromAcceptLanguage(acceptLanguageHeader, config.supportedLocales);
25
- // Check whether this navigation flow has already redirected
26
- const hasRedirected = request.headers.get(INTOR_HEADERS.REDIRECTED) === "1";
27
- // ----------------------------------------------------------
28
- // Resolve inbound routing decision (pure computation)
29
- // ----------------------------------------------------------
30
- const { locale, localeSource, pathname, shouldRedirect } = await resolveInbound(config, rawPathname, {
31
- host,
32
- query: normalizeQuery(Object.fromEntries(searchParams.entries())),
33
- cookie: request.cookies.get(config.cookie.name)?.value,
34
- detected: localeFromAcceptLanguage || config.defaultLocale,
35
- }, { hasRedirected });
36
- // ----------------------------------------------------------
37
- // Prepare Next.js response (redirect or pass-through)
38
- // ----------------------------------------------------------
39
- const url = request.nextUrl.clone();
40
- url.pathname = pathname;
41
- const response = shouldRedirect
42
- ? NextResponse.redirect(url)
43
- : NextResponse.next();
44
- // ----------------------------------------------------------
45
- // Attach routing metadata to response headers
46
- // ----------------------------------------------------------
47
- response.headers.set(INTOR_HEADERS.LOCALE, locale);
48
- response.headers.set(INTOR_HEADERS.LOCALE_SOURCE, localeSource);
49
- response.headers.set(INTOR_HEADERS.PATHNAME, pathname);
50
- // Mark redirect to prevent infinite loops in this flow
51
- if (shouldRedirect)
52
- response.headers.set(INTOR_HEADERS.REDIRECTED, "1");
53
- return response;
54
- };
20
+ function createIntorHandler(config) {
21
+ return async function intorHandler(request) {
22
+ const { host, searchParams, pathname: rawPathname } = request.nextUrl;
23
+ // Locale from Accept-Language header
24
+ const acceptLanguageHeader = request.headers.get("accept-language");
25
+ const localeFromAcceptLanguage = getLocaleFromAcceptLanguage(acceptLanguageHeader, config.supportedLocales);
26
+ // Check whether this navigation flow has already redirected
27
+ const hasRedirected = request.headers.get(INTOR_HEADERS.REDIRECTED) === "1";
28
+ // ----------------------------------------------------------
29
+ // Resolve inbound routing decision (pure computation)
30
+ // ----------------------------------------------------------
31
+ const { locale, localeSource, pathname, shouldRedirect } = await resolveInbound(config, rawPathname, {
32
+ host,
33
+ query: normalizeQuery(Object.fromEntries(searchParams.entries())),
34
+ cookie: request.cookies.get(config.cookie.name)?.value,
35
+ detected: localeFromAcceptLanguage || config.defaultLocale,
36
+ }, { hasRedirected });
37
+ // ----------------------------------------------------------
38
+ // Prepare Next.js response (redirect or pass-through)
39
+ // ----------------------------------------------------------
40
+ const url = request.nextUrl.clone();
41
+ url.pathname = pathname;
42
+ const response = shouldRedirect
43
+ ? NextResponse.redirect(url)
44
+ : NextResponse.next();
45
+ // ----------------------------------------------------------
46
+ // Attach routing metadata to response headers
47
+ // ----------------------------------------------------------
48
+ response.headers.set(INTOR_HEADERS.LOCALE, locale);
49
+ response.headers.set(INTOR_HEADERS.LOCALE_SOURCE, localeSource);
50
+ response.headers.set(INTOR_HEADERS.PATHNAME, pathname);
51
+ // Mark redirect to prevent infinite loops in this flow
52
+ if (shouldRedirect)
53
+ response.headers.set(INTOR_HEADERS.REDIRECTED, "1");
54
+ return response;
55
+ };
56
+ }
55
57
 
56
58
  export { createIntorHandler };
@@ -29,8 +29,13 @@ function useNavigation() {
29
29
  });
30
30
  return goto(outboundResult.destination, rest);
31
31
  }
32
+ function href(url) {
33
+ const { destination } = resolveOutbound(config, get(currentLocale), page.url.pathname, { destination: url });
34
+ return destination;
35
+ }
32
36
  return {
33
37
  goto: goto$1,
38
+ href,
34
39
  };
35
40
  }
36
41
 
@@ -1,5 +1,6 @@
1
1
  import type { IntorResolvedConfig } from "../../config";
2
2
  import type { NextRequest } from "next/server";
3
+ import { NextResponse } from "next/server";
3
4
  /**
4
5
  * Resolves locale-aware routing for the current execution context.
5
6
  *
@@ -9,4 +10,4 @@ import type { NextRequest } from "next/server";
9
10
  *
10
11
  * @platform Next.js
11
12
  */
12
- export declare const createIntorHandler: (config: IntorResolvedConfig, request: NextRequest) => Promise<Response>;
13
+ export declare function createIntorHandler(config: IntorResolvedConfig): (request: NextRequest) => Promise<NextResponse<unknown>>;
@@ -12,4 +12,5 @@ export declare function useNavigation<CK extends GenConfigKeys = "__default__">(
12
12
  goto: (url: string, opts?: Parameters<typeof svelteGoto>[1] & {
13
13
  locale?: GenLocale<CK>;
14
14
  }) => Promise<void>;
15
+ href: (url: string) => string;
15
16
  };
@@ -5,4 +5,4 @@ export { getLogger, clearLoggerPool } from "./logger";
5
5
  export { loadRemoteMessages, mergeMessages, isValidMessages, nestObjectFromPath, type MessagesReader, type MessagesReaders, INTOR_PREFIX, INTOR_MESSAGES_KIND_KEY, INTOR_MESSAGES_KIND, getMessagesKind, type IntorMessagesKind, } from "./messages";
6
6
  export { createHtmlRenderer, type TagRenderers, type HtmlTagRenderers, } from "./render";
7
7
  export { createTranslator, type CreateTranslatorParams, createTRich, } from "./translator";
8
- export type { INTOR_GENERATED_KEY, IfGen, GenConfigKeys, GenConfig, GenMessages, GenLocale, GenReplacements, GenRich, TranslatorInstance, RoutingLocaleSource, RoutingLocaleCarrier, LocalePathPrefix, RuntimeFetch, } from "./types";
8
+ export type { INTOR_GENERATED_KEY, GenConfigKeys, GenConfig, GenMessages, GenLocale, GenReplacements, GenRich, TranslatorInstance, RoutingLocaleSource, RoutingLocaleCarrier, LocalePathPrefix, RuntimeFetch, } from "./types";
@@ -1,41 +1,44 @@
1
1
  import type { PREFIX_PLACEHOLDER } from "../constants";
2
2
  import type { Locale, LocaleMessages, Replacement, Rich } from "intor-translator";
3
3
  /**
4
- * ================================================
5
- * Generated-aware type system for Intor.
6
- *
7
- * This module defines conditional and fallback types that adapt
8
- * based on whether generated types are present.
9
- * ================================================
4
+ * =================================================
5
+ * Generated-aware type system for Intor
6
+ * =================================================
10
7
  */
11
8
  /**
12
- * Internal sentinel key indicating that Intor generated types are present.
13
- * - Used by conditional types to switch between fallback and generated modes.
14
- * - Type-level only. Not for runtime or user-facing usage.
9
+ * Sentinel key injected by CLI when generated types exist.
10
+ * Used purely for type-level generation detection.
15
11
  */
16
12
  export type INTOR_GENERATED_KEY = "__intor_generated__";
17
13
  /**
18
- * Conditional type for generated types.
19
- * - Uses key presence on `IntorGeneratedTypes` to detect generation.
14
+ * Detect whether generated types are present.
20
15
  */
21
- export type IfGen<Then, Else = never> = IntorGeneratedTypes extends {
16
+ type HasGenerated = IntorGeneratedTypes extends {
22
17
  [K in INTOR_GENERATED_KEY]: true;
23
- } ? Then : Else;
18
+ } ? true : false;
24
19
  /**
25
- * Config keys provided by generated types.
26
- * - Excludes internal sentinel
20
+ * Extract valid configuration keys from generated types.
21
+ * (Excludes sentinel key.)
27
22
  */
28
23
  type GeneratedConfigKeys = Exclude<keyof IntorGeneratedTypes, INTOR_GENERATED_KEY>;
29
24
  /**
30
- * Union of all configuration keys.
31
- * - Defaults to `string` if `IntorGeneratedTypes` does not exist.
25
+ * Public configuration key union.
26
+ * Falls back to `string` in non-generated mode.
27
+ */
28
+ export type GenConfigKeys = HasGenerated extends true ? GeneratedConfigKeys : string;
29
+ /**
30
+ * Fallback configuration shape (non-generated mode).
32
31
  */
33
- export type GenConfigKeys = IfGen<GeneratedConfigKeys, string>;
32
+ type FallbackConfig = {
33
+ Locales: Locale;
34
+ Messages: LocaleMessages;
35
+ Replacements: Replacement;
36
+ Rich: Rich;
37
+ };
34
38
  /**
35
- * Configuration shape for a given config key.
36
- * - If `IntorGeneratedTypes` is not defined, falls back to default shape.
39
+ * Extract generated configuration shape safely.
37
40
  */
38
- export type GenConfig<CK extends GenConfigKeys> = IfGen<CK extends keyof IntorGeneratedTypes ? IntorGeneratedTypes[CK] extends {
41
+ type ExtractGeneratedConfig<T> = T extends {
39
42
  Locales: infer L extends string;
40
43
  Messages: Record<typeof PREFIX_PLACEHOLDER, infer M>;
41
44
  Replacements: infer RE;
@@ -45,18 +48,19 @@ export type GenConfig<CK extends GenConfigKeys> = IfGen<CK extends keyof IntorGe
45
48
  Messages: Record<L, M>;
46
49
  Replacements: RE;
47
50
  Rich: RI;
48
- } : never : never, {
49
- Locales: Locale;
50
- Messages: LocaleMessages;
51
- Replacements: Replacement;
52
- Rich: Rich;
53
- }>;
54
- /** Resolves message schema for a given config key */
51
+ } : never;
52
+ /**
53
+ * Configuration shape resolver.
54
+ *
55
+ * - Uses generated types when available.
56
+ * - Falls back to default shape otherwise.
57
+ */
58
+ export type GenConfig<CK extends GenConfigKeys> = HasGenerated extends true ? CK extends GeneratedConfigKeys ? ExtractGeneratedConfig<IntorGeneratedTypes[CK]> : never : FallbackConfig;
59
+ /**
60
+ * Derived helpers
61
+ */
55
62
  export type GenMessages<CK extends GenConfigKeys> = GenConfig<CK>["Messages"];
56
- /** Resolves locale union for a given config key */
57
63
  export type GenLocale<CK extends GenConfigKeys> = GenConfig<CK>["Locales"];
58
- /** Resolves replacement schema for a given config key */
59
64
  export type GenReplacements<CK extends GenConfigKeys> = GenConfig<CK>["Replacements"];
60
- /** Resolves rich tag schema for a given config key */
61
65
  export type GenRich<CK extends GenConfigKeys> = GenConfig<CK>["Rich"];
62
66
  export {};
@@ -1,4 +1,4 @@
1
- export type { INTOR_GENERATED_KEY, IfGen, GenConfigKeys, GenConfig, GenMessages, GenLocale, GenReplacements, GenRich, } from "./generated";
1
+ export type { INTOR_GENERATED_KEY, GenConfigKeys, GenConfig, GenMessages, GenLocale, GenReplacements, GenRich, } from "./generated";
2
2
  export type { TranslatorInstance } from "./translator-instance";
3
3
  export type { RoutingLocaleSource, RoutingLocaleCarrier, LocalePathPrefix, } from "./routing";
4
4
  export type { RuntimeFetch } from "./runtime-fetch";
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "intor",
3
- "version": "2.4.8",
3
+ "version": "2.4.10",
4
4
  "description": "The i18n library for modern JavaScript",
5
5
  "author": "Yiming Liao",
6
- "homepage": "https://github.com/yiming-liao/intor#readme",
6
+ "homepage": "https://intor.dev",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "https://github.com/yiming-liao/intor"
@@ -18,14 +18,14 @@
18
18
  "keywords": [
19
19
  "i18n",
20
20
  "internationalization",
21
- "translation",
22
21
  "typescript",
22
+ "type-safe",
23
+ "i18n-cli",
24
+ "framework-agnostic",
25
+ "ssr",
26
+ "runtime",
23
27
  "node",
24
- "nextjs",
25
- "react",
26
- "translator",
27
- "i18n core",
28
- "custom messages"
28
+ "edge"
29
29
  ],
30
30
  "license": "MIT",
31
31
  "type": "module",