intor 2.4.6 → 2.4.8

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 (70) hide show
  1. package/dist/core/export/server/index.js +2 -3
  2. package/dist/core/src/routing/pathname/localize-pathname.js +1 -1
  3. package/dist/core/src/server/helpers/get-translator.js +3 -2
  4. package/dist/core/src/server/intor/intor.js +1 -1
  5. package/dist/core/src/server/translator/init-translator.js +6 -3
  6. package/dist/express/src/adapters/express/get-translator.js +5 -4
  7. package/dist/express/src/routing/pathname/localize-pathname.js +1 -1
  8. package/dist/express/src/server/helpers/get-translator.js +3 -2
  9. package/dist/express/src/server/translator/init-translator.js +6 -3
  10. package/dist/fastify/src/adapters/fastify/get-translator.js +5 -4
  11. package/dist/fastify/src/routing/pathname/localize-pathname.js +1 -1
  12. package/dist/fastify/src/server/helpers/get-translator.js +3 -2
  13. package/dist/fastify/src/server/translator/init-translator.js +6 -3
  14. package/dist/hono/src/routing/pathname/localize-pathname.js +1 -1
  15. package/dist/next/src/adapters/next/server/get-translator.js +5 -4
  16. package/dist/next/src/routing/pathname/localize-pathname.js +1 -1
  17. package/dist/next/src/server/helpers/get-translator.js +3 -2
  18. package/dist/next/src/server/intor/intor.js +1 -1
  19. package/dist/next/src/server/translator/init-translator.js +6 -3
  20. package/dist/svelte-kit/export/svelte-kit/index.js +1 -0
  21. package/dist/svelte-kit/src/adapters/svelte-kit/{server/create-intor-handler.js → create-intor-handler.js} +4 -4
  22. package/dist/svelte-kit/src/core/utils/resolve-loader-options.js +1 -5
  23. package/dist/svelte-kit/src/policies/shoud-full-reload.js +1 -1
  24. package/dist/svelte-kit/src/routing/pathname/localize-pathname.js +1 -1
  25. package/dist/types/export/server/index.d.ts +1 -1
  26. package/dist/types/export/svelte-kit/index.d.ts +1 -1
  27. package/dist/types/src/adapters/next/server/get-translator.d.ts +1 -1
  28. package/dist/types/src/adapters/svelte-kit/{server/create-intor-handler.d.ts → create-intor-handler.d.ts} +1 -1
  29. package/dist/types/src/adapters/svelte-kit/index.d.ts +1 -0
  30. package/dist/types/src/client/react/helpers/use-intor.d.ts +1 -2
  31. package/dist/types/src/client/react/provider/intor-provider.d.ts +1 -2
  32. package/dist/types/src/client/react/provider/types.d.ts +10 -11
  33. package/dist/types/src/client/react/provider/use-intor-context.d.ts +1 -2
  34. package/dist/types/src/routing/index.d.ts +1 -1
  35. package/dist/types/src/routing/pathname/localize-pathname.d.ts +1 -1
  36. package/dist/types/src/server/helpers/get-translator.d.ts +2 -0
  37. package/dist/types/src/server/index.d.ts +2 -1
  38. package/dist/types/src/server/intor/intor.d.ts +2 -3
  39. package/dist/types/src/server/translator/index.d.ts +1 -0
  40. package/dist/types/src/server/translator/init-translator.d.ts +2 -0
  41. package/dist/types/src/server/translator/types.d.ts +9 -0
  42. package/package.json +1 -5
  43. package/dist/svelte-kit/export/svelte-kit/server/index.js +0 -2
  44. package/dist/svelte-kit/src/adapters/svelte-kit/server/intor.js +0 -24
  45. package/dist/svelte-kit/src/core/logger/get-logger.js +0 -39
  46. package/dist/svelte-kit/src/core/logger/global-logger-pool.js +0 -8
  47. package/dist/svelte-kit/src/core/messages/load-remote-messages/collect-remote-resources.js +0 -25
  48. package/dist/svelte-kit/src/core/messages/load-remote-messages/fetch-remote-resource.js +0 -47
  49. package/dist/svelte-kit/src/core/messages/load-remote-messages/load-remote-messages.js +0 -93
  50. package/dist/svelte-kit/src/core/messages/load-remote-messages/resolve-remote-resources.js +0 -24
  51. package/dist/svelte-kit/src/core/messages/merge-messages.js +0 -33
  52. package/dist/svelte-kit/src/core/messages/utils/is-valid-messages.js +0 -44
  53. package/dist/svelte-kit/src/core/messages/utils/nest-object-from-path.js +0 -21
  54. package/dist/svelte-kit/src/core/translator/create-translator.js +0 -30
  55. package/dist/svelte-kit/src/core/utils/deep-merge.js +0 -47
  56. package/dist/svelte-kit/src/core/utils/normalizers/normalize-cache-key.js +0 -45
  57. package/dist/svelte-kit/src/server/intor/intor.js +0 -32
  58. package/dist/svelte-kit/src/server/messages/load-local-messages/cache/messages-pool.js +0 -11
  59. package/dist/svelte-kit/src/server/messages/load-local-messages/load-local-messages.js +0 -108
  60. package/dist/svelte-kit/src/server/messages/load-local-messages/read-locale-messages/collect-file-entries/collect-file-entries.js +0 -91
  61. package/dist/svelte-kit/src/server/messages/load-local-messages/read-locale-messages/parse-file-entries/parse-file-entries.js +0 -103
  62. package/dist/svelte-kit/src/server/messages/load-local-messages/read-locale-messages/parse-file-entries/utils/json-reader.js +0 -12
  63. package/dist/svelte-kit/src/server/messages/load-local-messages/read-locale-messages/read-locale-messages.js +0 -42
  64. package/dist/svelte-kit/src/server/messages/load-messages.js +0 -78
  65. package/dist/svelte-kit/src/server/translator/init-translator.js +0 -36
  66. package/dist/types/export/svelte-kit/server/index.d.ts +0 -1
  67. package/dist/types/src/adapters/svelte-kit/server/index.d.ts +0 -2
  68. package/dist/types/src/adapters/svelte-kit/server/intor.d.ts +0 -20
  69. /package/dist/svelte-kit/src/adapters/svelte-kit/{server/utils → utils}/is-svelte-kit-ssg.js +0 -0
  70. /package/dist/types/src/adapters/svelte-kit/{server/utils → utils}/is-svelte-kit-ssg.d.ts +0 -0
