@fluentic/i18n 0.1.0-beta.1 → 0.1.0-beta.2
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/CHANGELOG.md +13 -0
- package/README.md +9 -1
- package/dist/adapter.d.ts +6 -4
- package/dist/adapter.js +4 -3
- package/dist/compiled.d.ts +26 -24
- package/dist/compiled.js +4 -2
- package/dist/compiled.js.map +1 -1
- package/dist/compiler-support.d.ts +4 -0
- package/dist/compiler-support.js +4 -0
- package/dist/core/format.d.ts +11 -0
- package/dist/core/i18n.d.ts +26 -0
- package/dist/core/index.d.ts +1 -5
- package/dist/core/index.js +3 -2
- package/dist/core/types.d.ts +79 -0
- package/dist/hash-VJlyT31Z.js +90 -0
- package/dist/hash-VJlyT31Z.js.map +1 -0
- package/dist/hydration-store-BK6UxrtJ.js +13 -0
- package/dist/hydration-store-BK6UxrtJ.js.map +1 -0
- package/dist/hydration-store.d.ts +29 -0
- package/dist/hydration.d.ts +7 -0
- package/dist/hydration.js +35 -0
- package/dist/hydration.js.map +1 -0
- package/dist/index.d.ts +6 -6
- package/dist/index.js +3 -2
- package/dist/{interpreter-Dld8QyOI.js → interpreter-BfzvLLrD.js} +4 -3
- package/dist/interpreter-BfzvLLrD.js.map +1 -0
- package/dist/{manager-BW778X1Y.js → manager-BgMJWXWY.js} +21 -31
- package/dist/manager-BgMJWXWY.js.map +1 -0
- package/dist/manager.d.ts +62 -0
- package/dist/message-D4jK2Lzc.js +9 -0
- package/dist/message-D4jK2Lzc.js.map +1 -0
- package/dist/react.d.ts +41 -46
- package/dist/react.js +12 -8
- package/dist/react.js.map +1 -1
- package/dist/registry-manager.d.ts +7 -0
- package/dist/runtime-DXnGeCBw.js +110 -0
- package/dist/runtime-DXnGeCBw.js.map +1 -0
- package/dist/shared/compact.d.ts +5 -0
- package/dist/shared/formatting.d.ts +11 -0
- package/dist/shared/hash.d.ts +7 -0
- package/dist/shared/interpreter.d.ts +2 -0
- package/dist/shared/message.d.ts +2 -0
- package/dist/shared/runtime.d.ts +49 -0
- package/dist/{src-BovRx-mX.js → src-ON68XIog.js} +9 -7
- package/dist/src-ON68XIog.js.map +1 -0
- package/dist/state-manager.d.ts +6 -0
- package/dist/state.d.ts +8 -0
- package/dist/storage-manager.d.ts +14 -0
- package/dist/{translation-manager-C79eKu2K.js → translation-manager-BkmFnlb_.js} +5 -104
- package/dist/translation-manager-BkmFnlb_.js.map +1 -0
- package/dist/translation-manager.d.ts +34 -0
- package/dist/translation.d.ts +20 -0
- package/dist/types-BkDsJfVD.js.map +1 -1
- package/dist/types.d.ts +3 -2
- package/package.json +20 -54
- package/dist/adapter-CWC8rng-.d.ts +0 -178
- package/dist/analyze-CdXCxQDg.d.ts +0 -14
- package/dist/compact-CJ0OWoIv.d.ts +0 -7
- package/dist/compiler-BZtB9WLi.js +0 -365
- package/dist/compiler-BZtB9WLi.js.map +0 -1
- package/dist/compiler.d.ts +0 -35
- package/dist/compiler.js +0 -3
- package/dist/i18n-CfYNwubL.d.ts +0 -25
- package/dist/interpreter-Dld8QyOI.js.map +0 -1
- package/dist/manager-BW778X1Y.js.map +0 -1
- package/dist/options-DE7vYj0e.d.ts +0 -7
- package/dist/options-Dxxx0aOz.js +0 -23
- package/dist/options-Dxxx0aOz.js.map +0 -1
- package/dist/plugin/babel.d.ts +0 -11
- package/dist/plugin/babel.js +0 -31
- package/dist/plugin/babel.js.map +0 -1
- package/dist/plugin/esbuild.d.ts +0 -7
- package/dist/plugin/esbuild.js +0 -37
- package/dist/plugin/esbuild.js.map +0 -1
- package/dist/plugin/rollup.d.ts +0 -30
- package/dist/plugin/rollup.js +0 -34
- package/dist/plugin/rollup.js.map +0 -1
- package/dist/plugin/vite.d.ts +0 -31
- package/dist/plugin/vite.js +0 -11
- package/dist/plugin/vite.js.map +0 -1
- package/dist/plugin/webpack-loader.d.ts +0 -3
- package/dist/plugin/webpack-loader.js +0 -21
- package/dist/plugin/webpack-loader.js.map +0 -1
- package/dist/plugin/webpack.d.ts +0 -8
- package/dist/plugin/webpack.js +0 -22
- package/dist/plugin/webpack.js.map +0 -1
- package/dist/src-BovRx-mX.js.map +0 -1
- package/dist/translation-manager-C79eKu2K.js.map +0 -1
- package/dist/types-BuGoCU3P.d.ts +0 -75
- package/dist-cjs/babel.cjs +0 -379
- package/dist-cjs/babel.cjs.map +0 -1
- package/src/adapter.ts +0 -6
- package/src/compiled.ts +0 -116
- package/src/compiler/analyze.ts +0 -182
- package/src/compiler/index.ts +0 -208
- package/src/compiler/message.ts +0 -74
- package/src/core/format.ts +0 -40
- package/src/core/i18n.ts +0 -124
- package/src/core/index.ts +0 -1
- package/src/core/types.ts +0 -121
- package/src/index.ts +0 -9
- package/src/manager.ts +0 -175
- package/src/plugin/babel.ts +0 -34
- package/src/plugin/esbuild.ts +0 -45
- package/src/plugin/options.ts +0 -24
- package/src/plugin/rollup.ts +0 -29
- package/src/plugin/vite.ts +0 -6
- package/src/plugin/webpack-loader.ts +0 -22
- package/src/plugin/webpack.ts +0 -15
- package/src/react.ts +0 -97
- package/src/registry-manager.ts +0 -3
- package/src/shared/compact.ts +0 -51
- package/src/shared/formatting.ts +0 -121
- package/src/shared/interpreter.ts +0 -128
- package/src/shared/runtime.ts +0 -131
- package/src/state-manager.ts +0 -29
- package/src/state.ts +0 -20
- package/src/storage-manager.ts +0 -47
- package/src/translation-manager.ts +0 -82
- package/src/translation.ts +0 -106
- package/src/types.ts +0 -2
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as normalizeMessage } from "./message-D4jK2Lzc.js";
|
|
2
|
+
import { a as getFormats, c as renderJsxCallback, d as setLanguageId, f as setRuntimeResolver, i as defaultRuntime, l as setFormats, m as withRuntime, n as createRuntime, o as getRuntime, p as setTranslationGetter, r as createTagHandler, s as noTranslate, t as I18nRegistry, u as setGetJsxHandler } from "./runtime-DXnGeCBw.js";
|
|
2
3
|
import { t as isMessageDescriptor } from "./types-BkDsJfVD.js";
|
|
3
|
-
import { n as createFormatting, t as interpret } from "./interpreter-
|
|
4
|
-
import {
|
|
5
|
-
import { bytesToHex } from "@noble/hashes/utils";
|
|
4
|
+
import { n as createFormatting, t as interpret } from "./interpreter-BfzvLLrD.js";
|
|
5
|
+
import { i as messageHash } from "./hash-VJlyT31Z.js";
|
|
6
6
|
import { IntlMessageFormat } from "intl-messageformat";
|
|
7
7
|
// \0rolldown/runtime.js
|
|
8
8
|
var __defProp = Object.defineProperty;
|
|
@@ -44,6 +44,7 @@ function createT({ getText, getJsx }) {
|
|
|
44
44
|
return getText(toFormatOptions(message, params, scope));
|
|
45
45
|
},
|
|
46
46
|
jsx(message, params) {
|
|
47
|
+
if (typeof message === "function") return renderJsxCallback(message);
|
|
47
48
|
return getJsx(toFormatOptions(message, params, scope));
|
|
48
49
|
}
|
|
49
50
|
};
|
|
@@ -51,7 +52,7 @@ function createT({ getText, getJsx }) {
|
|
|
51
52
|
const createDescriptor = (message, schema, scope) => {
|
|
52
53
|
return Object.freeze({
|
|
53
54
|
__fluenticMessage: true,
|
|
54
|
-
text: Array.isArray(message) ? message[0] : message,
|
|
55
|
+
text: Array.isArray(message) ? message[0] : normalizeMessage(message),
|
|
55
56
|
...Array.isArray(message) ? { compiled: message } : {},
|
|
56
57
|
context: scope.context,
|
|
57
58
|
schema: schema ?? {},
|
|
@@ -107,6 +108,7 @@ var format_exports = /* @__PURE__ */ __exportAll({
|
|
|
107
108
|
getRuntime: () => getRuntime,
|
|
108
109
|
getText: () => getText,
|
|
109
110
|
noTranslate: () => noTranslate,
|
|
111
|
+
renderJsxCallback: () => renderJsxCallback,
|
|
110
112
|
setFormats: () => setFormats,
|
|
111
113
|
setGetJsxHandler: () => setGetJsxHandler,
|
|
112
114
|
setLanguageId: () => setLanguageId,
|
|
@@ -130,7 +132,7 @@ const formatting = /* @__PURE__ */ createFormatting((message, languageId, format
|
|
|
130
132
|
cache.set(key, formatter);
|
|
131
133
|
}
|
|
132
134
|
return formatter.formatToParts(values).map((part) => part.value);
|
|
133
|
-
}, false, (context, message) =>
|
|
135
|
+
}, false, (context, message) => messageHash(context ? `${context}\0${message}` : message));
|
|
134
136
|
const getText = (...args) => formatting.getText(...args);
|
|
135
137
|
const getJsx = (...args) => formatting.getJsx(...args);
|
|
136
138
|
const getMessageParts = (...args) => formatting.getMessageParts(...args);
|
|
@@ -139,4 +141,4 @@ const formatMessage = getText;
|
|
|
139
141
|
const t = /* @__PURE__ */ createT(format_exports);
|
|
140
142
|
export { t };
|
|
141
143
|
|
|
142
|
-
//# sourceMappingURL=src-
|
|
144
|
+
//# sourceMappingURL=src-ON68XIog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"src-ON68XIog.js","names":["formatting"],"sources":["../src/core/i18n.ts","../src/core/format.ts","../src/index.ts"],"sourcesContent":["import type { Formatting } from '../shared/formatting';\nimport { normalizeMessage } from '../shared/message';\nimport { createTagHandler, getRuntime, noTranslate, renderJsxCallback } from '../shared/runtime';\nimport type { I18nJsxOutput, I18nTagElement, I18nTagValue } from './types';\nimport { isMessageDescriptor } from './types';\nimport type {\n JsxRenderer,\n MessageDescriptor,\n MessageInput,\n MessageMeta,\n MessageParams,\n MessageSchema,\n MessageTagHandler,\n TextRenderer,\n TryRenderArgs,\n} from './types';\n\ntype MessageScope = { context: string | null; notes: string[]; meta?: MessageMeta; };\n\nexport type MessageApi<JsxOutput = unknown> = {\n context(name: string): MessageApi<JsxOutput>;\n note(note: string): MessageApi<JsxOutput>;\n meta(meta: MessageMeta): MessageApi<JsxOutput>;\n msg<const Text extends string, const Schema extends MessageSchema | undefined = undefined>(\n message: Text,\n schema?: Schema,\n ): MessageDescriptor<Text, Schema>;\n text: TextRenderer;\n jsx: JsxRenderer<JsxOutput>;\n};\n\nexport type TApi<JsxOutput = unknown, TagValue = unknown> = MessageApi<JsxOutput> & {\n clone<const Text extends string, const Schema extends MessageSchema | undefined>(\n message: MessageDescriptor<Text, Schema>,\n ): MessageDescriptor<Text, Schema>;\n params<Params extends MessageParams>(params?: Params | null): Params;\n tag(element: I18nTagElement): MessageTagHandler<I18nTagValue, I18nTagElement>;\n tag<T = TagValue, R = TagValue>(handler: (chunks: Array<string | T>) => R): MessageTagHandler<T, R>;\n try<T>(\n renderer: TextRenderer,\n value: T,\n ...args: TryRenderArgs<T>\n ): T extends { readonly __fluenticMessage: true; } ? string : T;\n try<T>(\n renderer: JsxRenderer<JsxOutput>,\n value: T,\n ...args: TryRenderArgs<T>\n ): T extends { readonly __fluenticMessage: true; } ? JsxOutput : T;\n notranslate: typeof noTranslate;\n};\n\nexport function createT({ getText, getJsx }: Formatting): TApi<I18nJsxOutput, I18nTagValue> {\n const createScope = (scope: MessageScope): MessageApi => {\n return {\n context(name) {\n return createScope({ ...scope, context: scope.context ? `${scope.context}.${name}` : name });\n },\n note(note) {\n return createScope({ ...scope, notes: [...scope.notes, note] });\n },\n meta(meta) {\n return createScope({ ...scope, meta });\n },\n msg(message, schema) {\n return createDescriptor(message, schema, scope);\n },\n text(message: MessageInput, params?: MessageParams) {\n return getText(toFormatOptions(message, params, scope));\n },\n jsx(message: MessageInput | (() => I18nTagElement), params?: MessageParams) {\n if (typeof message === 'function') return renderJsxCallback(message);\n\n return getJsx(toFormatOptions(message, params, scope));\n },\n };\n };\n\n const createDescriptor = <const Text extends string, const Schema extends MessageSchema | undefined>(\n message: Text,\n schema: Schema | undefined,\n scope: MessageScope,\n ): MessageDescriptor<Text, Schema> => {\n return Object.freeze({\n __fluenticMessage: true,\n text: Array.isArray(message) ? message[0] : normalizeMessage(message),\n ...(Array.isArray(message) ? { compiled: message } : {}),\n context: scope.context,\n schema: schema ?? {},\n notes: scope.notes,\n meta: scope.meta,\n }) as unknown as MessageDescriptor<Text, Schema>;\n };\n\n const toFormatOptions = (message: MessageInput, params: MessageParams | undefined, scope: MessageScope) => {\n if (isMessageDescriptor(message)) return { msg: message, params };\n\n return { msg: createDescriptor(message, undefined, scope), params };\n };\n\n const rootScope = createScope({ context: null, notes: [] });\n\n return Object.assign(rootScope, {\n clone(message: MessageDescriptor) {\n return Object.freeze({ ...message });\n },\n params<Params extends MessageParams>(params?: Params | null): Params {\n return (params ?? {}) as Params;\n },\n tag<T = unknown, R = unknown>(handler: (chunks: Array<string | T>) => R) {\n if (typeof handler !== 'function') {\n const adapt = getRuntime().tagElement;\n\n if (!adapt) throw new Error('[i18n] element tags require a platform adapter');\n\n return createTagHandler(adapt(handler));\n }\n\n return createTagHandler(handler);\n },\n try<T>(renderer: TextRenderer | JsxRenderer, value: T, params?: MessageParams) {\n return isMessageDescriptor(value)\n ? (renderer as (message: MessageInput, params?: MessageParams) => unknown)(value, params)\n : value;\n },\n notranslate: noTranslate,\n }) as TApi<I18nJsxOutput, I18nTagValue>;\n}\n","import { IntlMessageFormat } from 'intl-messageformat';\nimport { createFormatting } from '../shared/formatting';\nimport { messageHash } from '../shared/hash';\nimport { interpret } from '../shared/interpreter';\n\nconst cache = new Map<string, IntlMessageFormat>();\nconst formatting = /* @__PURE__ */ createFormatting(\n (message, languageId, formats, values, compiled) => {\n if (compiled) return interpret(message, languageId, formats, values, true);\n if (typeof message !== 'string') throw new TypeError('[i18n] invalid translation');\n\n const key = JSON.stringify([message, languageId, formats]);\n\n let formatter = cache.get(key);\n\n if (!formatter) {\n formatter = new IntlMessageFormat(\n message,\n languageId,\n formats as ConstructorParameters<typeof IntlMessageFormat>[2],\n );\n if (cache.size >= 500) cache.delete(cache.keys().next().value!);\n cache.set(key, formatter);\n }\n\n return formatter.formatToParts(values as Parameters<IntlMessageFormat['formatToParts']>[0]).map((part) =>\n part.value\n );\n },\n false,\n (context, message) => messageHash(context ? `${context}\\0${message}` : message),\n);\nexport * from '../shared/runtime';\n\nexport const getText = (...args: Parameters<typeof formatting.getText>) => formatting.getText(...args);\nexport const getJsx = (...args: Parameters<typeof formatting.getJsx>) => formatting.getJsx(...args);\nexport const getMessageParts = (...args: Parameters<typeof formatting.getMessageParts>) =>\n formatting.getMessageParts(...args);\nexport const formatMessage = getText;\n","import * as formatting from './core/format';\nimport { createT } from './core/i18n';\n\nexport const t = /* @__PURE__ */ createT(formatting);\nexport type { MessageApi, TApi } from './core/i18n';\nexport * from './core/types';\nexport { I18nRegistry, noTranslate, setFormats } from './shared/runtime';\nexport { defineTranslationLoader } from './translation-manager';\nexport type { TranslationData, TranslationItem, TranslationLoader, TranslationLoaderMap } from './translation-manager';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAmDA,SAAgB,QAAQ,EAAE,SAAS,UAAyD;CAC1F,MAAM,eAAe,UAAoC;EACvD,OAAO;GACL,QAAQ,MAAM;IACZ,OAAO,YAAY;KAAE,GAAG;KAAO,SAAS,MAAM,UAAU,GAAG,MAAM,QAAQ,GAAG,SAAS;IAAK,CAAC;GAC7F;GACA,KAAK,MAAM;IACT,OAAO,YAAY;KAAE,GAAG;KAAO,OAAO,CAAC,GAAG,MAAM,OAAO,IAAI;IAAE,CAAC;GAChE;GACA,KAAK,MAAM;IACT,OAAO,YAAY;KAAE,GAAG;KAAO;IAAK,CAAC;GACvC;GACA,IAAI,SAAS,QAAQ;IACnB,OAAO,iBAAiB,SAAS,QAAQ,KAAK;GAChD;GACA,KAAK,SAAuB,QAAwB;IAClD,OAAO,QAAQ,gBAAgB,SAAS,QAAQ,KAAK,CAAC;GACxD;GACA,IAAI,SAAgD,QAAwB;IAC1E,IAAI,OAAO,YAAY,YAAY,OAAO,kBAAkB,OAAO;IAEnE,OAAO,OAAO,gBAAgB,SAAS,QAAQ,KAAK,CAAC;GACvD;EACF;CACF;CAEA,MAAM,oBACJ,SACA,QACA,UACoC;EACpC,OAAO,OAAO,OAAO;GACnB,mBAAmB;GACnB,MAAM,MAAM,QAAQ,OAAO,IAAI,QAAQ,KAAK,iBAAiB,OAAO;GACpE,GAAI,MAAM,QAAQ,OAAO,IAAI,EAAE,UAAU,QAAQ,IAAI,CAAC;GACtD,SAAS,MAAM;GACf,QAAQ,UAAU,CAAC;GACnB,OAAO,MAAM;GACb,MAAM,MAA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AAC,CAAC,KAAM;EAC9D,MAAM,IAAI,KAAK,SAAS;CAC1B;CAEA,OAAO,UAAU,cAAc,MAA2D,CAAC,CAAC,KAAK,SAC/F,KAAK,KACP;AACF,GACA,QACC,SAAS,YAAY,YAAY,UAAU,GAAG,QAAQ,IAAI,YAAY,OAAO,CAChF;AAGA,MAAa,WAAW,GAAG,SAAgD,WAAW,QAAQ,GAAG,IAAI;AACrG,MAAa,UAAU,GAAG,SAA+C,WAAW,OAAO,GAAG,IAAI;AAClG,MAAa,mBAAmB,GAAG,SACjC,WAAW,gBAAgB,GAAG,IAAI;AACpC,MAAa,gBAAgB;;ACnC7B,MAAa,IAAoB,wBAAQA,cAAU"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type StateManager<StateData> = {
|
|
2
|
+
get(): StateData;
|
|
3
|
+
subscribe(listener: () => void): () => void;
|
|
4
|
+
set(partial: Partial<StateData>): void;
|
|
5
|
+
};
|
|
6
|
+
export declare function createStateManager<StateData extends object>(initial: StateData): StateManager<StateData>;
|
package/dist/state.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type StateData } from './manager';
|
|
2
|
+
export type { StateData } from './manager';
|
|
3
|
+
export declare const I18nState: {
|
|
4
|
+
get(): StateData;
|
|
5
|
+
subscribe(listener: () => void): () => void;
|
|
6
|
+
use(): StateData;
|
|
7
|
+
};
|
|
8
|
+
export declare function updateState(next: Partial<StateData>): void;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { LanguageId } from './core/types';
|
|
2
|
+
export type StoredState = {
|
|
3
|
+
languageId: LanguageId;
|
|
4
|
+
};
|
|
5
|
+
export type I18nStorage = {
|
|
6
|
+
read(): StoredState | null | Promise<StoredState | null>;
|
|
7
|
+
write(state: StoredState): void | Promise<void>;
|
|
8
|
+
};
|
|
9
|
+
export declare function createStorageManager(initial?: I18nStorage | null): {
|
|
10
|
+
setStorage(next: I18nStorage | null): void;
|
|
11
|
+
getStorage(): I18nStorage;
|
|
12
|
+
hasStorage(): boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare function createLocalStorage(): I18nStorage | null;
|
|
@@ -1,105 +1,4 @@
|
|
|
1
1
|
import { n as validateCompact } from "./compact-E3zj3Z8d.js";
|
|
2
|
-
// src/shared/runtime.ts
|
|
3
|
-
function createRuntime() {
|
|
4
|
-
return {
|
|
5
|
-
languageId: "en",
|
|
6
|
-
ready: false,
|
|
7
|
-
translationsEnabled: true,
|
|
8
|
-
translationGetter: null,
|
|
9
|
-
formats: {},
|
|
10
|
-
registry: {
|
|
11
|
-
number: {},
|
|
12
|
-
date: {},
|
|
13
|
-
time: {}
|
|
14
|
-
},
|
|
15
|
-
jsxLineBreak: "\n",
|
|
16
|
-
jsxHandler: null,
|
|
17
|
-
tagElement: null,
|
|
18
|
-
subscribe: () => () => {},
|
|
19
|
-
getSnapshot: () => null
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
const defaultRuntime = createRuntime();
|
|
23
|
-
let resolver = () => defaultRuntime;
|
|
24
|
-
function setRuntimeResolver(next) {
|
|
25
|
-
resolver = next;
|
|
26
|
-
}
|
|
27
|
-
function getRuntime() {
|
|
28
|
-
return resolver();
|
|
29
|
-
}
|
|
30
|
-
function setTranslationGetter(getter) {
|
|
31
|
-
getRuntime().translationGetter = getter;
|
|
32
|
-
}
|
|
33
|
-
function setLanguageId(languageId) {
|
|
34
|
-
getRuntime().languageId = languageId;
|
|
35
|
-
}
|
|
36
|
-
function setFormats(formats) {
|
|
37
|
-
getRuntime().formats = formats;
|
|
38
|
-
}
|
|
39
|
-
function setGetJsxHandler(handler) {
|
|
40
|
-
getRuntime().jsxHandler = handler;
|
|
41
|
-
}
|
|
42
|
-
const I18nRegistry = {
|
|
43
|
-
addNumberFormat(name, format) {
|
|
44
|
-
getRuntime().registry.number[name] = format;
|
|
45
|
-
},
|
|
46
|
-
addDateFormat(name, format) {
|
|
47
|
-
getRuntime().registry.date[name] = format;
|
|
48
|
-
},
|
|
49
|
-
addTimeFormat(name, format) {
|
|
50
|
-
getRuntime().registry.time[name] = format;
|
|
51
|
-
},
|
|
52
|
-
setLanguageId,
|
|
53
|
-
getConfig() {
|
|
54
|
-
const r = getRuntime().registry;
|
|
55
|
-
return {
|
|
56
|
-
number: { ...r.number },
|
|
57
|
-
date: { ...r.date },
|
|
58
|
-
time: { ...r.time }
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
function getFormats(runtime, languageId) {
|
|
63
|
-
const resolve = (entries) => Object.fromEntries(Object.entries(entries).map(([key, value]) => [key, typeof value === "function" ? value({ languageId }) : value]));
|
|
64
|
-
return {
|
|
65
|
-
number: {
|
|
66
|
-
...runtime.formats.number,
|
|
67
|
-
...resolve(runtime.registry.number)
|
|
68
|
-
},
|
|
69
|
-
date: {
|
|
70
|
-
...runtime.formats.date,
|
|
71
|
-
...resolve(runtime.registry.date)
|
|
72
|
-
},
|
|
73
|
-
time: {
|
|
74
|
-
...runtime.formats.time,
|
|
75
|
-
...resolve(runtime.registry.time)
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
function noTranslate(fn) {
|
|
80
|
-
const runtime = getRuntime();
|
|
81
|
-
const previous = runtime.translationsEnabled;
|
|
82
|
-
runtime.translationsEnabled = false;
|
|
83
|
-
try {
|
|
84
|
-
return fn();
|
|
85
|
-
} finally {
|
|
86
|
-
runtime.translationsEnabled = previous;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
function createTagHandler(handler) {
|
|
90
|
-
Object.defineProperty(handler, "__fluenticTagHandler", { value: true });
|
|
91
|
-
return handler;
|
|
92
|
-
}
|
|
93
|
-
/** Synchronous binding only: async callers must keep and use their own instance. */
|
|
94
|
-
function withRuntime(runtime, fn) {
|
|
95
|
-
const previous = resolver;
|
|
96
|
-
resolver = () => runtime;
|
|
97
|
-
try {
|
|
98
|
-
return fn();
|
|
99
|
-
} finally {
|
|
100
|
-
resolver = previous;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
2
|
// src/translation.ts
|
|
104
3
|
function parseCatalog(data) {
|
|
105
4
|
const catalog = Object.create(null);
|
|
@@ -205,9 +104,11 @@ function createTranslationManager() {
|
|
|
205
104
|
compiledCatalogs,
|
|
206
105
|
setTranslationLoader,
|
|
207
106
|
loadTranslations,
|
|
208
|
-
getTranslation
|
|
107
|
+
getTranslation,
|
|
108
|
+
languageLoading: () => loader?.onLanguageLoading?.(),
|
|
109
|
+
languageSelected: (languageId) => loader?.onLanguageSelected?.(languageId)
|
|
209
110
|
};
|
|
210
111
|
}
|
|
211
|
-
export {
|
|
112
|
+
export { defineTranslationLoader as n, createTranslationManager as t };
|
|
212
113
|
|
|
213
|
-
//# sourceMappingURL=translation-manager-
|
|
114
|
+
//# sourceMappingURL=translation-manager-BkmFnlb_.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"translation-manager-BkmFnlb_.js","names":[],"sources":["../src/translation.ts","../src/translation-manager.ts"],"sourcesContent":["import { type CompactMessage, validateCompact } from './shared/compact';\n\nexport type TranslationItem = { id: string; translation: string; };\nexport type TranslationRow = [id: string, translation: string] | [context: string, id: string, translation: string];\nexport type CompiledTranslationItem = [id: string, message: CompactMessage];\nexport type CompiledCatalogHeader = { compiled: true; };\nexport type TranslationJsonl = string;\n\nexport type TranslationData =\n | unknown[]\n | TranslationJsonl\n | { jsonl: TranslationJsonl; };\n\nexport type Catalog = Record<string, CompactMessage>;\n\ntype TranslationItemRaw = {\n id?: string;\n source?: string;\n context?: string;\n message?: string | [string, string];\n translation?: string;\n};\n\nexport function normalizeCatalog(data: TranslationData): Catalog {\n return parseCatalog(data).catalog;\n}\n\nexport function parseCatalog(data: TranslationData): { catalog: Catalog; compiled: boolean; } {\n const catalog: Catalog = Object.create(null);\n const rows = parseRows(data);\n const header = rows[0];\n const hasHeader = isCompiledHeader(header);\n const compiled = hasHeader ||\n (Array.isArray(data) && rows.some((row) => Array.isArray(row) && row.length === 2 && Array.isArray(row[1])));\n\n if (hasHeader) rows.shift();\n if (Array.isArray(data) && rows.at(-1) === null) rows.pop();\n\n for (const row of rows) {\n if (Array.isArray(row)) {\n const [id, message] = compiled ? parseCompiledRow(row) : parseTranslationRow(row, Array.isArray(data));\n\n if (compiled || message !== '') catalog[id] = message;\n } else {\n if (compiled) throw new TypeError('[i18n] invalid compiled catalog row');\n\n const item = parseTranslationItem(row);\n\n if (item.translation !== '') catalog[item.id] = item.translation;\n }\n }\n\n return { catalog, compiled };\n}\n\nfunction parseRows(data: TranslationData): unknown[] {\n if (Array.isArray(data)) return [...data];\n\n const jsonl = typeof data === 'string' ? data : data.jsonl;\n\n return jsonl.split(/\\r?\\n/).filter((line) => line.trim()).map((line) => JSON.parse(line));\n}\n\nfunction isCompiledHeader(row: unknown): row is CompiledCatalogHeader {\n return typeof row === 'object' && row !== null && !Array.isArray(row) &&\n 'compiled' in row && row.compiled === true;\n}\n\nfunction parseCompiledRow(row: unknown[]): CompiledTranslationItem {\n if (row.length !== 2 || typeof row[0] !== 'string') {\n throw new TypeError('[i18n] invalid compiled catalog row');\n }\n\n validateCompact(row[1]);\n\n return [row[0], row[1]];\n}\n\nfunction parseTranslationRow(row: unknown[], allowCompact: boolean): [string, CompactMessage] {\n if (row.length === 2 && typeof row[0] === 'string') {\n // Programmatic compileCatalog() results can be passed directly as arrays.\n if (allowCompact) validateCompact(row[1]);\n else if (typeof row[1] !== 'string') throw new TypeError('[i18n] invalid translation row');\n\n return [row[0], row[1]];\n }\n if (row.length === 3 && row.every((value) => typeof value === 'string')) {\n return [`${row[0]}\\0${row[1]}`, row[2] as string];\n }\n\n throw new TypeError('[i18n] invalid translation row');\n}\n\nfunction parseTranslationItem(row: unknown): TranslationItem {\n const item = row as TranslationItemRaw;\n\n if (!item || typeof item.translation !== 'string') throw new TypeError('[i18n] invalid translation item');\n\n const source = item.source ?? (Array.isArray(item.message) ? item.message[1] : item.message);\n const context = Array.isArray(item.message) ? item.message[0] : item.context;\n const id = item.id ?? (source === undefined ? undefined : context ? `${context}\\0${source}` : source);\n\n if (typeof id !== 'string') throw new TypeError('[i18n] translation id is missing');\n\n return { id, translation: item.translation };\n}\n","import type { LanguageId, MessageContext } from './core/types';\nimport { type Catalog, parseCatalog, type TranslationData } from './translation';\n\nexport type * from './translation';\nexport { normalizeCatalog } from './translation';\n\nexport type TranslationLoaderArgs = { languageId: LanguageId; };\nexport type TranslationLookupArgs = { languageId: LanguageId; context: MessageContext | null; message: string; };\nexport type TranslationLoader = ((args: TranslationLoaderArgs) => TranslationData | Promise<TranslationData>) & {\n /** Called before a manager starts loading a selected locale and its fallbacks. */\n onLanguageLoading?: () => void;\n /** Called only after the manager successfully commits a language selection, including in-memory cache hits. */\n onLanguageSelected?: (languageId: LanguageId) => void;\n};\nexport type TranslationModule = { default: TranslationData; };\nexport type TranslationSource = TranslationData | TranslationModule;\n\nexport type TranslationLoaderEntry =\n | TranslationSource\n | Promise<TranslationSource>\n | (() => TranslationSource | Promise<TranslationSource>);\n\nexport type TranslationLoaderMap = Record<string, TranslationLoaderEntry>;\n\nexport function defineTranslationLoader(loader: TranslationLoader | TranslationLoaderMap): TranslationLoader {\n if (typeof loader === 'function') return loader;\n\n return async ({ languageId }) => {\n if (!Object.prototype.hasOwnProperty.call(loader, languageId)) return [];\n\n const entry = loader[languageId];\n const source = await (typeof entry === 'function' ? entry() : entry);\n\n return typeof source === 'object' && source !== null && 'default' in source\n ? source.default\n : source as TranslationData;\n };\n}\n\nexport function createTranslationManager() {\n const catalogs: Record<string, Catalog> = Object.create(null);\n const pending = new Map<string, Promise<void>>();\n const compiledCatalogs: Record<string, boolean> = Object.create(null);\n\n let loader: TranslationLoader | null = null;\n let generation = 0;\n\n const setTranslationLoader = (next: TranslationLoader | null) => {\n loader = next;\n generation++;\n pending.clear();\n\n for (const key of Object.keys(catalogs)) delete catalogs[key];\n for (const key of Object.keys(compiledCatalogs)) delete compiledCatalogs[key];\n };\n\n const loadTranslations = async (languageId: string) => {\n if (!loader || Object.prototype.hasOwnProperty.call(catalogs, languageId)) return;\n if (pending.has(languageId)) return pending.get(languageId);\n\n const version = generation;\n const currentLoader = loader;\n\n const task = Promise.resolve().then(() => currentLoader({ languageId })).then((data) => {\n if (version === generation) {\n const result = parseCatalog(data);\n catalogs[languageId] = result.catalog;\n compiledCatalogs[languageId] = result.compiled;\n }\n }).finally(() => {\n if (version === generation) pending.delete(languageId);\n });\n\n pending.set(languageId, task);\n\n return task;\n };\n\n const getTranslation = (args: TranslationLookupArgs) => {\n const catalog = catalogs[args.languageId];\n const id = args.context ? `${args.context}\\0${args.message}` : args.message;\n\n return catalog?.[id] ?? catalog?.[args.message] ?? null;\n };\n\n return {\n catalogs,\n compiledCatalogs,\n setTranslationLoader,\n loadTranslations,\n getTranslation,\n languageLoading: () => loader?.onLanguageLoading?.(),\n languageSelected: (languageId: string) => loader?.onLanguageSelected?.(languageId),\n };\n}\n"],"mappings":";;AA2BA,SAAgB,aAAa,MAAiE;CAC5F,MAAM,UAAmB,OAAO,OAAO,IAAI;CAC3C,MAAM,OAAO,UAAU,IAAI;CAC3B,MAAM,SAAS,KAAK;CACpB,MAAM,YAAY,iBAAiB,MAAM;CACzC,MAAM,WAAW,aACd,MAAM,QAAQ,IAAI,KAAK,KAAK,MAAM,QAAQ,MAAM,QAAQ,GAAG,KAAK,IAAI,WAAW,KAAK,MAAM,QAAQ,IAAI,EAAE,CAAC;CAE5G,IAAI,WAAW,KAAK,MAAM;CAC1B,IAAI,MAAM,QAAQ,IAAI,KAAK,KAAK,GAAG,EAAE,MAAM,MAAM,KAAK,IAAI;CAE1D,KAAK,MAAM,OAAO,MAChB,IAAI,MAAM,QAAQ,GAAG,GAAG;EACtB,MAAM,CAAC,IAAI,WAAW,WAAW,iBAAiB,GAAG,IAAI,oBAAoB,KAAK,MAAM,QAAQ,IAAI,CAAC;EAErG,IAAI,YAAY,YAAY,IAAI,QAAQ,MAAM;CAChD,OAAO;EACL,IAAI,UAAU,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AAU,GAAG,OAAO,QAAQ,IAAI,UAAU;EAE1D,MAAM,UAAU;EAChB,MAAM,gBAAgB;EAEtB,MAAM,OAAO,QAAQ,QAAQ,CAAC,CAAC,WAAW,cAAc,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,MAAM,SAAS;GACtF,IAAI,YAAY,YAAY;IAC1B,MAAM,SAAS,aAAa,IAAI;IAChC,SAAS,cAAc,OAAO;IAC9B,iBAAiB,cAAc,OAAO;GACxC;EACF,CAAC,CAAC,CAAC,cAAc;GACf,IAAI,YAAY,YAAY,QAAQ,OAAO,UAAU;EACvD,CAAC;EAED,QAAQ,IAAI,YAAY,IAAI;EAE5B,OAAO;CACT;CAEA,MAAM,kBAAkB,SAAgC;EACtD,MAAM,UAAU,SAAS,KAAK;EAC9B,MAAM,KAAK,KAAK,UAAU,GAAG,KAAK,QAAQ,IAAI,KAAK,YAAY,KAAK;EAEpE,OAAO,UAAU,OAAO,UAAU,KAAK,YAAY;CACrD;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA,uBAAuB,QAAQ,oBAAoB;EACnD,mBAAmB,eAAuB,QAAQ,qBAAqB,UAAU;CACnF;AACF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { LanguageId, MessageContext } from './core/types';
|
|
2
|
+
import { type Catalog, type TranslationData } from './translation';
|
|
3
|
+
export type * from './translation';
|
|
4
|
+
export { normalizeCatalog } from './translation';
|
|
5
|
+
export type TranslationLoaderArgs = {
|
|
6
|
+
languageId: LanguageId;
|
|
7
|
+
};
|
|
8
|
+
export type TranslationLookupArgs = {
|
|
9
|
+
languageId: LanguageId;
|
|
10
|
+
context: MessageContext | null;
|
|
11
|
+
message: string;
|
|
12
|
+
};
|
|
13
|
+
export type TranslationLoader = ((args: TranslationLoaderArgs) => TranslationData | Promise<TranslationData>) & {
|
|
14
|
+
/** Called before a manager starts loading a selected locale and its fallbacks. */
|
|
15
|
+
onLanguageLoading?: () => void;
|
|
16
|
+
/** Called only after the manager successfully commits a language selection, including in-memory cache hits. */
|
|
17
|
+
onLanguageSelected?: (languageId: LanguageId) => void;
|
|
18
|
+
};
|
|
19
|
+
export type TranslationModule = {
|
|
20
|
+
default: TranslationData;
|
|
21
|
+
};
|
|
22
|
+
export type TranslationSource = TranslationData | TranslationModule;
|
|
23
|
+
export type TranslationLoaderEntry = TranslationSource | Promise<TranslationSource> | (() => TranslationSource | Promise<TranslationSource>);
|
|
24
|
+
export type TranslationLoaderMap = Record<string, TranslationLoaderEntry>;
|
|
25
|
+
export declare function defineTranslationLoader(loader: TranslationLoader | TranslationLoaderMap): TranslationLoader;
|
|
26
|
+
export declare function createTranslationManager(): {
|
|
27
|
+
catalogs: Record<string, Catalog>;
|
|
28
|
+
compiledCatalogs: Record<string, boolean>;
|
|
29
|
+
setTranslationLoader: (next: TranslationLoader | null) => void;
|
|
30
|
+
loadTranslations: (languageId: string) => Promise<void>;
|
|
31
|
+
getTranslation: (args: TranslationLookupArgs) => import("./adapter").CompactMessage;
|
|
32
|
+
languageLoading: () => void | undefined;
|
|
33
|
+
languageSelected: (languageId: string) => void | undefined;
|
|
34
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type CompactMessage } from './shared/compact';
|
|
2
|
+
export type TranslationItem = {
|
|
3
|
+
id: string;
|
|
4
|
+
translation: string;
|
|
5
|
+
};
|
|
6
|
+
export type TranslationRow = [id: string, translation: string] | [context: string, id: string, translation: string];
|
|
7
|
+
export type CompiledTranslationItem = [id: string, message: CompactMessage];
|
|
8
|
+
export type CompiledCatalogHeader = {
|
|
9
|
+
compiled: true;
|
|
10
|
+
};
|
|
11
|
+
export type TranslationJsonl = string;
|
|
12
|
+
export type TranslationData = unknown[] | TranslationJsonl | {
|
|
13
|
+
jsonl: TranslationJsonl;
|
|
14
|
+
};
|
|
15
|
+
export type Catalog = Record<string, CompactMessage>;
|
|
16
|
+
export declare function normalizeCatalog(data: TranslationData): Catalog;
|
|
17
|
+
export declare function parseCatalog(data: TranslationData): {
|
|
18
|
+
catalog: Catalog;
|
|
19
|
+
compiled: boolean;
|
|
20
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types-BkDsJfVD.js","names":[],"sources":["../src/core/types.ts"],"sourcesContent":["import type { CompactMessage } from '../shared/compact';\nimport type { I18nJsxConfig } from '../types';\n\nexport type { I18nJsxConfig } from '../types';\n\nexport type I18nJsxOutput = I18nJsxConfig extends { JSX: infer Output; } ? NonNullable<Output> : unknown;\nexport type I18nTagElement = I18nJsxConfig extends { Element: infer Element; } ? Element : never;\nexport type I18nTagValue = I18nJsxConfig extends { Value: infer Value; } ? Value : unknown;\nexport type PrimitiveType = string | number | boolean | null | undefined;\n\nexport type LanguageId = string;\nexport type JsonValue = string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue; };\nexport type MessageMeta = JsonValue;\nexport type MessageContext = string;\n\nexport type MessageSchemaValue = StringConstructor | NumberConstructor | BooleanConstructor | DateConstructor;\nexport type MessageSchema = Partial<Record<string, MessageSchemaValue>>;\n\nexport type InferMessageSchema<Schema extends MessageSchema> = {\n [Key in keyof Schema]: Schema[Key] extends StringConstructor ? string\n : Schema[Key] extends NumberConstructor ? number\n : Schema[Key] extends BooleanConstructor ? boolean\n : Schema[Key] extends DateConstructor ? Date\n : never;\n};\n\nexport type MessageDescriptor<Text extends string = string, Schema extends MessageSchema | undefined = MessageSchema> =\n {\n readonly __fluenticMessage: true;\n readonly text: Text;\n readonly compiled?: readonly [string, CompactMessage];\n readonly context: MessageContext | null;\n readonly schema: Schema extends MessageSchema ? Schema : MessageSchema;\n readonly notes: readonly string[];\n readonly meta: MessageMeta | undefined;\n };\n\nexport type AnyMessageDescriptor = MessageDescriptor<string, MessageSchema | undefined>;\n\nexport type MessageValueContext = { languageId: LanguageId; };\nexport type MessageValueFactory<T = unknown> = (context: MessageValueContext) => T;\n\nexport type MessageTagHandler<T = unknown, R = unknown> = ((chunks: Array<string | T>) => R) & {\n readonly __fluenticTagHandler: true;\n};\n\nexport type MessageRuntimeValue =\n | PrimitiveType\n | Date\n | AnyMessageDescriptor\n | MessageValueFactory\n | Pick<MessageTagHandler, '__fluenticTagHandler'>;\n\nexport type MessageParam = MessageRuntimeValue;\nexport type MessageParams = Record<string, MessageParam>;\nexport type MessageInput = string | AnyMessageDescriptor;\n\nexport type InferRuntimeParams<Schema extends MessageSchema> = {\n [Key in keyof InferMessageSchema<Schema>]:\n | InferMessageSchema<Schema>[Key]\n | MessageValueFactory<InferMessageSchema<Schema>[Key]>;\n};\n\nexport type DescriptorRenderArgs<Schema extends MessageSchema | undefined> = Schema extends undefined\n ? [params?: MessageParams]\n : keyof Schema extends never ? []\n : Schema extends MessageSchema ? [params: InferRuntimeParams<Schema>]\n : never;\n\nexport type TryRenderArgs<Value> = Value extends { readonly __fluenticMessage: true; }\n ? Value extends MessageDescriptor<string, infer Schema>\n ? Schema extends MessageSchema | undefined ? DescriptorRenderArgs<Schema>\n : [params: MessageParams]\n : [params: MessageParams]\n : [params?: MessageParams];\n\nexport type TextRenderer = {\n <Text extends string>(message: Text, params?: MessageParams): string;\n <Text extends string, Schema extends MessageSchema | undefined>(\n message: MessageDescriptor<Text, Schema>,\n ...args: DescriptorRenderArgs<Schema>\n ): string;\n};\n\nexport type JsxRenderer<Output = unknown> = {\n <Text extends string>(message: Text, params?: MessageParams): Output;\n <Text extends string, Schema extends MessageSchema | undefined>(\n message: MessageDescriptor<Text, Schema>,\n ...args: DescriptorRenderArgs<Schema>\n ): Output;\n};\n\nexport type MessageFormatOptions = {\n msg: MessageInput;\n params?: MessageParams;\n languageId?: LanguageId;\n};\n\nexport type GetJsxHandler<Output = unknown> = (options: MessageFormatOptions) => Output;\n\nexport type CompiledTranslation = { compiled: CompactMessage; };\n\nexport type TranslationGetter = (args: {\n languageId: LanguageId;\n context: MessageContext | null;\n message: string;\n getCompiledId?: () => string;\n}) => CompactMessage | CompiledTranslation | null;\n\nexport function isMessageDescriptor(value: unknown): value is AnyMessageDescriptor {\n return value !== null && typeof value === 'object' && '__fluenticMessage' in value &&\n value.__fluenticMessage === true;\n}\n\nexport function isMessageTagHandler(value: unknown): value is MessageTagHandler {\n return typeof value === 'function' && '__fluenticTagHandler' in value && value.__fluenticTagHandler === true;\n}\n\nexport function isMessageSchemaValue(value: unknown): value is MessageSchemaValue {\n return value === String || value === Number || value === Boolean || value === Date;\n}\n"],"mappings":";
|
|
1
|
+
{"version":3,"file":"types-BkDsJfVD.js","names":[],"sources":["../src/core/types.ts"],"sourcesContent":["import type { CompactMessage } from '../shared/compact';\nimport type { I18nJsxConfig } from '../types';\n\nexport type { I18nJsxConfig } from '../types';\n\nexport type I18nJsxOutput = I18nJsxConfig extends { JSX: infer Output; } ? NonNullable<Output> : unknown;\nexport type I18nTagElement = I18nJsxConfig extends { Element: infer Element; } ? Element : never;\nexport type I18nTagValue = I18nJsxConfig extends { Value: infer Value; } ? Value : unknown;\nexport type PrimitiveType = string | number | boolean | null | undefined;\n\nexport type LanguageId = string;\nexport type JsonValue = string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue; };\nexport type MessageMeta = JsonValue;\nexport type MessageContext = string;\n\nexport type MessageSchemaValue = StringConstructor | NumberConstructor | BooleanConstructor | DateConstructor;\nexport type MessageSchema = Partial<Record<string, MessageSchemaValue>>;\n\nexport type InferMessageSchema<Schema extends MessageSchema> = {\n [Key in keyof Schema]: Schema[Key] extends StringConstructor ? string\n : Schema[Key] extends NumberConstructor ? number\n : Schema[Key] extends BooleanConstructor ? boolean\n : Schema[Key] extends DateConstructor ? Date\n : never;\n};\n\nexport type MessageDescriptor<Text extends string = string, Schema extends MessageSchema | undefined = MessageSchema> =\n {\n readonly __fluenticMessage: true;\n readonly text: Text;\n readonly compiled?: readonly [string, CompactMessage];\n readonly context: MessageContext | null;\n readonly schema: Schema extends MessageSchema ? Schema : MessageSchema;\n readonly notes: readonly string[];\n readonly meta: MessageMeta | undefined;\n };\n\nexport type AnyMessageDescriptor = MessageDescriptor<string, MessageSchema | undefined>;\n\nexport type MessageValueContext = { languageId: LanguageId; };\nexport type MessageValueFactory<T = unknown> = (context: MessageValueContext) => T;\n\nexport type MessageTagHandler<T = unknown, R = unknown> = ((chunks: Array<string | T>) => R) & {\n readonly __fluenticTagHandler: true;\n};\n\nexport type MessageRuntimeValue =\n | PrimitiveType\n | Date\n | AnyMessageDescriptor\n | MessageValueFactory\n | Pick<MessageTagHandler, '__fluenticTagHandler'>;\n\nexport type MessageParam = MessageRuntimeValue;\nexport type MessageParams = Record<string, MessageParam>;\nexport type MessageInput = string | AnyMessageDescriptor;\n\nexport type InferRuntimeParams<Schema extends MessageSchema> = {\n [Key in keyof InferMessageSchema<Schema>]:\n | InferMessageSchema<Schema>[Key]\n | MessageValueFactory<InferMessageSchema<Schema>[Key]>;\n};\n\nexport type DescriptorRenderArgs<Schema extends MessageSchema | undefined> = Schema extends undefined\n ? [params?: MessageParams]\n : keyof Schema extends never ? []\n : Schema extends MessageSchema ? [params: InferRuntimeParams<Schema>]\n : never;\n\nexport type TryRenderArgs<Value> = Value extends { readonly __fluenticMessage: true; }\n ? Value extends MessageDescriptor<string, infer Schema>\n ? Schema extends MessageSchema | undefined ? DescriptorRenderArgs<Schema>\n : [params: MessageParams]\n : [params: MessageParams]\n : [params?: MessageParams];\n\nexport type TextRenderer = {\n <Text extends string>(message: Text, params?: MessageParams): string;\n <Text extends string, Schema extends MessageSchema | undefined>(\n message: MessageDescriptor<Text, Schema>,\n ...args: DescriptorRenderArgs<Schema>\n ): string;\n};\n\nexport type JsxRenderer<Output = unknown> = {\n (render: () => I18nTagElement): Output;\n <Text extends string>(message: Text, params?: MessageParams): Output;\n <Text extends string, Schema extends MessageSchema | undefined>(\n message: MessageDescriptor<Text, Schema>,\n ...args: DescriptorRenderArgs<Schema>\n ): Output;\n};\n\nexport type MessageFormatOptions = {\n msg: MessageInput;\n params?: MessageParams;\n languageId?: LanguageId;\n};\n\nexport type GetJsxHandler<Output = unknown> = (options: MessageFormatOptions) => Output;\n\nexport type CompiledTranslation = { compiled: CompactMessage; };\n\nexport type TranslationGetter = (args: {\n languageId: LanguageId;\n context: MessageContext | null;\n message: string;\n getCompiledId?: () => string;\n}) => CompactMessage | CompiledTranslation | null;\n\nexport function isMessageDescriptor(value: unknown): value is AnyMessageDescriptor {\n return value !== null && typeof value === 'object' && '__fluenticMessage' in value &&\n value.__fluenticMessage === true;\n}\n\nexport function isMessageTagHandler(value: unknown): value is MessageTagHandler {\n return typeof value === 'function' && '__fluenticTagHandler' in value && value.__fluenticTagHandler === true;\n}\n\nexport function isMessageSchemaValue(value: unknown): value is MessageSchemaValue {\n return value === String || value === Number || value === Boolean || value === Date;\n}\n"],"mappings":";AA8GA,SAAgB,oBAAoB,OAA+C;CACjF,OAAO,UAAU,QAAQ,OAAO,UAAU,YAAY,uBAAuB,SAC3E,MAAM,sBAAsB;AAChC;AAEA,SAAgB,oBAAoB,OAA4C;CAC9E,OAAO,OAAO,UAAU,cAAc,0BAA0B,SAAS,MAAM,yBAAyB;AAC1G;AAEA,SAAgB,qBAAqB,OAA6C;CAChF,OAAO,UAAU,UAAU,UAAU,UAAU,UAAU,WAAW,UAAU;AAChF"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export interface I18nJsxConfig {
|
|
2
|
+
}
|
|
3
|
+
export * from './core/types';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluentic/i18n",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.2",
|
|
4
4
|
"description": "Framework-independent internationalization primitives for Fluentic applications.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -24,93 +24,59 @@
|
|
|
24
24
|
},
|
|
25
25
|
"exports": {
|
|
26
26
|
".": {
|
|
27
|
-
"types": "./
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
28
|
"import": "./dist/index.js",
|
|
29
29
|
"default": "./dist/index.js"
|
|
30
30
|
},
|
|
31
31
|
"./core": {
|
|
32
|
-
"types": "./
|
|
32
|
+
"types": "./dist/core/index.d.ts",
|
|
33
33
|
"import": "./dist/core/index.js",
|
|
34
34
|
"default": "./dist/core/index.js"
|
|
35
35
|
},
|
|
36
36
|
"./adapter": {
|
|
37
|
-
"types": "./
|
|
37
|
+
"types": "./dist/adapter.d.ts",
|
|
38
38
|
"import": "./dist/adapter.js",
|
|
39
39
|
"default": "./dist/adapter.js"
|
|
40
40
|
},
|
|
41
41
|
"./react": {
|
|
42
|
-
"types": "./
|
|
42
|
+
"types": "./dist/react.d.ts",
|
|
43
43
|
"import": "./dist/react.js",
|
|
44
44
|
"default": "./dist/react.js"
|
|
45
45
|
},
|
|
46
|
+
"./hydration": {
|
|
47
|
+
"types": "./dist/hydration.d.ts",
|
|
48
|
+
"import": "./dist/hydration.js",
|
|
49
|
+
"default": "./dist/hydration.js"
|
|
50
|
+
},
|
|
46
51
|
"./types": {
|
|
47
|
-
"types": "./
|
|
52
|
+
"types": "./dist/types.d.ts",
|
|
48
53
|
"import": "./dist/types.js",
|
|
49
54
|
"default": "./dist/types.js"
|
|
50
55
|
},
|
|
51
56
|
"./compiled": {
|
|
52
|
-
"types": "./
|
|
57
|
+
"types": "./dist/compiled.d.ts",
|
|
53
58
|
"default": "./dist/compiled.js"
|
|
54
59
|
},
|
|
55
|
-
"./compiler": {
|
|
56
|
-
"types": "./
|
|
57
|
-
"default": "./dist/compiler.js"
|
|
58
|
-
},
|
|
59
|
-
"./plugin/babel": {
|
|
60
|
-
"types": "./src/plugin/babel.ts",
|
|
61
|
-
"import": "./dist/plugin/babel.js",
|
|
62
|
-
"require": "./dist-cjs/babel.cjs"
|
|
63
|
-
},
|
|
64
|
-
"./plugin/vite": {
|
|
65
|
-
"types": "./src/plugin/vite.ts",
|
|
66
|
-
"default": "./dist/plugin/vite.js"
|
|
67
|
-
},
|
|
68
|
-
"./plugin/rollup": {
|
|
69
|
-
"types": "./src/plugin/rollup.ts",
|
|
70
|
-
"default": "./dist/plugin/rollup.js"
|
|
71
|
-
},
|
|
72
|
-
"./plugin/esbuild": {
|
|
73
|
-
"types": "./src/plugin/esbuild.ts",
|
|
74
|
-
"default": "./dist/plugin/esbuild.js"
|
|
75
|
-
},
|
|
76
|
-
"./plugin/webpack": {
|
|
77
|
-
"types": "./src/plugin/webpack.ts",
|
|
78
|
-
"default": "./dist/plugin/webpack.js"
|
|
79
|
-
},
|
|
80
|
-
"./plugin/webpack-loader": {
|
|
81
|
-
"types": "./src/plugin/webpack-loader.ts",
|
|
82
|
-
"default": "./dist/plugin/webpack-loader.js"
|
|
60
|
+
"./compiler-support": {
|
|
61
|
+
"types": "./dist/compiler-support.d.ts",
|
|
62
|
+
"default": "./dist/compiler-support.js"
|
|
83
63
|
}
|
|
84
64
|
},
|
|
85
65
|
"files": [
|
|
86
66
|
"dist",
|
|
87
|
-
"src",
|
|
88
67
|
"README.md",
|
|
89
68
|
"CHANGELOG.md",
|
|
90
|
-
"LICENSE"
|
|
91
|
-
"dist-cjs"
|
|
69
|
+
"LICENSE"
|
|
92
70
|
],
|
|
93
71
|
"dependencies": {
|
|
94
|
-
"intl-messageformat": "^10.7.16"
|
|
95
|
-
"@babel/parser": "^7.28.4",
|
|
96
|
-
"@babel/traverse": "^7.28.4",
|
|
97
|
-
"@babel/types": "^7.28.4",
|
|
98
|
-
"@babel/generator": "^7.28.3",
|
|
99
|
-
"@formatjs/icu-messageformat-parser": "2.11.4",
|
|
100
|
-
"jiti": "^2.7.0",
|
|
101
|
-
"@jridgewell/remapping": "^2.3.5",
|
|
102
|
-
"@noble/hashes": "^1.8.0"
|
|
72
|
+
"intl-messageformat": "^10.7.16"
|
|
103
73
|
},
|
|
104
74
|
"devDependencies": {
|
|
105
75
|
"@types/react": "^19.2.14",
|
|
106
76
|
"react": "^19.2.0",
|
|
107
77
|
"react-test-renderer": "19.3.1",
|
|
108
78
|
"tsdown": "^0.22.1",
|
|
109
|
-
"typescript": "^
|
|
110
|
-
"@types/babel__traverse": "^7.20.7",
|
|
111
|
-
"@types/babel__generator": "^7.27.0",
|
|
112
|
-
"@types/node": "^22.15.0",
|
|
113
|
-
"@babel/core": "^7.28.4"
|
|
79
|
+
"typescript": "^7.0.2"
|
|
114
80
|
},
|
|
115
81
|
"peerDependencies": {
|
|
116
82
|
"react": ">=18"
|
|
@@ -124,10 +90,10 @@
|
|
|
124
90
|
"./dist/react.js"
|
|
125
91
|
],
|
|
126
92
|
"scripts": {
|
|
127
|
-
"build": "tsdown",
|
|
93
|
+
"build": "tsdown && tsc -p tsconfig.build.json",
|
|
128
94
|
"dev": "tsdown --watch",
|
|
129
95
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
130
96
|
"test": "pnpm test:types && pnpm build && node --test test/*.test.mjs",
|
|
131
|
-
"test:types": "tsc --noEmit --strict --skipLibCheck --esModuleInterop --module ESNext --moduleResolution Bundler --target ES2020 --jsx react-jsx test/react.types.tsx test/compiled.types.ts"
|
|
97
|
+
"test:types": "tsc --ignoreConfig --noEmit --strict --skipLibCheck --esModuleInterop --module ESNext --moduleResolution Bundler --target ES2020 --lib ES2022,DOM --jsx react-jsx test/react.types.tsx test/compiled.types.ts"
|
|
132
98
|
}
|
|
133
99
|
}
|