intor 2.3.31 → 2.3.32
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/dist/core/export/index.js +1 -1
- package/dist/core/export/server/index.js +1 -1
- package/dist/core/src/config/resolvers/resolve-fallback-locales.js +1 -0
- package/dist/core/src/config/resolvers/resolve-routing-options.js +1 -0
- package/dist/core/src/config/validators/validate-default-locale.js +1 -0
- package/dist/core/src/config/validators/validate-id.js +1 -0
- package/dist/core/src/config/validators/validate-supported-locales.js +1 -0
- package/dist/{svelte/src/client/svelte/render/create-svelte-renderer.js → core/src/core/render/create-html-renderer.js} +6 -7
- package/dist/{svelte/src/client/svelte → core/src/core}/render/utils/render-attributes.js +7 -5
- package/dist/core/src/core/translator/create-t-rich.js +22 -0
- package/dist/core/src/routing/pathname/canonicalize-pathname.js +1 -0
- package/dist/core/src/routing/pathname/materialize-pathname.js +1 -0
- package/dist/core/src/routing/pathname/standardize-pathname.js +1 -0
- package/dist/core/src/server/helpers/get-translator.js +12 -3
- package/dist/core/src/server/intor/intor.js +1 -0
- package/dist/core/src/server/messages/load-local-messages/load-local-messages.js +1 -0
- package/dist/core/src/server/messages/load-local-messages/read-locale-messages/collect-file-entries/collect-file-entries.js +1 -0
- package/dist/core/src/server/messages/load-local-messages/read-locale-messages/parse-file-entries/parse-file-entries.js +1 -0
- package/dist/core/src/server/messages/load-messages.js +1 -0
- package/dist/core/src/server/translator/create-translator.js +5 -15
- package/dist/core/src/server/translator/init-translator.js +6 -12
- package/dist/express/src/adapters/express/helpers/get-translator.js +1 -1
- package/dist/express/src/adapters/express/middleware/create-intor-middleware.js +3 -3
- package/dist/express/src/core/render/create-html-renderer.js +44 -0
- package/dist/express/src/core/render/utils/escape-html.js +10 -0
- package/dist/express/src/core/render/utils/render-attributes.js +17 -0
- package/dist/express/src/core/translator/create-t-rich.js +22 -0
- package/dist/express/src/routing/inbound/resolve-locale/resolve-locale.js +1 -0
- package/dist/express/src/routing/locale/get-locale-from-pathname.js +1 -0
- package/dist/express/src/routing/pathname/canonicalize-pathname.js +1 -0
- package/dist/express/src/routing/pathname/materialize-pathname.js +1 -0
- package/dist/express/src/routing/pathname/standardize-pathname.js +1 -0
- package/dist/express/src/server/helpers/get-translator.js +12 -3
- package/dist/express/src/server/messages/load-local-messages/load-local-messages.js +1 -0
- package/dist/express/src/server/messages/load-local-messages/read-locale-messages/collect-file-entries/collect-file-entries.js +1 -0
- package/dist/express/src/server/messages/load-local-messages/read-locale-messages/parse-file-entries/parse-file-entries.js +1 -0
- package/dist/express/src/server/messages/load-messages.js +1 -0
- package/dist/express/src/server/translator/create-translator.js +5 -15
- package/dist/express/src/server/translator/init-translator.js +6 -12
- package/dist/next/src/adapters/next/navigation/link.js +1 -0
- package/dist/next/src/adapters/next/navigation/redirect.js +1 -0
- package/dist/next/src/adapters/next/navigation/use-router.js +1 -0
- package/dist/next/src/adapters/next/proxy/intor-proxy.js +1 -0
- package/dist/next/src/adapters/next/server/get-locale.js +1 -0
- package/dist/next/src/adapters/next/server/get-translator.js +1 -1
- package/dist/next/src/adapters/next/server/intor.js +1 -1
- package/dist/next/src/client/shared/navigation/execute-navigation.js +1 -0
- package/dist/next/src/core/render/create-html-renderer.js +44 -0
- package/dist/next/src/core/render/utils/escape-html.js +10 -0
- package/dist/next/src/core/render/utils/render-attributes.js +17 -0
- package/dist/next/src/core/translator/create-t-rich.js +22 -0
- package/dist/next/src/policies/shoud-full-reload.js +1 -0
- package/dist/next/src/routing/inbound/resolve-locale/resolve-locale.js +1 -0
- package/dist/next/src/routing/locale/get-locale-from-pathname.js +1 -0
- package/dist/next/src/routing/pathname/canonicalize-pathname.js +1 -0
- package/dist/next/src/routing/pathname/materialize-pathname.js +1 -0
- package/dist/next/src/routing/pathname/standardize-pathname.js +1 -0
- package/dist/next/src/server/helpers/get-translator.js +12 -3
- package/dist/next/src/server/intor/intor.js +1 -0
- package/dist/next/src/server/messages/load-local-messages/load-local-messages.js +1 -0
- package/dist/next/src/server/messages/load-local-messages/read-locale-messages/collect-file-entries/collect-file-entries.js +1 -0
- package/dist/next/src/server/messages/load-local-messages/read-locale-messages/parse-file-entries/parse-file-entries.js +1 -0
- package/dist/next/src/server/messages/load-messages.js +1 -0
- package/dist/next/src/server/translator/create-translator.js +5 -15
- package/dist/next/src/server/translator/init-translator.js +6 -12
- package/dist/react/src/client/react/helpers/use-intor.js +1 -0
- package/dist/react/src/client/react/provider/effects/use-locale-effects.js +1 -0
- package/dist/react/src/client/react/render/create-react-renderer.js +0 -1
- package/dist/react/src/client/react/translator/create-t-rich.js +7 -4
- package/dist/react/src/client/react/translator/use-translator.js +3 -3
- package/dist/react/src/client/shared/helpers/get-client-locale.js +1 -0
- package/dist/react/src/client/shared/messages/create-refetch-messages.js +1 -0
- package/dist/svelte/src/client/shared/helpers/get-client-locale.js +1 -0
- package/dist/svelte/src/client/shared/messages/create-refetch-messages.js +1 -0
- package/dist/svelte/src/client/svelte/provider/effects/locale-effects.js +1 -0
- package/dist/svelte/src/client/svelte/provider/intor-provider.svelte +7 -2
- package/dist/svelte/src/client/svelte/translator/use-translator.js +5 -7
- package/dist/svelte/src/core/render/create-html-renderer.js +44 -0
- package/dist/svelte/src/core/render/utils/escape-html.js +10 -0
- package/dist/svelte/src/core/render/utils/render-attributes.js +17 -0
- package/dist/svelte/src/core/translator/create-t-rich.js +22 -0
- package/dist/svelte-kit/src/adapters/svelte-kit/navigation/use-navigation.js +1 -0
- package/dist/svelte-kit/src/adapters/svelte-kit/server/create-intor-handle.js +1 -0
- package/dist/svelte-kit/src/adapters/svelte-kit/server/intor.js +1 -1
- package/dist/svelte-kit/src/client/shared/navigation/execute-navigation.js +1 -0
- package/dist/svelte-kit/src/policies/shoud-full-reload.js +1 -0
- package/dist/svelte-kit/src/routing/inbound/resolve-locale/resolve-locale.js +1 -0
- package/dist/svelte-kit/src/routing/locale/get-locale-from-pathname.js +1 -0
- package/dist/svelte-kit/src/routing/pathname/canonicalize-pathname.js +1 -0
- package/dist/svelte-kit/src/routing/pathname/materialize-pathname.js +1 -0
- package/dist/svelte-kit/src/routing/pathname/standardize-pathname.js +1 -0
- package/dist/svelte-kit/src/server/intor/intor.js +1 -0
- package/dist/svelte-kit/src/server/messages/load-local-messages/load-local-messages.js +1 -0
- package/dist/svelte-kit/src/server/messages/load-local-messages/read-locale-messages/collect-file-entries/collect-file-entries.js +1 -0
- package/dist/svelte-kit/src/server/messages/load-local-messages/read-locale-messages/parse-file-entries/parse-file-entries.js +1 -0
- package/dist/svelte-kit/src/server/messages/load-messages.js +1 -0
- package/dist/svelte-kit/src/server/translator/create-translator.js +5 -15
- package/dist/svelte-kit/src/server/translator/init-translator.js +6 -12
- package/dist/types/export/internal/index.d.ts +1 -1
- package/dist/types/export/svelte/index.d.ts +1 -1
- package/dist/types/src/client/react/render/index.d.ts +1 -1
- package/dist/types/src/client/react/render/types.d.ts +2 -6
- package/dist/types/src/client/react/translator/create-t-rich.d.ts +2 -2
- package/dist/types/src/client/react/translator/translator-instance.d.ts +1 -1
- package/dist/types/src/client/svelte/index.d.ts +1 -1
- package/dist/types/src/client/svelte/provider/index.d.ts +1 -0
- package/dist/types/src/client/svelte/provider/types.d.ts +4 -0
- package/dist/types/src/client/svelte/translator/translator-instance.d.ts +3 -4
- package/dist/types/src/client/vue/render/index.d.ts +1 -1
- package/dist/types/src/client/vue/render/types.d.ts +2 -6
- package/dist/types/src/client/vue/translator/create-t-rich.d.ts +2 -3
- package/dist/types/src/client/vue/translator/translator-instance.d.ts +1 -1
- package/dist/types/src/core/index.d.ts +2 -0
- package/dist/types/src/core/render/create-html-renderer.d.ts +11 -0
- package/dist/types/src/core/render/index.d.ts +2 -0
- package/dist/types/src/core/render/types.d.ts +10 -0
- package/dist/types/src/core/translator/create-t-rich.d.ts +12 -0
- package/dist/types/src/core/translator/index.d.ts +1 -0
- package/dist/types/src/server/helpers/get-translator.d.ts +4 -4
- package/dist/types/src/server/translator/create-translator.d.ts +5 -13
- package/dist/types/src/server/translator/init-translator.d.ts +6 -7
- package/dist/types/src/server/translator/translator-instance.d.ts +5 -3
- package/dist/vue/src/client/shared/helpers/get-client-locale.js +1 -0
- package/dist/vue/src/client/shared/messages/create-refetch-messages.js +1 -0
- package/dist/vue/src/client/vue/helpers/use-intor.js +1 -0
- package/dist/vue/src/client/vue/provider/effects/use-locale-effects.js +1 -0
- package/dist/vue/src/client/vue/render/create-vue-renderer.js +0 -1
- package/dist/vue/src/client/vue/translator/create-t-rich.js +6 -8
- package/dist/vue/src/client/vue/translator/use-translator.js +4 -6
- package/package.json +15 -15
- package/dist/react/src/client/react/render/render-rich-message-react.js +0 -22
- package/dist/svelte/src/client/svelte/render/render-rich-message-svelte.js +0 -20
- package/dist/svelte/src/client/svelte/translator/create-t-rich.js +0 -23
- package/dist/types/src/client/react/render/render-rich-message-react.d.ts +0 -14
- package/dist/types/src/client/svelte/render/create-svelte-renderer.d.ts +0 -14
- package/dist/types/src/client/svelte/render/index.d.ts +0 -2
- package/dist/types/src/client/svelte/render/render-rich-message-svelte.d.ts +0 -12
- package/dist/types/src/client/svelte/render/types.d.ts +0 -8
- package/dist/types/src/client/svelte/translator/create-t-rich.d.ts +0 -15
- package/dist/types/src/client/vue/render/render-rich-message-vue.d.ts +0 -14
- package/dist/vue/src/client/vue/render/render-rich-message-vue.js +0 -19
- /package/dist/{svelte/src/client/svelte → core/src/core}/render/utils/escape-html.js +0 -0
- /package/dist/types/src/{client/svelte → core}/render/utils/escape-html.d.ts +0 -0
- /package/dist/types/src/{client/svelte → core}/render/utils/render-attributes.d.ts +0 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { escapeHtml } from './escape-html.js';
|
|
2
|
+
|
|
3
|
+
function renderAttributes(attributes) {
|
|
4
|
+
if (!attributes)
|
|
5
|
+
return "";
|
|
6
|
+
return Object.entries(attributes)
|
|
7
|
+
.map(([key, value]) => {
|
|
8
|
+
if (value === true)
|
|
9
|
+
return ` ${key}`;
|
|
10
|
+
if (value == null)
|
|
11
|
+
return "";
|
|
12
|
+
return ` ${key}="${escapeHtml(String(value))}"`;
|
|
13
|
+
})
|
|
14
|
+
.join("");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { renderAttributes };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { renderRichMessage } from 'intor-translator';
|
|
2
|
+
import { createHtmlRenderer } from '../render/create-html-renderer.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Create an HTML-string rich translation function.
|
|
6
|
+
*
|
|
7
|
+
* - Resolves translated messages via `translator.t`
|
|
8
|
+
* - Renders semantic rich tags into escaped HTML strings
|
|
9
|
+
* - Supports optional scoped keys via `preKey`
|
|
10
|
+
*
|
|
11
|
+
* Can be used in any HTML-based environment (Astro, Svelte, SSR, etc.).
|
|
12
|
+
*/
|
|
13
|
+
const createTRich = (t) => {
|
|
14
|
+
return (key, tagRenderers, replacements) => {
|
|
15
|
+
const message = t(key, replacements);
|
|
16
|
+
const renderer = createHtmlRenderer(tagRenderers);
|
|
17
|
+
const nodes = renderRichMessage(message, renderer);
|
|
18
|
+
return nodes.join("");
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { createTRich };
|
|
@@ -4,6 +4,7 @@ import { useIntorContext } from 'intor/svelte';
|
|
|
4
4
|
import '../../../core/error/intor-error.js';
|
|
5
5
|
import 'logry';
|
|
6
6
|
import 'p-limit';
|
|
7
|
+
import 'intor-translator';
|
|
7
8
|
import { resolveNavigation } from '../../../routing/navigation/resolve-navigation.js';
|
|
8
9
|
import { goto } from '$app/navigation';
|
|
9
10
|
import { page } from '$app/state';
|
|
@@ -4,6 +4,7 @@ import '../../../core/error/intor-error.js';
|
|
|
4
4
|
import { normalizeQuery } from '../../../core/utils/normalizers/normalize-query.js';
|
|
5
5
|
import 'logry';
|
|
6
6
|
import 'p-limit';
|
|
7
|
+
import 'intor-translator';
|
|
7
8
|
import { resolveInbound } from '../../../routing/inbound/resolve-inbound.js';
|
|
8
9
|
import { getLocaleFromAcceptLanguage } from '../../../routing/locale/get-locale-from-accept-language.js';
|
|
9
10
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import '../../../core/error/intor-error.js';
|
|
2
2
|
import 'logry';
|
|
3
3
|
import 'p-limit';
|
|
4
|
+
import 'intor-translator';
|
|
4
5
|
import { intor as intor$1 } from '../../../server/intor/intor.js';
|
|
5
6
|
import 'node:path';
|
|
6
7
|
import 'node:fs/promises';
|
|
7
|
-
import 'intor-translator';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Initializes Intor for the current execution context.
|
|
@@ -2,6 +2,7 @@ import '../../../core/error/intor-error.js';
|
|
|
2
2
|
import { normalizeLocale } from '../../../core/utils/normalizers/normalize-locale.js';
|
|
3
3
|
import 'logry';
|
|
4
4
|
import 'p-limit';
|
|
5
|
+
import 'intor-translator';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Resolve the active locale from inbound routing configuration.
|
|
@@ -3,6 +3,7 @@ import '../../core/error/intor-error.js';
|
|
|
3
3
|
import { normalizePathname } from '../../core/utils/normalizers/normalize-pathname.js';
|
|
4
4
|
import 'logry';
|
|
5
5
|
import 'p-limit';
|
|
6
|
+
import 'intor-translator';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Standardizes a canonical pathname into an internal routing template
|
|
@@ -3,6 +3,7 @@ import pLimit from 'p-limit';
|
|
|
3
3
|
import '../../../core/error/intor-error.js';
|
|
4
4
|
import { normalizeCacheKey } from '../../../core/utils/normalizers/normalize-cache-key.js';
|
|
5
5
|
import { getLogger } from '../../../core/logger/get-logger.js';
|
|
6
|
+
import 'intor-translator';
|
|
6
7
|
import { getMessagesPool } from './cache/messages-pool.js';
|
|
7
8
|
import { readLocaleMessages } from './read-locale-messages/read-locale-messages.js';
|
|
8
9
|
|
|
@@ -3,6 +3,7 @@ import path from 'node:path';
|
|
|
3
3
|
import '../../../../../core/error/intor-error.js';
|
|
4
4
|
import { getLogger } from '../../../../../core/logger/get-logger.js';
|
|
5
5
|
import 'p-limit';
|
|
6
|
+
import 'intor-translator';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Recursively collects message file metadata under a given locale root.
|
|
@@ -5,6 +5,7 @@ import { getLogger } from '../../../../../core/logger/get-logger.js';
|
|
|
5
5
|
import 'p-limit';
|
|
6
6
|
import { isValidMessages } from '../../../../../core/messages/utils/is-valid-messages.js';
|
|
7
7
|
import { nestObjectFromPath } from '../../../../../core/messages/utils/nest-object-from-path.js';
|
|
8
|
+
import 'intor-translator';
|
|
8
9
|
import { jsonReader } from './utils/json-reader.js';
|
|
9
10
|
|
|
10
11
|
/**
|
|
@@ -2,6 +2,7 @@ import '../../core/error/intor-error.js';
|
|
|
2
2
|
import { resolveLoaderOptions } from '../../core/utils/resolve-loader-options.js';
|
|
3
3
|
import { getLogger } from '../../core/logger/get-logger.js';
|
|
4
4
|
import { loadRemoteMessages } from '../../core/messages/load-remote-messages/load-remote-messages.js';
|
|
5
|
+
import 'intor-translator';
|
|
5
6
|
import { loadLocalMessages } from './load-local-messages/load-local-messages.js';
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -2,17 +2,14 @@ import { Translator } from 'intor-translator';
|
|
|
2
2
|
import { mergeMessages } from '../../core/messages/merge-messages.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Create a server-side
|
|
5
|
+
* Create a server-side Translator instance for a fixed locale.
|
|
6
6
|
*
|
|
7
7
|
* - Merges static config messages with runtime-loaded messages
|
|
8
|
-
* -
|
|
9
|
-
* -
|
|
10
|
-
*
|
|
11
|
-
* The returned object is a read-only translation view
|
|
12
|
-
* and does not expose the underlying Translator instance.
|
|
8
|
+
* - Initializes a Translator bound to a specific locale
|
|
9
|
+
* - Injects fallback rules, handlers, and plugins from config
|
|
13
10
|
*/
|
|
14
11
|
function createTranslator(params) {
|
|
15
|
-
const { config, locale, messages,
|
|
12
|
+
const { config, locale, messages, handlers, plugins } = params;
|
|
16
13
|
// Merge static config messages with runtime-loaded messages
|
|
17
14
|
const finalMessages = mergeMessages(config.messages, messages, {
|
|
18
15
|
config,
|
|
@@ -27,14 +24,7 @@ function createTranslator(params) {
|
|
|
27
24
|
handlers,
|
|
28
25
|
plugins,
|
|
29
26
|
});
|
|
30
|
-
|
|
31
|
-
const scoped = preKey ? translator.scoped(preKey) : null;
|
|
32
|
-
return {
|
|
33
|
-
messages: finalMessages,
|
|
34
|
-
locale,
|
|
35
|
-
hasKey: scoped ? scoped.hasKey : translator.hasKey,
|
|
36
|
-
t: scoped ? scoped.t : translator.t,
|
|
37
|
-
};
|
|
27
|
+
return translator;
|
|
38
28
|
}
|
|
39
29
|
|
|
40
30
|
export { createTranslator };
|
|
@@ -2,19 +2,20 @@ import '../../core/error/intor-error.js';
|
|
|
2
2
|
import { resolveLoaderOptions } from '../../core/utils/resolve-loader-options.js';
|
|
3
3
|
import 'logry';
|
|
4
4
|
import 'p-limit';
|
|
5
|
+
import 'intor-translator';
|
|
5
6
|
import { loadMessages } from '../messages/load-messages.js';
|
|
6
7
|
import 'node:path';
|
|
7
8
|
import 'node:fs/promises';
|
|
8
9
|
import { createTranslator } from './create-translator.js';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
|
-
*
|
|
12
|
+
* Initialize a locale-bound Translator snapshot.
|
|
12
13
|
*
|
|
13
|
-
* -
|
|
14
|
-
* -
|
|
14
|
+
* - Resolves loader options and loads messages if configured
|
|
15
|
+
* - Creates an immutable Translator instance for server usage
|
|
15
16
|
*/
|
|
16
17
|
async function initTranslator(config, locale, options) {
|
|
17
|
-
const { readers, allowCacheWrite = false, fetch,
|
|
18
|
+
const { readers, allowCacheWrite = false, fetch, handlers, plugins, } = options;
|
|
18
19
|
const loader = resolveLoaderOptions(config, "server");
|
|
19
20
|
// Load messages
|
|
20
21
|
let messages = {};
|
|
@@ -29,14 +30,7 @@ async function initTranslator(config, locale, options) {
|
|
|
29
30
|
messages = loaded || {};
|
|
30
31
|
}
|
|
31
32
|
// Create immutable translator snapshot
|
|
32
|
-
return createTranslator({
|
|
33
|
-
config,
|
|
34
|
-
locale,
|
|
35
|
-
messages,
|
|
36
|
-
preKey,
|
|
37
|
-
handlers,
|
|
38
|
-
plugins,
|
|
39
|
-
});
|
|
33
|
+
return createTranslator({ config, locale, messages, handlers, plugins });
|
|
40
34
|
}
|
|
41
35
|
|
|
42
36
|
export { initTranslator };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export type {
|
|
1
|
+
export type { GenConfigKeys, GenConfig, TranslatorInstance, } from "../../src/core";
|
|
2
2
|
export type { TranslatorInstanceReact } from "../../src/client/react/translator/translator-instance";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createReactRenderer } from "./create-react-renderer";
|
|
2
2
|
export type { ReactTagRenderers } from "./types";
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
+
import type { TagRenderers } from "../../../core";
|
|
1
2
|
import type { Rich } from "intor-translator";
|
|
2
|
-
/** Renderer function for a semantic rich tag. */
|
|
3
|
-
type ReactTagRenderer = ((children: React.ReactNode[]) => React.ReactNode) | React.ReactNode;
|
|
4
3
|
/** Mapping of semantic rich tags to React renderers. */
|
|
5
|
-
export type ReactTagRenderers<RichSchema = Rich> =
|
|
6
|
-
[K in keyof RichSchema]: ReactTagRenderer;
|
|
7
|
-
} & Record<string, ReactTagRenderer>;
|
|
8
|
-
export {};
|
|
4
|
+
export type ReactTagRenderers<RichSchema = Rich> = TagRenderers<React.ReactNode, RichSchema>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ReactTagRenderers } from "../render";
|
|
2
|
-
import type
|
|
2
|
+
import { type Replacement, type TranslatorMethods } from "intor-translator";
|
|
3
3
|
/**
|
|
4
4
|
* Create a React-specific rich translation function.
|
|
5
5
|
*
|
|
@@ -12,4 +12,4 @@ import type { Replacement, Translator } from "intor-translator";
|
|
|
12
12
|
*
|
|
13
13
|
* Intended for React client usage only.
|
|
14
14
|
*/
|
|
15
|
-
export declare const createTRich: (
|
|
15
|
+
export declare const createTRich: (t: TranslatorMethods["t"]) => (key: string, tagRenderers?: ReactTagRenderers, replacements?: Replacement) => import("react/jsx-runtime").JSX.Element[];
|
|
@@ -12,5 +12,5 @@ export type TranslatorInstanceReact<M extends LocaleMessages, ReplacementSchema
|
|
|
12
12
|
/** Update the active locale. */
|
|
13
13
|
setLocale: (locale: Locale<M>) => void;
|
|
14
14
|
/** Translate a key into React nodes using semantic tags */
|
|
15
|
-
tRich: <K extends string = PK extends string ? ScopedKey<M, PK> : LocalizedKey<M>, RI = LocalizedRich<RichSchema, K>, RE = LocalizedReplacement<ReplacementSchema, K>>(key?: K | (string & {}), tagRenderers?: ReactTagRenderers<RI
|
|
15
|
+
tRich: <K extends string = PK extends string ? ScopedKey<M, PK> : LocalizedKey<M>, RI = LocalizedRich<RichSchema, K>, RE = LocalizedReplacement<ReplacementSchema, K>>(key?: K | (string & {}), tagRenderers?: ReactTagRenderers<RI> | ReactTagRenderers, replacements?: RE | Replacement) => JSX.Element[];
|
|
16
16
|
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { createIntorStore, IntorProvider, useIntorContext } from "./provider";
|
|
1
|
+
export { createIntorStore, IntorProvider, type IntorProviderProps, useIntorContext, } from "./provider";
|
|
2
2
|
export { useTranslator } from "./translator";
|
|
3
3
|
export { getClientLocale } from "../shared/helpers";
|
|
@@ -10,6 +10,10 @@ export interface IntorValue {
|
|
|
10
10
|
handlers?: TranslateHandlers;
|
|
11
11
|
plugins?: (TranslatorPlugin | TranslateHook)[];
|
|
12
12
|
}
|
|
13
|
+
export interface IntorProviderProps {
|
|
14
|
+
value: IntorValue;
|
|
15
|
+
children: () => any;
|
|
16
|
+
}
|
|
13
17
|
export interface IntorContextValue {
|
|
14
18
|
config: IntorResolvedConfig;
|
|
15
19
|
locale: Writable<Locale>;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { TranslatorInstance } from "../../../core";
|
|
3
|
-
import type { Readable, Writable } from "svelte/store";
|
|
1
|
+
import type { HtmlTagRenderers, TranslatorInstance } from "../../../core";
|
|
4
2
|
import { type Locale, type LocaleMessages, type LocalizedKey, type LocalizedReplacement, type LocalizedRich, type Replacement, type Rich, type ScopedKey } from "intor-translator";
|
|
3
|
+
import { type Readable, type Writable } from "svelte/store";
|
|
5
4
|
export type TranslatorInstanceSvelte<M extends LocaleMessages, ReplacementSchema = Replacement, RichSchema = Rich, PK extends string | undefined = undefined> = {
|
|
6
5
|
/** `messages`: The message object containing all translations. */
|
|
7
6
|
messages: Readable<M>;
|
|
@@ -16,5 +15,5 @@ export type TranslatorInstanceSvelte<M extends LocaleMessages, ReplacementSchema
|
|
|
16
15
|
/** Translate a given key into its string representation. */
|
|
17
16
|
t: Readable<TranslatorInstance<M, ReplacementSchema, PK>["t"]>;
|
|
18
17
|
/** Translate a key into an HTML string using semantic rich tags. */
|
|
19
|
-
tRich: Readable<(<K extends string = PK extends string ? ScopedKey<M, PK> : LocalizedKey<M>, RI = LocalizedRich<RichSchema, K>, RE = LocalizedReplacement<ReplacementSchema, K>>(key?: K | (string & {}), tagRenderers?:
|
|
18
|
+
tRich: Readable<(<K extends string = PK extends string ? ScopedKey<M, PK> : LocalizedKey<M>, RI = LocalizedRich<RichSchema, K>, RE = LocalizedReplacement<ReplacementSchema, K>>(key?: K | (string & {}), tagRenderers?: HtmlTagRenderers<RI> | HtmlTagRenderers, replacements?: RE | Replacement) => string)>;
|
|
20
19
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { createVueRenderer } from "./create-vue-renderer";
|
|
2
2
|
export type { VueTagRenderers } from "./types";
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
+
import type { TagRenderers } from "../../../core";
|
|
1
2
|
import type { Rich } from "intor-translator";
|
|
2
3
|
import type { VNodeChild } from "vue";
|
|
3
|
-
/** Renderer function for a semantic rich tag. */
|
|
4
|
-
type VueTagRenderer = (children: VNodeChild[]) => VNodeChild | VNodeChild;
|
|
5
4
|
/** Mapping of semantic rich tags to Vue renderers. */
|
|
6
|
-
export type VueTagRenderers<RichSchema = Rich> =
|
|
7
|
-
[K in keyof RichSchema]: VueTagRenderer;
|
|
8
|
-
} & Record<string, VueTagRenderer>;
|
|
9
|
-
export {};
|
|
5
|
+
export type VueTagRenderers<RichSchema = Rich> = TagRenderers<VNodeChild, RichSchema>;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { VueTagRenderers } from "../../../client/vue/render";
|
|
2
|
-
import type
|
|
3
|
-
import { type ComputedRef } from "vue";
|
|
2
|
+
import { type Replacement, type TranslatorMethods } from "intor-translator";
|
|
4
3
|
/**
|
|
5
4
|
* Create a Vue-specific rich translation function.
|
|
6
5
|
*
|
|
@@ -13,4 +12,4 @@ import { type ComputedRef } from "vue";
|
|
|
13
12
|
*
|
|
14
13
|
* Intended for Vue client usage only.
|
|
15
14
|
*/
|
|
16
|
-
export declare const createTRich: (
|
|
15
|
+
export declare const createTRich: (t: TranslatorMethods["t"]) => (key: string, tagRenderers?: VueTagRenderers, replacements?: Replacement) => import("vue").VNodeChild[];
|
|
@@ -12,5 +12,5 @@ export type TranslatorInstanceVue<M extends LocaleMessages, ReplacementSchema =
|
|
|
12
12
|
/** Update the active locale. */
|
|
13
13
|
setLocale: (locale: Locale<M>) => void;
|
|
14
14
|
/** Translate a key into React nodes using semantic tags */
|
|
15
|
-
tRich: <K extends string = PK extends string ? ScopedKey<M, PK> : LocalizedKey<M>, RI = LocalizedRich<RichSchema, K>, RE = LocalizedReplacement<ReplacementSchema, K>>(key?: K | (string & {}), tagRenderers?: VueTagRenderers<RI
|
|
15
|
+
tRich: <K extends string = PK extends string ? ScopedKey<M, PK> : LocalizedKey<M>, RI = LocalizedRich<RichSchema, K>, RE = LocalizedReplacement<ReplacementSchema, K>>(key?: K | (string & {}), tagRenderers?: VueTagRenderers<RI> | VueTagRenderers, replacements?: RE | Replacement) => VNodeChild[];
|
|
16
16
|
};
|
|
@@ -3,4 +3,6 @@ export { IntorError, IntorErrorCode } from "./error";
|
|
|
3
3
|
export { deepMerge, type PlainObject, type DeepMergeOverrideEvent, resolveLoaderOptions, normalizePathname, normalizeCacheKey, normalizeLocale, normalizeQuery, } from "./utils";
|
|
4
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
|
+
export { createHtmlRenderer, type TagRenderers, type HtmlTagRenderers, } from "./render";
|
|
7
|
+
export { createTRich } from "./translator";
|
|
6
8
|
export type { INTOR_GENERATED_KEY, IfGen, GenConfigKeys, GenConfig, GenMessages, GenLocale, GenReplacements, GenRich, TranslatorInstance, RoutingLocaleSource, RoutingLocaleCarrier, LocalePathPrefix, RuntimeFetch, } from "./types";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TagRenderers } from "./types";
|
|
2
|
+
import type { Renderer } from "intor-translator";
|
|
3
|
+
/**
|
|
4
|
+
* Create an HTML string renderer for semantic rich messages.
|
|
5
|
+
*
|
|
6
|
+
* - Transforms semantic rich AST nodes into escaped HTML strings.
|
|
7
|
+
* - Can be used in any HTML-based environment.
|
|
8
|
+
*
|
|
9
|
+
* This renderer is intentionally minimal and stateless.
|
|
10
|
+
*/
|
|
11
|
+
export declare const createHtmlRenderer: (tagRenderers?: TagRenderers) => Renderer<string>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Rich } from "intor-translator";
|
|
2
|
+
/** Renderer function for a semantic rich tag. */
|
|
3
|
+
type TagRenderer<Output = string> = ((children: Output[]) => Output) | Output;
|
|
4
|
+
/** Core mapping of semantic rich tags to renderers. */
|
|
5
|
+
export type TagRenderers<Output = string, RichSchema = Rich> = {
|
|
6
|
+
[K in keyof RichSchema]: TagRenderer<Output>;
|
|
7
|
+
} & Record<string, TagRenderer<Output>>;
|
|
8
|
+
/** Mapping of semantic rich tags to HTML string renderers. */
|
|
9
|
+
export type HtmlTagRenderers<RichSchema = Rich> = TagRenderers<string, RichSchema>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Replacement, type TranslatorMethods } from "intor-translator";
|
|
2
|
+
import { type TagRenderers } from "../render";
|
|
3
|
+
/**
|
|
4
|
+
* Create an HTML-string rich translation function.
|
|
5
|
+
*
|
|
6
|
+
* - Resolves translated messages via `translator.t`
|
|
7
|
+
* - Renders semantic rich tags into escaped HTML strings
|
|
8
|
+
* - Supports optional scoped keys via `preKey`
|
|
9
|
+
*
|
|
10
|
+
* Can be used in any HTML-based environment (Astro, Svelte, SSR, etc.).
|
|
11
|
+
*/
|
|
12
|
+
export declare const createTRich: (t: TranslatorMethods["t"]) => (key: string, tagRenderers?: TagRenderers, replacements?: Replacement) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createTRich } from "./create-t-rich";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { TranslatorInstanceServer } from "../translator/translator-instance";
|
|
2
2
|
import type { IntorResolvedConfig } from "../../config";
|
|
3
|
-
import type { GenConfigKeys, GenMessages, GenReplacements, MessagesReaders, RuntimeFetch } from "../../core";
|
|
4
3
|
import type { LocalizedPreKey, TranslateHandlers, TranslateHook, TranslatorPlugin } from "intor-translator";
|
|
4
|
+
import { type GenConfigKeys, type GenMessages, type GenReplacements, type GenRich, type MessagesReaders, type RuntimeFetch } from "../../core";
|
|
5
5
|
export interface GetTranslatorParams {
|
|
6
6
|
locale: string;
|
|
7
7
|
readers?: MessagesReaders;
|
|
@@ -13,7 +13,7 @@ export interface GetTranslatorParams {
|
|
|
13
13
|
/**
|
|
14
14
|
* Get a server-side translator for the current execution context.
|
|
15
15
|
*/
|
|
16
|
-
export declare function getTranslator<CK extends GenConfigKeys = "__default__", ReplacementSchema = GenReplacements<CK>>(config: IntorResolvedConfig, params: GetTranslatorParams): Promise<TranslatorInstanceServer<GenMessages<CK>, ReplacementSchema>>;
|
|
17
|
-
export declare function getTranslator<CK extends GenConfigKeys = "__default__", ReplacementSchema = GenReplacements<CK>, PK extends string = LocalizedPreKey<GenMessages<CK>>>(config: IntorResolvedConfig, params: GetTranslatorParams & {
|
|
16
|
+
export declare function getTranslator<CK extends GenConfigKeys = "__default__", ReplacementSchema = GenReplacements<CK>, RichSchema = GenRich<CK>>(config: IntorResolvedConfig, params: GetTranslatorParams): Promise<TranslatorInstanceServer<GenMessages<CK>, ReplacementSchema, RichSchema, undefined>>;
|
|
17
|
+
export declare function getTranslator<CK extends GenConfigKeys = "__default__", ReplacementSchema = GenReplacements<CK>, RichSchema = GenRich<CK>, PK extends string = LocalizedPreKey<GenMessages<CK>>>(config: IntorResolvedConfig, params: GetTranslatorParams & {
|
|
18
18
|
preKey?: PK;
|
|
19
|
-
}): Promise<TranslatorInstanceServer<GenMessages<CK>, ReplacementSchema, PK>>;
|
|
19
|
+
}): Promise<TranslatorInstanceServer<GenMessages<CK>, ReplacementSchema, RichSchema, PK>>;
|
|
@@ -1,26 +1,18 @@
|
|
|
1
1
|
import type { IntorResolvedConfig } from "../../config";
|
|
2
2
|
import type { LocaleMessages, TranslateHandlers, TranslateHook, TranslatorPlugin } from "intor-translator";
|
|
3
|
+
import { Translator } from "intor-translator";
|
|
3
4
|
export interface CreateTranslatorParams {
|
|
4
5
|
config: IntorResolvedConfig;
|
|
5
6
|
locale: string;
|
|
6
7
|
messages: LocaleMessages;
|
|
7
|
-
preKey?: string;
|
|
8
8
|
handlers?: TranslateHandlers;
|
|
9
9
|
plugins?: (TranslatorPlugin | TranslateHook)[];
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
|
-
* Create a server-side
|
|
12
|
+
* Create a server-side Translator instance for a fixed locale.
|
|
13
13
|
*
|
|
14
14
|
* - Merges static config messages with runtime-loaded messages
|
|
15
|
-
* -
|
|
16
|
-
* -
|
|
17
|
-
*
|
|
18
|
-
* The returned object is a read-only translation view
|
|
19
|
-
* and does not expose the underlying Translator instance.
|
|
15
|
+
* - Initializes a Translator bound to a specific locale
|
|
16
|
+
* - Injects fallback rules, handlers, and plugins from config
|
|
20
17
|
*/
|
|
21
|
-
export declare function createTranslator(params: CreateTranslatorParams):
|
|
22
|
-
messages: LocaleMessages;
|
|
23
|
-
locale: string;
|
|
24
|
-
hasKey: <K extends string>(key: K, targetLocale?: string | undefined) => boolean;
|
|
25
|
-
t: <K extends string = string>(key: K, replacements?: import("intor-translator").Replacement | undefined) => string;
|
|
26
|
-
};
|
|
18
|
+
export declare function createTranslator(params: CreateTranslatorParams): Translator<unknown>;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import type { TranslatorInstanceServer } from "./translator-instance";
|
|
2
1
|
import type { IntorResolvedConfig } from "../../config";
|
|
3
|
-
import type { Locale,
|
|
2
|
+
import type { Locale, Translator } from "intor-translator";
|
|
4
3
|
import { type LoadMessagesParams } from "../messages";
|
|
5
4
|
import { type CreateTranslatorParams } from "./create-translator";
|
|
6
|
-
export interface InitTranslatorOptions extends Pick<LoadMessagesParams, "readers" | "allowCacheWrite" | "fetch">, Pick<CreateTranslatorParams, "
|
|
5
|
+
export interface InitTranslatorOptions extends Pick<LoadMessagesParams, "readers" | "allowCacheWrite" | "fetch">, Pick<CreateTranslatorParams, "handlers" | "plugins"> {
|
|
7
6
|
}
|
|
8
7
|
/**
|
|
9
|
-
*
|
|
8
|
+
* Initialize a locale-bound Translator snapshot.
|
|
10
9
|
*
|
|
11
|
-
* -
|
|
12
|
-
* -
|
|
10
|
+
* - Resolves loader options and loads messages if configured
|
|
11
|
+
* - Creates an immutable Translator instance for server usage
|
|
13
12
|
*/
|
|
14
|
-
export declare function initTranslator(config: IntorResolvedConfig, locale: Locale, options: InitTranslatorOptions): Promise<
|
|
13
|
+
export declare function initTranslator(config: IntorResolvedConfig, locale: Locale, options: InitTranslatorOptions): Promise<Translator<unknown>>;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import type { TranslatorInstance } from "../../core";
|
|
2
|
-
import { type Locale, type LocaleMessages, type Replacement } from "intor-translator";
|
|
3
|
-
export type TranslatorInstanceServer<M extends LocaleMessages, ReplacementSchema = Replacement, PK extends string | undefined = undefined> = TranslatorInstance<M, ReplacementSchema, PK> & {
|
|
1
|
+
import type { HtmlTagRenderers, TranslatorInstance } from "../../core";
|
|
2
|
+
import { type Locale, type LocaleMessages, type LocalizedKey, type LocalizedReplacement, type LocalizedRich, type Replacement, type Rich, type ScopedKey } from "intor-translator";
|
|
3
|
+
export type TranslatorInstanceServer<M extends LocaleMessages, ReplacementSchema = Replacement, RichSchema = Rich, PK extends string | undefined = undefined> = TranslatorInstance<M, ReplacementSchema, PK> & {
|
|
4
4
|
/** `messages`: The message object containing all translations. */
|
|
5
5
|
messages: M;
|
|
6
6
|
/** Current locale in use. */
|
|
7
7
|
locale: Locale<M>;
|
|
8
|
+
/** Translate a key into an HTML string using semantic rich tags. */
|
|
9
|
+
tRich: <K extends string = PK extends string ? ScopedKey<M, PK> : LocalizedKey<M>, RI = LocalizedRich<RichSchema, K>, RE = LocalizedReplacement<ReplacementSchema, K>>(key?: K | (string & {}), tagRenderers?: HtmlTagRenderers<RI> | HtmlTagRenderers, replacements?: RE | Replacement) => string;
|
|
8
10
|
};
|
|
@@ -2,6 +2,7 @@ import '../../../core/error/intor-error.js';
|
|
|
2
2
|
import { normalizeLocale } from '../../../core/utils/normalizers/normalize-locale.js';
|
|
3
3
|
import 'logry';
|
|
4
4
|
import 'p-limit';
|
|
5
|
+
import 'intor-translator';
|
|
5
6
|
import { detectBrowserLocale } from '../utils/locale/detect-browser-locale.js';
|
|
6
7
|
import { getLocaleFromCookie } from '../utils/locale/get-locale-from-cookie.js';
|
|
7
8
|
|
|
@@ -3,6 +3,7 @@ import { resolveLoaderOptions } from '../../../core/utils/resolve-loader-options
|
|
|
3
3
|
import 'logry';
|
|
4
4
|
import { loadRemoteMessages } from '../../../core/messages/load-remote-messages/load-remote-messages.js';
|
|
5
5
|
import { mergeMessages } from '../../../core/messages/merge-messages.js';
|
|
6
|
+
import 'intor-translator';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Creates a framework-agnostic message refetcher.
|
|
@@ -3,6 +3,7 @@ import '../../../core/error/intor-error.js';
|
|
|
3
3
|
import 'logry';
|
|
4
4
|
import 'p-limit';
|
|
5
5
|
import { mergeMessages } from '../../../core/messages/merge-messages.js';
|
|
6
|
+
import 'intor-translator';
|
|
6
7
|
import { getClientLocale } from '../../shared/helpers/get-client-locale.js';
|
|
7
8
|
|
|
8
9
|
function useIntor(config, loader) {
|
|
@@ -3,6 +3,7 @@ import { shouldPersistOnFirstVisit } from '../../../../policies/should-persist-o
|
|
|
3
3
|
import '../../../../core/error/intor-error.js';
|
|
4
4
|
import 'logry';
|
|
5
5
|
import 'p-limit';
|
|
6
|
+
import 'intor-translator';
|
|
6
7
|
import { getLocaleFromCookie } from '../../../shared/utils/locale/get-locale-from-cookie.js';
|
|
7
8
|
import { setLocaleCookie } from '../../../shared/utils/locale/set-locale-cookie.js';
|
|
8
9
|
import { setDocumentLocale } from '../../../shared/utils/locale/set-document-locale.js';
|
|
@@ -11,7 +11,6 @@ const createVueRenderer = (tagRenderers) => {
|
|
|
11
11
|
},
|
|
12
12
|
/** Render semantic tag nodes */
|
|
13
13
|
tag(name, _attributes, children) {
|
|
14
|
-
// Custom tag renderer
|
|
15
14
|
const tagRenderer = tagRenderers?.[name];
|
|
16
15
|
if (tagRenderer) {
|
|
17
16
|
return typeof tagRenderer === "function"
|