@@ -1,10 +1,9 @@
1
1
  export { intor } from '../../src/server/intor/intor.js';
2
- export { loadMessages } from '../../src/server/messages/load-messages.js';
3
- import 'node:path';
4
- import 'p-limit';
5
2
  import '../../src/core/error/intor-error.js';
6
3
  import 'logry';
4
+ import 'p-limit';
7
5
  import 'intor-translator';
6
+ import 'node:path';
8
7
  export { clearMessagesPool } from '../../src/server/messages/load-local-messages/cache/messages-pool.js';
9
8
  import 'node:fs/promises';
10
9
  export { getTranslator } from '../../src/server/helpers/get-translator.js';
@@ -11,7 +11,7 @@ import { standardizePathname } from './standardize-pathname.js';
11
11
  * // config.supportedLocales: ["en-US"]
12
12
  * // config.routing.basePath: "/app"
13
13
  * // config.routing.prefix: "all"
14
- * localizePathname(config, "/app/en-US/about", "en-US");
14
+ * localizePathname("/app/en-US/about", config, "en-US");
15
15
  * // => {
16
16
  * // pathname: '/app/en-US/about'
17
17
  * // unprefixedPathname: '/about',
@@ -9,14 +9,15 @@ import { initTranslator } from '../translator/init-translator.js';
9
9
  * Get a server-side translator for the current execution context.
10
10
  */
11
11
  async function getTranslator(config, params) {
12
- const { locale, readers, allowCacheWrite, fetch, preKey, handlers, plugins } = params;
12
+ const { locale, loader, readers, allowCacheWrite = false, fetch, handlers, plugins, preKey, } = params;
13
13
  // Initialize a locale-bound translator snapshot with messages loaded
14
14
  const translator = await initTranslator(config, locale, {
15
+ loader,
15
16
  readers,
16
17
  allowCacheWrite,
17
18
  fetch: fetch || globalThis.fetch,
18
- plugins,
19
19
  handlers,
20
+ plugins,
20
21
  });
21
22
  const scoped = translator.scoped(preKey);
22
23
  return {
@@ -18,7 +18,7 @@ async function intor(config, locale, options) {
18
18
  // Initialize a locale-bound translator snapshot with messages loaded
19
19
  const translator = await initTranslator(config, locale, {
20
20
  readers: options?.readers,
21
- allowCacheWrite: options?.allowCacheWrite,
21
+ allowCacheWrite: options?.allowCacheWrite ?? true,
22
22
  fetch: options?.fetch || globalThis.fetch,
23
23
  });
24
24
  logger.info("Intor initialized.");
@@ -15,11 +15,11 @@ import 'node:fs/promises';
15
15
  * - Creates an immutable Translator instance for server usage
16
16
  */
17
17
  async function initTranslator(config, locale, options) {
18
- const { readers, allowCacheWrite = false, fetch, handlers, plugins, } = options;
19
- const loader = resolveLoaderOptions(config, "server");
18
+ const { loader, readers, allowCacheWrite = false, fetch, handlers, plugins, } = options;
19
+ const loaderOptions = resolveLoaderOptions(config, "server");
20
20
  // Load messages
21
21
  let messages = {};
22
- if (loader) {
22
+ if (loaderOptions && !loader) {
23
23
  const loaded = await loadMessages({
24
24
  config,
25
25
  locale,
@@ -29,6 +29,9 @@ async function initTranslator(config, locale, options) {
29
29
  });
30
30
  messages = loaded || {};
31
31
  }
32
+ if (loader) {
33
+ messages = await loader(config, locale);
34
+ }
32
35
  // Create immutable translator snapshot
33
36
  return createTranslator({ config, locale, messages, handlers, plugins });
34
37
  }
@@ -14,14 +14,15 @@ import { getTranslator as getTranslator$1 } from '../../server/helpers/get-trans
14
14
  * @platform Express
15
15
  */
16
16
  async function getTranslator(config, req, params) {
17
- const { preKey, handlers, plugins, readers, allowCacheWrite } = params || {};
17
+ const { loader, readers, allowCacheWrite, handlers, plugins, preKey } = params || {};
18
18
  return getTranslator$1(config, {
19
19
  locale: req.intor?.locale || config.defaultLocale,
20
- preKey,
21
- handlers,
22
- plugins,
20
+ loader,
23
21
  readers,
24
22
  allowCacheWrite,
23
+ handlers,
24
+ plugins,
25
+ preKey,
25
26
  });
26
27
  }
27
28
 
@@ -11,7 +11,7 @@ import { standardizePathname } from './standardize-pathname.js';
11
11
  * // config.supportedLocales: ["en-US"]
12
12
  * // config.routing.basePath: "/app"
13
13
  * // config.routing.prefix: "all"
14
- * localizePathname(config, "/app/en-US/about", "en-US");
14
+ * localizePathname("/app/en-US/about", config, "en-US");
15
15
  * // => {
16
16
  * // pathname: '/app/en-US/about'
17
17
  * // unprefixedPathname: '/about',
@@ -9,14 +9,15 @@ import { initTranslator } from '../translator/init-translator.js';
9
9
  * Get a server-side translator for the current execution context.
10
10
  */
11
11
  async function getTranslator(config, params) {
12
- const { locale, readers, allowCacheWrite, fetch, preKey, handlers, plugins } = params;
12
+ const { locale, loader, readers, allowCacheWrite = false, fetch, handlers, plugins, preKey, } = params;
13
13
  // Initialize a locale-bound translator snapshot with messages loaded
14
14
  const translator = await initTranslator(config, locale, {
15
+ loader,
15
16
  readers,
16
17
  allowCacheWrite,
17
18
  fetch: fetch || globalThis.fetch,
18
- plugins,
19
19
  handlers,
20
+ plugins,
20
21
  });
21
22
  const scoped = translator.scoped(preKey);
22
23
  return {
@@ -15,11 +15,11 @@ import 'node:fs/promises';
15
15
  * - Creates an immutable Translator instance for server usage
16
16
  */
17
17
  async function initTranslator(config, locale, options) {
18
- const { readers, allowCacheWrite = false, fetch, handlers, plugins, } = options;
19
- const loader = resolveLoaderOptions(config);
18
+ const { loader, readers, allowCacheWrite = false, fetch, handlers, plugins, } = options;
19
+ const loaderOptions = resolveLoaderOptions(config);
20
20
  // Load messages
21
21
  let messages = {};
22
- if (loader) {
22
+ if (loaderOptions && !loader) {
23
23
  const loaded = await loadMessages({
24
24
  config,
25
25
  locale,
@@ -29,6 +29,9 @@ async function initTranslator(config, locale, options) {
29
29
  });
30
30
  messages = loaded || {};
31
31
  }
32
+ if (loader) {
33
+ messages = await loader(config, locale);
34
+ }
32
35
  // Create immutable translator snapshot
33
36
  return createTranslator({ config, locale, messages, handlers, plugins });
34
37
  }
@@ -14,14 +14,15 @@ import { getTranslator as getTranslator$1 } from '../../server/helpers/get-trans
14
14
  * @platform Fastify
15
15
  */
16
16
  async function getTranslator(config, request, params) {
17
- const { preKey, handlers, plugins, readers, allowCacheWrite } = params || {};
17
+ const { loader, readers, allowCacheWrite, handlers, plugins, preKey } = params || {};
18
18
  return getTranslator$1(config, {
19
19
  locale: request.intor?.locale || config.defaultLocale,
20
- preKey,
21
- handlers,
22
- plugins,
20
+ loader,
23
21
  readers,
24
22
  allowCacheWrite,
23
+ handlers,
24
+ plugins,
25
+ preKey,
25
26
  });
26
27
  }
27
28
 
@@ -11,7 +11,7 @@ import { standardizePathname } from './standardize-pathname.js';
11
11
  * // config.supportedLocales: ["en-US"]
12
12
  * // config.routing.basePath: "/app"
13
13
  * // config.routing.prefix: "all"
14
- * localizePathname(config, "/app/en-US/about", "en-US");
14
+ * localizePathname("/app/en-US/about", config, "en-US");
15
15
  * // => {
16
16
  * // pathname: '/app/en-US/about'
17
17
  * // unprefixedPathname: '/about',
@@ -9,14 +9,15 @@ import { initTranslator } from '../translator/init-translator.js';
9
9
  * Get a server-side translator for the current execution context.
10
10
  */
11
11
  async function getTranslator(config, params) {
12
- const { locale, readers, allowCacheWrite, fetch, preKey, handlers, plugins } = params;
12
+ const { locale, loader, readers, allowCacheWrite = false, fetch, handlers, plugins, preKey, } = params;
13
13
  // Initialize a locale-bound translator snapshot with messages loaded
14
14
  const translator = await initTranslator(config, locale, {
15
+ loader,
15
16
  readers,
16
17
  allowCacheWrite,
17
18
  fetch: fetch || globalThis.fetch,
18
- plugins,
19
19
  handlers,
20
+ plugins,
20
21
  });
21
22
  const scoped = translator.scoped(preKey);
22
23
  return {
@@ -15,11 +15,11 @@ import 'node:fs/promises';
15
15
  * - Creates an immutable Translator instance for server usage
16
16
  */
17
17
  async function initTranslator(config, locale, options) {
18
- const { readers, allowCacheWrite = false, fetch, handlers, plugins, } = options;
19
- const loader = resolveLoaderOptions(config);
18
+ const { loader, readers, allowCacheWrite = false, fetch, handlers, plugins, } = options;
19
+ const loaderOptions = resolveLoaderOptions(config);
20
20
  // Load messages
21
21
  let messages = {};
22
- if (loader) {
22
+ if (loaderOptions && !loader) {
23
23
  const loaded = await loadMessages({
24
24
  config,
25
25
  locale,
@@ -29,6 +29,9 @@ async function initTranslator(config, locale, options) {
29
29
  });
30
30
  messages = loaded || {};
31
31
  }
32
+ if (loader) {
33
+ messages = await loader(config, locale);
34
+ }
32
35
  // Create immutable translator snapshot
33
36
  return createTranslator({ config, locale, messages, handlers, plugins });
34
37
  }
@@ -11,7 +11,7 @@ import { standardizePathname } from './standardize-pathname.js';
11
11
  * // config.supportedLocales: ["en-US"]
12
12
  * // config.routing.basePath: "/app"
13
13
  * // config.routing.prefix: "all"
14
- * localizePathname(config, "/app/en-US/about", "en-US");
14
+ * localizePathname("/app/en-US/about", config, "en-US");
15
15
  * // => {
16
16
  * // pathname: '/app/en-US/about'
17
17
  * // unprefixedPathname: '/about',
@@ -15,14 +15,15 @@ import { getLocale } from './get-locale.js';
15
15
  * @platform Next.js
16
16
  */
17
17
  async function getTranslator(config, params) {
18
- const { preKey, handlers, plugins, readers, allowCacheWrite } = params || {};
18
+ const { loader, readers, allowCacheWrite, handlers, plugins, preKey } = params || {};
19
19
  return getTranslator$1(config, {
20
20
  locale: await getLocale(config),
21
- preKey,
22
- handlers,
23
- plugins,
21
+ loader,
24
22
  readers,
25
23
  allowCacheWrite,
24
+ handlers,
25
+ plugins,
26
+ preKey,
26
27
  });
27
28
  }
28
29
 
@@ -11,7 +11,7 @@ import { standardizePathname } from './standardize-pathname.js';
11
11
  * // config.supportedLocales: ["en-US"]
12
12
  * // config.routing.basePath: "/app"
13
13
  * // config.routing.prefix: "all"
14
- * localizePathname(config, "/app/en-US/about", "en-US");
14
+ * localizePathname("/app/en-US/about", config, "en-US");
15
15
  * // => {
16
16
  * // pathname: '/app/en-US/about'
17
17
  * // unprefixedPathname: '/about',
@@ -9,14 +9,15 @@ import { initTranslator } from '../translator/init-translator.js';
9
9
  * Get a server-side translator for the current execution context.
10
10
  */
11
11
  async function getTranslator(config, params) {
12
- const { locale, readers, allowCacheWrite, fetch, preKey, handlers, plugins } = params;
12
+ const { locale, loader, readers, allowCacheWrite = false, fetch, handlers, plugins, preKey, } = params;
13
13
  // Initialize a locale-bound translator snapshot with messages loaded
14
14
  const translator = await initTranslator(config, locale, {
15
+ loader,
15
16
  readers,
16
17
  allowCacheWrite,
17
18
  fetch: fetch || globalThis.fetch,
18
- plugins,
19
19
  handlers,
20
+ plugins,
20
21
  });
21
22
  const scoped = translator.scoped(preKey);
22
23
  return {
@@ -18,7 +18,7 @@ async function intor(config, locale, options) {
18
18
  // Initialize a locale-bound translator snapshot with messages loaded
19
19
  const translator = await initTranslator(config, locale, {
20
20
  readers: options?.readers,
21
- allowCacheWrite: options?.allowCacheWrite,
21
+ allowCacheWrite: options?.allowCacheWrite ?? true,
22
22
  fetch: options?.fetch || globalThis.fetch,
23
23
  });
24
24
  logger.info("Intor initialized.");
@@ -15,11 +15,11 @@ import 'node:fs/promises';
15
15
  * - Creates an immutable Translator instance for server usage
16
16
  */
17
17
  async function initTranslator(config, locale, options) {
18
- const { readers, allowCacheWrite = false, fetch, handlers, plugins, } = options;
19
- const loader = resolveLoaderOptions(config, "server");
18
+ const { loader, readers, allowCacheWrite = false, fetch, handlers, plugins, } = options;
19
+ const loaderOptions = resolveLoaderOptions(config, "server");
20
20
  // Load messages
21
21
  let messages = {};
22
- if (loader) {
22
+ if (loaderOptions && !loader) {
23
23
  const loaded = await loadMessages({
24
24
  config,
25
25
  locale,
@@ -29,6 +29,9 @@ async function initTranslator(config, locale, options) {
29
29
  });
30
30
  messages = loaded || {};
31
31
  }
32
+ if (loader) {
33
+ messages = await loader(config, locale);
34
+ }
32
35
  // Create immutable translator snapshot
33
36
  return createTranslator({ config, locale, messages, handlers, plugins });
34
37
  }
@@ -1 +1,2 @@
1
+ export { createIntorHandler } from '../../src/adapters/svelte-kit/create-intor-handler.js';
1
2
  export { useNavigation } from '../../src/adapters/svelte-kit/use-navigation.js';
@@ -1,12 +1,12 @@
1
1
  import { redirect } from '@sveltejs/kit';
2
2
  import { isSvelteKitSSG } from './utils/is-svelte-kit-ssg.js';
3
- import '../../../core/error/intor-error.js';
4
- import { normalizeQuery } from '../../../core/utils/normalizers/normalize-query.js';
3
+ import '../../core/error/intor-error.js';
4
+ import { normalizeQuery } from '../../core/utils/normalizers/normalize-query.js';
5
5
  import 'logry';
6
6
  import 'p-limit';
7
7
  import 'intor-translator';
8
- import { resolveInbound } from '../../../routing/inbound/resolve-inbound.js';
9
- import { getLocaleFromAcceptLanguage } from '../../../routing/locale/get-locale-from-accept-language.js';
8
+ import { resolveInbound } from '../../routing/inbound/resolve-inbound.js';
9
+ import { getLocaleFromAcceptLanguage } from '../../routing/locale/get-locale-from-accept-language.js';
10
10
 
11
11
  /**
12
12
  * Resolves locale-aware routing for the current execution context.
@@ -21,7 +21,7 @@ const resolveLoaderOptions = (config, runtime) => {
21
21
  // ------------------------------------------------
22
22
  // runtime: client
23
23
  // ------------------------------------------------
24
- if (runtime === "client") {
24
+ {
25
25
  const client = config.client?.loader;
26
26
  if (client) {
27
27
  // Client loader is always remote by design
@@ -29,10 +29,6 @@ const resolveLoaderOptions = (config, runtime) => {
29
29
  }
30
30
  return config.server?.loader ?? config.loader;
31
31
  }
32
- // ------------------------------------------------
33
- // runtime: server
34
- // ------------------------------------------------
35
- return config.server?.loader ?? config.loader;
36
32
  };
37
33
 
38
34
  export { resolveLoaderOptions };
@@ -8,7 +8,7 @@ import 'intor-translator';
8
8
  * Determine whether client-side navigation must be forced to reload.
9
9
  */
10
10
  function shouldFullReload(config) {
11
- const loader = resolveLoaderOptions(config, "client");
11
+ const loader = resolveLoaderOptions(config);
12
12
  return (loader?.mode === "local" || config.routing.outbound.forceFullReload === true);
13
13
  }
14
14
 
@@ -11,7 +11,7 @@ import { standardizePathname } from './standardize-pathname.js';
11
11
  * // config.supportedLocales: ["en-US"]
12
12
  * // config.routing.basePath: "/app"
13
13
  * // config.routing.prefix: "all"
14
- * localizePathname(config, "/app/en-US/about", "en-US");
14
+ * localizePathname("/app/en-US/about", config, "en-US");
15
15
  * // => {
16
16
  * // pathname: '/app/en-US/about'
17
17
  * // unprefixedPathname: '/about',
@@ -1 +1 @@
1
- export { intor, type IntorValue, loadMessages, clearMessagesPool, getTranslator, } from "../../src/server";
1
+ export { intor, type IntorValue, clearMessagesPool, getTranslator, type MessagesLoader, } from "../../src/server";
@@ -1 +1 @@
1
- export { useNavigation } from "../../src/adapters/svelte-kit";
1
+ export { createIntorHandler, useNavigation } from "../../src/adapters/svelte-kit";
@@ -10,7 +10,7 @@ type GetTranslatorNextParams<CK extends GenConfigKeys = "__default__"> = Omit<Ge
10
10
  *
11
11
  * @platform Next.js
12
12
  */
13
- export declare function getTranslator<CK extends GenConfigKeys = "__default__", ReplacementSchema = GenReplacements<CK>, RichSchema = GenRich<CK>, PK extends LocalizedPreKey<GenMessages<CK>> | undefined = undefined>(config: IntorResolvedConfig, params: GetTranslatorNextParams<CK> & {
13
+ export declare function getTranslator<CK extends GenConfigKeys = "__default__", ReplacementSchema = GenReplacements<CK>, RichSchema = GenRich<CK>, PK extends LocalizedPreKey<GenMessages<CK>> | undefined = undefined>(config: IntorResolvedConfig, params?: GetTranslatorNextParams<CK> & {
14
14
  preKey?: PK;
15
15
  }): Promise<TranslatorInstance<GenMessages<CK>, ReplacementSchema, RichSchema, PK>>;
16
16
  export {};
@@ -1,4 +1,4 @@
1
- import type { IntorResolvedConfig } from "../../../config";
1
+ import type { IntorResolvedConfig } from "../../config";
2
2
  import type { Handle } from "@sveltejs/kit";
3
3
  /**
4
4
  * Resolves locale-aware routing for the current execution context.
@@ -1 +1,2 @@
1
+ export { createIntorHandler } from "./create-intor-handler";
1
2
  export { useNavigation } from "./use-navigation";
@@ -1,5 +1,4 @@
1
1
  import type { IntorValue } from "../provider";
2
2
  import type { IntorResolvedConfig } from "../../../config";
3
- import type { GenConfigKeys } from "../../../core";
4
3
  import type { Locale, LocaleMessages } from "intor-translator";
5
- export declare function useIntor<CK extends GenConfigKeys = "__default__">(config: IntorResolvedConfig, loader: (config: IntorResolvedConfig, locale: Locale) => Promise<LocaleMessages>): Omit<IntorValue<CK>, "handlers" | "plugins">;
4
+ export declare function useIntor(config: IntorResolvedConfig, loader: (config: IntorResolvedConfig, locale: Locale) => Promise<LocaleMessages>): Omit<IntorValue, "handlers" | "plugins">;
@@ -1,5 +1,4 @@
1
1
  import type { IntorContextValue, IntorProviderProps } from "./types";
2
- import type { GenConfigKeys } from "../../../core";
3
2
  import * as React from "react";
4
3
  export declare const IntorContext: React.Context<IntorContextValue | undefined>;
5
- export declare function IntorProvider<CK extends GenConfigKeys = "__default__">({ value: { config, locale: initialLocale, messages, handlers, plugins, onLocaleChange, isLoading: externalIsLoading, }, children, }: IntorProviderProps<CK>): import("react/jsx-runtime").JSX.Element;
4
+ export declare function IntorProvider({ value: { config, locale: initialLocale, messages, handlers, plugins, onLocaleChange, isLoading: externalIsLoading, }, children, }: IntorProviderProps): import("react/jsx-runtime").JSX.Element;
@@ -1,24 +1,23 @@
1
1
  import type { IntorResolvedConfig } from "../../../config";
2
- import type { GenConfigKeys, GenLocale, GenMessages } from "../../../core";
3
- import type { TranslateHandlers, TranslateHook, TranslatorPlugin } from "intor-translator";
2
+ import type { Locale, LocaleMessages, TranslateHandlers, TranslateHook, TranslatorPlugin } from "intor-translator";
4
3
  import type { Translator } from "intor-translator";
5
4
  import type * as React from "react";
6
- export interface IntorValue<CK extends GenConfigKeys = "__default__"> {
5
+ export interface IntorValue {
7
6
  config: IntorResolvedConfig;
8
- locale: GenLocale<CK>;
9
- messages?: Readonly<GenMessages<CK>>;
7
+ locale: Locale;
8
+ messages?: Readonly<LocaleMessages>;
10
9
  isLoading?: boolean;
11
- onLocaleChange?: (newLocale: GenLocale<CK>) => Promise<void> | void;
10
+ onLocaleChange?: (newLocale: Locale) => Promise<void> | void;
12
11
  handlers?: TranslateHandlers;
13
12
  plugins?: (TranslatorPlugin | TranslateHook)[];
14
13
  }
15
- export interface IntorProviderProps<CK extends GenConfigKeys = "__default__"> {
16
- value: IntorValue<CK>;
14
+ export interface IntorProviderProps {
15
+ value: IntorValue;
17
16
  children: React.ReactNode;
18
17
  }
19
- export type IntorContextValue<CK extends GenConfigKeys = "__default__"> = {
18
+ export type IntorContextValue = {
20
19
  config: IntorResolvedConfig;
21
- locale: GenLocale<CK>;
22
- setLocale: (locale: GenLocale<CK>) => void;
20
+ locale: Locale;
21
+ setLocale: (locale: Locale) => void;
23
22
  translator: Translator<unknown>;
24
23
  };
@@ -1,3 +1,2 @@
1
1
  import type { IntorContextValue } from "./types";
2
- import type { GenConfigKeys } from "../../../core";
3
- export declare function useIntorContext<CK extends GenConfigKeys = "__default__">(): IntorContextValue<CK>;
2
+ export declare function useIntorContext(): IntorContextValue;
@@ -1,4 +1,4 @@
1
1
  export { resolveInbound, type InboundResult, type InboundContext, resolveInboundFromRequest, } from "./inbound";
2
+ export { resolveOutbound, type OutboundResult } from "./outbound";
2
3
  export { localizePathname, type LocalizedPathname } from "./pathname";
3
4
  export { getLocaleFromAcceptLanguage, getLocaleFromPathname, getLocaleFromHost, getLocaleFromQuery, } from "./locale";
4
- export { resolveOutbound, type OutboundResult } from "./outbound";
@@ -37,7 +37,7 @@ export interface LocalizedPathname {
37
37
  * // config.supportedLocales: ["en-US"]
38
38
  * // config.routing.basePath: "/app"
39
39
  * // config.routing.prefix: "all"
40
- * localizePathname(config, "/app/en-US/about", "en-US");
40
+ * localizePathname("/app/en-US/about", config, "en-US");
41
41
  * // => {
42
42
  * // pathname: '/app/en-US/about'
43
43
  * // unprefixedPathname: '/about',
@@ -1,8 +1,10 @@
1
1
  import type { IntorResolvedConfig } from "../../config";
2
2
  import type { LocalizedPreKey, TranslateHandlers, TranslateHook, TranslatorPlugin } from "intor-translator";
3
3
  import { type GenConfigKeys, type GenLocale, type GenMessages, type GenReplacements, type GenRich, type MessagesReaders, type RuntimeFetch, type TranslatorInstance } from "../../core";
4
+ import { type MessagesLoader } from "../translator";
4
5
  export interface GetTranslatorParams<CK extends GenConfigKeys = "__default__"> {
5
6
  locale: GenLocale<CK> | (string & {});
7
+ loader?: MessagesLoader;
6
8
  readers?: MessagesReaders;
7
9
  allowCacheWrite?: boolean;
8
10
  fetch?: RuntimeFetch;
@@ -1,3 +1,4 @@
1
1
  export { intor, type IntorValue } from "./intor";
2
- export { loadMessages, clearMessagesPool } from "./messages";
2
+ export { clearMessagesPool } from "./messages";
3
3
  export { getTranslator, type GetTranslatorParams } from "./helpers";
4
+ export type { MessagesLoader } from "./translator";
@@ -1,14 +1,13 @@
1
1
  import type { IntorValue } from "./types";
2
2
  import type { IntorResolvedConfig } from "../../config";
3
- import type { Locale } from "intor-translator";
4
- import { type GenConfigKeys, type MessagesReaders, type RuntimeFetch } from "../../core";
3
+ import { type GenConfigKeys, type GenLocale, type MessagesReaders, type RuntimeFetch } from "../../core";
5
4
  /**
6
5
  * Initializes Intor for the current execution context.
7
6
  *
8
7
  * Produces a server-side snapshot for SSR and
9
8
  * full-stack rendering environments.
10
9
  */
11
- export declare function intor<CK extends GenConfigKeys = "__default__">(config: IntorResolvedConfig, locale: Locale, options?: {
10
+ export declare function intor<CK extends GenConfigKeys = "__default__">(config: IntorResolvedConfig, locale: GenLocale<CK> | (string & {}), options?: {
12
11
  readers?: MessagesReaders;
13
12
  allowCacheWrite?: boolean;
14
13
  fetch?: RuntimeFetch;
@@ -1 +1,2 @@
1
1
  export { initTranslator } from "../translator/init-translator";
2
+ export type { MessagesLoader } from "./types";
@@ -1,8 +1,10 @@
1
+ import type { MessagesLoader } from "./types";
1
2
  import type { IntorResolvedConfig } from "../../config";
2
3
  import type { Locale, Translator } from "intor-translator";
3
4
  import { type CreateTranslatorParams } from "../../core";
4
5
  import { type LoadMessagesParams } from "../messages";
5
6
  interface InitTranslatorOptions extends Pick<LoadMessagesParams, "readers" | "allowCacheWrite" | "fetch">, Pick<CreateTranslatorParams, "handlers" | "plugins"> {
7
+ loader?: MessagesLoader;
6
8
  }
7
9
  /**
8
10
  * Initialize a locale-bound Translator snapshot.
@@ -0,0 +1,9 @@
1
+ import type { IntorResolvedConfig } from "../../config";
2
+ import type { LocaleMessages } from "intor-translator";
3
+ /**
4
+ * Runtime message loader override.
5
+ *
6
+ * Loads locale messages imperatively at runtime, bypassing
7
+ * message loading defined in the Intor config.
8
+ */
9
+ export type MessagesLoader = (config: IntorResolvedConfig, locale: string) => Promise<LocaleMessages>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intor",
3
- "version": "2.4.6",
3
+ "version": "2.4.8",
4
4
  "description": "The i18n library for modern JavaScript",
5
5
  "author": "Yiming Liao",
6
6
  "homepage": "https://github.com/yiming-liao/intor#readme",
@@ -73,10 +73,6 @@
73
73
  "import": "./dist/svelte-kit/export/svelte-kit/index.js",
74
74
  "types": "./dist/types/export/svelte-kit/index.d.ts"
75
75
  },
76
- "./svelte-kit/server": {
77
- "import": "./dist/svelte-kit/export/svelte-kit/server/index.js",
78
- "types": "./dist/types/export/svelte-kit/server/index.d.ts"
79
- },
80
76
  "./express": {
81
77
  "import": "./dist/express/export/express/index.js",
82
78
  "types": "./dist/types/export/express/index.d.ts",
@@ -1,2 +0,0 @@
1
- export { createIntorHandler } from '../../../src/adapters/svelte-kit/server/create-intor-handler.js';
2
- export { intor } from '../../../src/adapters/svelte-kit/server/intor.js';
@@ -1,24 +0,0 @@
1
- import { intor as intor$1 } from '../../../server/intor/intor.js';
2
- import '../../../core/error/intor-error.js';
3
- import 'logry';
4
- import 'p-limit';
5
- import 'intor-translator';
6
- import 'node:path';
7
- import 'node:fs/promises';
8
-
9
- /**
10
- * Initializes Intor for the current execution context.
11
- *
12
- * - Uses the locale resolved by the SvelteKit request lifecycle.
13
- * - Permits cache writes during server execution.
14
- * @platform SvelteKit
15
- */
16
- async function intor(config, locale, fetch, options) {
17
- return await intor$1(config, locale, {
18
- readers: options?.readers,
19
- allowCacheWrite: options?.allowCacheWrite ?? true,
20
- fetch,
21
- });
22
- }
23
-
24
- export { intor };