@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
package/dist/i18n-CfYNwubL.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { C as MessageTagHandler, D as TextRenderer, _ as MessageMeta, d as JsxRenderer, k as TryRenderArgs, m as MessageDescriptor, o as I18nTagElement, s as I18nTagValue, x as MessageSchema, y as MessageParams } from "./types-BuGoCU3P.js";
|
|
2
|
-
import { G as noTranslate } from "./adapter-CWC8rng-.js";
|
|
3
|
-
type MessageApi<JsxOutput = unknown> = {
|
|
4
|
-
context(name: string): MessageApi<JsxOutput>;
|
|
5
|
-
note(note: string): MessageApi<JsxOutput>;
|
|
6
|
-
meta(meta: MessageMeta): MessageApi<JsxOutput>;
|
|
7
|
-
msg<const Text extends string, const Schema extends MessageSchema | undefined = undefined>(message: Text, schema?: Schema): MessageDescriptor<Text, Schema>;
|
|
8
|
-
text: TextRenderer;
|
|
9
|
-
jsx: JsxRenderer<JsxOutput>;
|
|
10
|
-
};
|
|
11
|
-
type TApi<JsxOutput = unknown, TagValue = unknown> = MessageApi<JsxOutput> & {
|
|
12
|
-
clone<const Text extends string, const Schema extends MessageSchema | undefined>(message: MessageDescriptor<Text, Schema>): MessageDescriptor<Text, Schema>;
|
|
13
|
-
params<Params extends MessageParams>(params?: Params | null): Params;
|
|
14
|
-
tag(element: I18nTagElement): MessageTagHandler<I18nTagValue, I18nTagElement>;
|
|
15
|
-
tag<T = TagValue, R = TagValue>(handler: (chunks: Array<string | T>) => R): MessageTagHandler<T, R>;
|
|
16
|
-
try<T>(renderer: TextRenderer, value: T, ...args: TryRenderArgs<T>): T extends {
|
|
17
|
-
readonly __fluenticMessage: true;
|
|
18
|
-
} ? string : T;
|
|
19
|
-
try<T>(renderer: JsxRenderer<JsxOutput>, value: T, ...args: TryRenderArgs<T>): T extends {
|
|
20
|
-
readonly __fluenticMessage: true;
|
|
21
|
-
} ? JsxOutput : T;
|
|
22
|
-
notranslate: typeof noTranslate;
|
|
23
|
-
};
|
|
24
|
-
export { TApi as n, MessageApi as t };
|
|
25
|
-
//# sourceMappingURL=i18n-CfYNwubL.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"interpreter-Dld8QyOI.js","names":[],"sources":["../src/shared/formatting.ts","../src/shared/interpreter.ts"],"sourcesContent":["import { isMessageDescriptor, isMessageSchemaValue, isMessageTagHandler } from '../core/types';\nimport type { MessageFormatOptions, MessageParam } from '../core/types';\nimport type { CompactMessage } from './compact';\nimport { type Formats, getFormats, getRuntime, type Runtime } from './runtime';\n\nexport type Engine = (\n message: CompactMessage,\n languageId: string,\n formats: Partial<Formats>,\n values: Record<string, unknown>,\n compiled: boolean,\n) => unknown[];\n\nexport type Formatting = ReturnType<typeof createFormatting>;\n\nexport function createFormatting(\n engine: Engine,\n compiled = false,\n getCompiledId?: (context: string | null, message: string) => string,\n) {\n const getMessageParts = (options: MessageFormatOptions, runtime = getRuntime(), jsx = false): unknown[] => {\n if (!runtime.ready) throw new Error('[i18n] runtime is not ready; await adapter initialization before rendering');\n\n const languageId = options.languageId ?? runtime.languageId;\n\n const descriptor = isMessageDescriptor(options.msg)\n ? options.msg\n : { text: options.msg, context: null, schema: {}, compiled: undefined };\n\n if (compiled && !descriptor.compiled) {\n throw new TypeError('[i18n] compiled runtime requires compiled messages; enable the Fluentic plugin');\n }\n\n const key = descriptor.compiled?.[0] ?? descriptor.text;\n\n const translated = runtime.translationsEnabled\n ? runtime.translationGetter?.({\n languageId,\n context: descriptor.compiled ? null : descriptor.context,\n message: key,\n getCompiledId: getCompiledId && !descriptor.compiled\n ? () => getCompiledId(descriptor.context, descriptor.text)\n : undefined,\n })\n : null;\n const compiledTranslation = typeof translated === 'object' && translated !== null && !Array.isArray(translated);\n if (compiled && typeof translated === 'string') {\n throw new TypeError('[i18n] compiled runtime requires compiled translations');\n }\n\n const message = compiledTranslation\n ? translated.compiled\n : translated ?? descriptor.compiled?.[1] ?? descriptor.text;\n const isCompiled = compiled || compiledTranslation || Array.isArray(message);\n const values: Record<string, unknown> = {};\n\n const resolve = (value: MessageParam): unknown => {\n if (isMessageTagHandler(value)) return value;\n if (isMessageSchemaValue(value)) {\n throw new Error('[i18n] Message parameter schemas are only valid in t.msg(); pass a real value');\n }\n if (typeof value === 'function') return resolve(value({ languageId }) as MessageParam);\n if (isMessageDescriptor(value)) return getText({ msg: value, languageId }, runtime);\n\n return value;\n };\n\n for (const [key, value] of Object.entries(options.params ?? {})) values[key] = resolve(value);\n values.break = jsx ? runtime.jsxLineBreak : '\\n';\n\n for (const [key, expected] of Object.entries(descriptor.schema)) {\n if (key !== 'break' && (!options.params || options.params[key] === undefined)) {\n throw new Error('[i18n] Missing required message parameter: ' + key);\n }\n\n const value = values[key];\n\n const valid = expected === String\n ? typeof value === 'string'\n : expected === Number\n ? typeof value === 'number'\n : expected === Boolean\n ? typeof value === 'boolean'\n : expected === Date\n ? value instanceof Date && !Number.isNaN(value.getTime())\n : true;\n\n if (!valid) {\n throw new Error('[i18n] Message parameter \"' + key + '\" must be a ' + (expected as { name: string; }).name);\n }\n }\n\n return engine(message, languageId, getFormats(runtime, languageId), values, isCompiled);\n };\n\n const getText = (options: MessageFormatOptions, runtime = getRuntime()): string => {\n const parts = getMessageParts(options, runtime);\n\n if (parts.some((part) => typeof part !== 'string')) {\n throw new Error('[i18n] t.text() received a non-text rich value; use t.jsx() instead');\n }\n\n return parts.join('');\n };\n\n const getJsx = (options: MessageFormatOptions): unknown => {\n const runtime = getRuntime();\n\n if (!runtime.jsxHandler) throw new Error('[i18n] JSX renderer is not configured; initialize a platform adapter');\n // Capture notranslate at element creation, not at React's later render.\n const enabled = runtime.translationsEnabled;\n\n return runtime.jsxHandler(\n options,\n (current = getRuntime()) =>\n getMessageParts(options, enabled ? current : { ...current, translationsEnabled: false }, true),\n );\n };\n\n return { getText, getJsx, getMessageParts, formatMessage: getText };\n}\n","import type { CompactMessage } from './compact';\nimport type { Engine } from './formatting';\n\nconst numberCache = new Map<string, Intl.NumberFormat>();\nconst dateCache = new Map<string, Intl.DateTimeFormat>();\nconst pluralCache = new Map<string, Intl.PluralRules>();\n\nfunction cached<T>(map: Map<string, T>, key: string, create: () => T): T {\n let value = map.get(key);\n\n if (!value) {\n value = create();\n if (map.size >= 100) map.delete(map.keys().next().value!);\n map.set(key, value);\n }\n\n return value;\n}\n\nconst numberDefaults = {\n integer: { maximumFractionDigits: 0 },\n currency: { style: 'currency' },\n percent: { style: 'percent' },\n};\nconst dateDefaults = {\n short: { month: 'numeric', day: 'numeric', year: '2-digit' },\n medium: { month: 'short', day: 'numeric', year: 'numeric' },\n long: { month: 'long', day: 'numeric', year: 'numeric' },\n full: { weekday: 'long', month: 'long', day: 'numeric', year: 'numeric' },\n};\nconst timeDefaults = {\n short: { hour: 'numeric', minute: 'numeric' },\n medium: { hour: 'numeric', minute: 'numeric', second: 'numeric' },\n long: { hour: 'numeric', minute: 'numeric', second: 'numeric', timeZoneName: 'short' },\n full: { hour: 'numeric', minute: 'numeric', second: 'numeric', timeZoneName: 'long' },\n};\nexport const interpret: Engine = (message, locale, formats, values) => {\n const number = (value: number, options?: Intl.NumberFormatOptions) =>\n cached(numberCache, JSON.stringify([locale, options]), () => new Intl.NumberFormat(locale, options)).format(value);\n\n const render = (message: CompactMessage, pound?: number): unknown[] => {\n if (typeof message === 'string') return [message];\n\n const output: unknown[] = [];\n\n const append = (value: unknown) => {\n if (Array.isArray(value)) {\n for (const part of value) append(part);\n } else if (typeof value === 'string' && typeof output[output.length - 1] === 'string') {\n output[output.length - 1] += value;\n } else output.push(value);\n };\n\n for (const part of message) {\n if (typeof part === 'string') {\n append(part);\n continue;\n }\n\n const op = part[0];\n\n if (op === 6) {\n if (pound !== undefined) append(number(pound));\n continue;\n }\n\n const name = part[1];\n\n if (!(name in values)) throw new Error('[i18n] Missing required message parameter: ' + name);\n\n const value = values[name];\n\n if (op === 0) {\n append(typeof value === 'string' || typeof value === 'number' ? String(value) : value || '');\n continue;\n }\n if (op >= 1 && op <= 3) {\n const style = part[2] as string | Record<string, unknown> | null;\n const kind = op === 1 ? 'number' : op === 2 ? 'date' : 'time';\n const defaults = op === 1 ? numberDefaults : op === 2 ? dateDefaults : timeDefaults;\n\n const options = (typeof style === 'string'\n ? formats[kind]?.[style] ?? (defaults as Record<string, object>)[style]\n : style ?? (op === 3 ? timeDefaults.medium : undefined)) as Record<string, unknown> | undefined;\n\n if (op === 1) {\n append(number(Number(value) * (Number(options?.scale ?? 1)), options));\n } else {\n append(\n cached(\n dateCache,\n JSON.stringify([locale, options]),\n () => new Intl.DateTimeFormat(locale, options as Intl.DateTimeFormatOptions),\n ).format(value as Date),\n );\n }\n } else if (op === 4) {\n const branches = part[2];\n append(\n render(\n Object.prototype.hasOwnProperty.call(branches, String(value)) ? branches[String(value)] : branches.other,\n ),\n );\n } else if (op === 5) {\n const count = Number(value);\n const adjusted = count - part[2];\n const branches = part[4];\n const exact = '=' + count;\n\n const key = Object.prototype.hasOwnProperty.call(branches, exact)\n ? exact\n : cached(\n pluralCache,\n locale + ':' + part[3],\n () => new Intl.PluralRules(locale, { type: part[3] ? 'ordinal' : 'cardinal' }),\n ).select(adjusted);\n append(render(branches[key] ?? branches.other, adjusted));\n } else if (op === 7) {\n if (typeof value !== 'function') throw new TypeError('[i18n] rich tag ' + name + ' requires a handler');\n append(value(render(part[2], pound)));\n }\n }\n\n return output;\n };\n\n return render(message);\n};\n"],"mappings":";;;AAeA,SAAgB,iBACd,QACA,WAAW,OACX,eACA;CACA,MAAM,mBAAmB,SAA+B,UAAU,WAAW,GAAG,MAAM,UAAqB;EACzG,IAAI,CAAC,QAAQ,OAAO,MAAM,IAAI,MAAM,4EAA4E;EAEhH,MAAM,aAAa,QAAQ,cAAc,QAAQ;EAEjD,MAAM,aAAa,oBAAoB,QAAQ,GAAG,IAC9C,QAAQ,MACR;GAAE,MAAM,QAAQ;GAAK,SAAS;GAAM,QAAQ,CAAC;GAAG,UAAU,KAAA;EAAU;EAExE,IAAI,YAAY,CAAC,WAAW,UAC1B,MAAM,IAAI,UAAU,gFAAgF;EAGtG,MAAM,MAAM,WAAW,WAAW,MAAM,WAAW;EAEnD,MAAM,aAAa,QAAQ,sBACvB,QAAQ,oBAAoB;GAC5B;GACA,SAAS,WAAW,WAAW,OAAO,WAAW;GACjD,SAAS;GACT,eAAe,iBAAiB,CAAC,WAAW,iBAClC,cAAc,WAAW,SAAS,WAAW,IAAI,IACvD,KAAA;EACN,CAAC,IACC;EACJ,MAAM,sBAAsB,OAAO,eAAe,YAAY,eAAe,QAAQ,CAAC,MAAM,QAAQ,UAAU;EAC9G,IAAI,Y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AAO,OAAO,OAAO;AACvB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"manager-BW778X1Y.js","names":[],"sources":["../src/state-manager.ts","../src/storage-manager.ts","../src/manager.ts"],"sourcesContent":["export type StateManager<StateData> = {\n get(): StateData;\n subscribe(listener: () => void): () => void;\n set(partial: Partial<StateData>): void;\n};\n\nexport function createStateManager<StateData extends object>(initial: StateData): StateManager<StateData> {\n let current = initial;\n\n const listeners = new Set<() => void>();\n\n return {\n get: () => current,\n subscribe: (listener) => {\n listeners.add(listener);\n\n return () => listeners.delete(listener);\n },\n set(partial) {\n const next = { ...current, ...partial };\n const changed = Object.keys(next).some((key) => current[key as keyof StateData] !== next[key as keyof StateData]);\n\n if (!changed) return;\n current = next;\n\n for (const listener of listeners) listener();\n },\n };\n}\n","import type { LanguageId } from './core/types';\n\nexport type StoredState = { languageId: LanguageId; };\n\nexport type I18nStorage = {\n read(): StoredState | null | Promise<StoredState | null>;\n write(state: StoredState): void | Promise<void>;\n};\n\nexport function createStorageManager(initial: I18nStorage | null = null) {\n let storage = initial;\n\n return {\n setStorage(next: I18nStorage | null): void {\n storage = next;\n },\n getStorage(): I18nStorage {\n if (!storage) throw new Error('[i18n] storage is not configured');\n\n return storage;\n },\n hasStorage(): boolean {\n return storage !== null;\n },\n };\n}\n\nexport function createLocalStorage(): I18nStorage | null {\n if (typeof globalThis.localStorage === 'undefined') return null;\n\n return {\n read() {\n const value = globalThis.localStorage.getItem('fluentic:i18n:state');\n\n if (!value) return null;\n\n try {\n return JSON.parse(value) as StoredState;\n } catch {\n return null;\n }\n },\n write(state) {\n globalThis.localStorage.setItem('fluentic:i18n:state', JSON.stringify(state));\n },\n };\n}\n","import { createRuntime, defaultRuntime, type Formats, getFormats, type Runtime } from './shared/runtime';\nimport { createStateManager } from './state-manager';\nimport { createStorageManager, type I18nStorage } from './storage-manager';\nimport { type Catalog, createTranslationManager, type TranslationLoader } from './translation-manager';\n\nexport type { I18nStorage, StoredState } from './storage-manager';\nexport { defineTranslationLoader } from './translation-manager';\nexport type * from './translation-manager';\n\nexport type StateData = { languageId: string; isLoading: boolean; ready: boolean; };\nexport type I18nManagerOptions = { languageId: string; fallbackLanguageId?: string; };\nexport type CreateI18nManagerOptions = { storage?: I18nStorage | null; runtime?: Runtime; };\nexport type GetTranslationArgs = { languageId?: string; context?: string | null; message: string; };\n\nexport type I18nSnapshot = {\n languageId: string;\n fallbackLanguageId?: string;\n translations: Record<string, Catalog>;\n formats?: Partial<Formats>;\n compiledLanguages?: string[];\n};\n\nexport function createI18nManager(options: CreateI18nManagerOptions = {}) {\n const runtime = options.runtime ?? createRuntime();\n\n const state = createStateManager<StateData>({\n languageId: runtime.languageId,\n isLoading: false,\n ready: runtime.ready,\n });\n const storage = createStorageManager(options.storage ?? null);\n const translations = createTranslationManager();\n\n let fallbackLanguageId: string | undefined;\n let version = 0;\n\n runtime.subscribe = state.subscribe;\n runtime.getSnapshot = state.get;\n\n /* configure */\n\n const configure = (config: I18nManagerOptions) => {\n runtime.languageId = config.languageId;\n runtime.ready = false;\n fallbackLanguageId = config.fallbackLanguageId;\n version++;\n state.set({ languageId: config.languageId, ready: false });\n };\n\n const setTranslationLoader = (loader: TranslationLoader | null) => {\n translations.setTranslationLoader(loader);\n runtime.ready = false;\n state.set({ ready: false });\n };\n\n /* language and translations */\n\n const init = async () => {\n const saved = storage.hasStorage() ? await storage.getStorage().read() : null;\n\n await loadTranslations(saved?.languageId ?? runtime.languageId);\n };\n\n const setLanguageId = async (languageId: string) => {\n const committed = await loadTranslations(languageId);\n\n if (committed && storage.hasStorage()) await storage.getStorage().write({ languageId });\n };\n\n const getLanguageId = () => {\n return runtime.languageId;\n };\n\n const getTranslation = (args: GetTranslationArgs) => {\n for (const languageId of getLanguageIds(args.languageId ?? runtime.languageId)) {\n const value = translations.getTranslation({ ...args, languageId, context: args.context ?? null });\n\n if (value !== null) return value;\n }\n\n return null;\n };\n\n /* snapshots */\n\n const getSnapshot = (): I18nSnapshot => {\n return {\n languageId: runtime.languageId,\n fallbackLanguageId,\n translations: Object.fromEntries(\n Object.entries(translations.catalogs).map(([id, catalog]) => [id, { ...catalog }]),\n ),\n formats: getFormats(runtime, runtime.languageId),\n compiledLanguages: Object.keys(translations.compiledCatalogs).filter((id) => translations.compiledCatalogs[id]),\n };\n };\n\n const hydrate = (snapshot: I18nSnapshot) => {\n version++;\n\n for (const id of Object.keys(translations.catalogs)) delete translations.catalogs[id];\n for (const id of Object.keys(translations.compiledCatalogs)) delete translations.compiledCatalogs[id];\n for (const [id, catalog] of Object.entries(snapshot.translations)) {\n translations.catalogs[id] = Object.assign(Object.create(null), catalog);\n }\n\n for (const id of snapshot.compiledLanguages ?? []) translations.compiledCatalogs[id] = true;\n\n runtime.formats = snapshot.formats ?? {};\n runtime.languageId = snapshot.languageId;\n fallbackLanguageId = snapshot.fallbackLanguageId;\n runtime.ready = true;\n state.set({ languageId: snapshot.languageId, ready: true, isLoading: false });\n };\n\n /* utils */\n\n const getLanguageIds = (languageId: string) => {\n const ids = fallbackLanguageId === undefined\n ? [languageId, languageId.split('-')[0]]\n : [languageId, languageId.split('-')[0], fallbackLanguageId];\n\n return [...new Set(ids)];\n };\n\n const loadTranslations = async (languageId: string) => {\n const current = ++version;\n state.set({ isLoading: true });\n\n try {\n await Promise.all(getLanguageIds(languageId).map(translations.loadTranslations));\n if (version !== current) return false;\n runtime.languageId = languageId;\n runtime.ready = true;\n state.set({ languageId, ready: true, isLoading: false });\n\n return true;\n } finally {\n if (current === version) state.set({ isLoading: false });\n }\n };\n\n const manager = {\n configure,\n setStorage: storage.setStorage,\n setTranslationLoader,\n init,\n setLanguageId,\n getLanguageId,\n getTranslation,\n getSnapshot,\n hydrate,\n };\n\n runtime.translationGetter = (args) => {\n for (const languageId of getLanguageIds(args.languageId)) {\n const compiled = translations.compiledCatalogs[languageId];\n const message = compiled && args.getCompiledId ? args.getCompiledId() : args.message;\n const context = compiled && args.getCompiledId ? null : args.context;\n const value = translations.getTranslation({ languageId, context, message });\n\n if (value !== null) return compiled ? { compiled: value } : value;\n }\n\n return null;\n };\n\n return { manager, state, runtime };\n}\n\nexport type ManagedI18n = ReturnType<typeof createI18nManager>;\nexport type I18nManager = ManagedI18n['manager'];\nexport const defaultManaged = createI18nManager({ runtime: defaultRuntime });\nexport const I18nManager = defaultManaged.manager;\nexport const defaultI18nState = defaultManaged.state;\n"],"mappings":";;AAMA,SAAgB,mBAA6C,SAA6C;CACxG,IAAI,UAAU;CAEd,MAAM,4BAAY,IAAI,IAAgB;CAEtC,OAAO;EACL,WAAW;EACX,YAAY,aAAa;GACvB,UAAU,IAAI,QAAQ;GAEtB,aAAa,UAAU,OAAO,QAAQ;EACxC;EACA,IAAI,SAAS;GACX,MAAM,OAAO;IAAE,GAAG;IAAS,GAAG;GAAQ;GAGtC,IAAI,CAFY,OAAO,KAAK,IAAI,CAAC,CAAC,MAAM,QAAQ,QAAQ,SAA4B,KAAK,IAE9E,GAAG;GACd,UAAU;GAEV,KAAK,MAAM,YAAY,WAAW,SAAS;EAC7C;CACF;AACF;;ACnBA,SAAgB,qBAAqB,UAA8B,MAAM;CACvE,IAAI,UAAU;CAEd,OAAO;EACL,WAAW,MAAgC;GACzC,UAAU;EACZ;EACA,aAA0B;GACxB,IAAI,CAAC,SAAS,MAAM,IAAI,MAAM,kCAAkC;GAEhE,OAAO;EACT;EACA,aAAsB;GACpB,OAAO,YAAY;EACrB;CACF;AACF;AAEA,SAAgB,qBAAyC;CACvD,IAAI,OAAO,WAAW,iBAAiB,aAAa,OAAO;CAE3D,OAAO;EACL,OAAO;GACL,MAAM,QAAQ,WAAW,aAAa,QAAQ,qBAAqB;GAEnE,IAAI,CAAC,OAAO,OAAO;GAEnB,IAAI;IACF,OAAO,KAAK,MAAM,KAAK;GACzB,QAAQ;IACN,OAAO;GACT;EACF;EACA,MAAM,OAAO;GACX,WAAW,aAAa,QAAQ,uBAAuB,KAAK,UAAU,KAAK,CAAC;EAC9E;CACF;AACF;;ACx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,IAAI,eAAe,UAAU,CAAC,CAAC,IAAI,aAAa,gBAAgB,CAAC;GAC/E,IAAI,YAAY,SAAS,OAAO;GAChC,QAAQ,aAAa;GACrB,QAAQ,QAAQ;GAChB,MAAM,IAAI;IAAE;IAAY,OAAO;IAAM,WAAW;GAAM,CAAC;GAEvD,OAAO;EACT,UAAU;GACR,IAAI,YAAY,SAAS,MAAM,IAAI,EAAE,WAAW,MAAM,CAAC;EACzD;CACF;CAEA,MAAM,UAAU;EACd;EACA,YAAY,QAAQ;EACpB;EACA;EACA;EACA;EACA;EACA;EACA;CACF;CAEA,QAAQ,qBAAqB,SAAS;EACpC,KAAK,MAAM,cAAc,eAAe,KAAK,UAAU,GAAG;GACxD,MAAM,WAAW,aAAa,iBAAiB;GAC/C,MAAM,UAAU,YAAY,KAAK,gBAAgB,KAAK,cAAc,IAAI,KAAK;GAC7E,MAAM,UAAU,YAAY,KAAK,gBAAgB,OAAO,KAAK;GAC7D,MAAM,QAAQ,aAAa,eAAe;IAAE;IAAY;IAAS;GAAQ,CAAC;GAE1E,IAAI,UAAU,MAAM,OAAO,WAAW,EAAE,UAAU,MAAM,IAAI;EAC9D;EAEA,OAAO;CACT;CAEA,OAAO;EAAE;EAAS;EAAO;CAAQ;AACnC;AAIA,MAAa,iBAAiB,kBAAkB,EAAE,SAAS,eAAe,CAAC;AAC3E,MAAa,cAAc,eAAe;AAC1C,MAAa,mBAAmB,eAAe"}
|
package/dist/options-Dxxx0aOz.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { createJiti } from "jiti";
|
|
2
|
-
import { existsSync } from "node:fs";
|
|
3
|
-
import { resolve } from "node:path";
|
|
4
|
-
// src/plugin/options.ts
|
|
5
|
-
function loadOptions(options = {}, root = process.cwd()) {
|
|
6
|
-
const file = options.config ? resolve(root, options.config) : [
|
|
7
|
-
"i18n.config.ts",
|
|
8
|
-
"i18n.config.js",
|
|
9
|
-
"i18n.config.mjs"
|
|
10
|
-
].map((name) => resolve(root, name)).find(existsSync);
|
|
11
|
-
const config = file ? createJiti(import.meta.url, { moduleCache: false })(file) : {};
|
|
12
|
-
return {
|
|
13
|
-
...config.default ?? config,
|
|
14
|
-
...options,
|
|
15
|
-
configFile: file
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
function accepts(id, options) {
|
|
19
|
-
return /\.[cm]?[jt]sx?$/.test(id.split("?")[0]) && (options.includeDependencies || !id.includes("/node_modules/"));
|
|
20
|
-
}
|
|
21
|
-
export { loadOptions as n, accepts as t };
|
|
22
|
-
|
|
23
|
-
//# sourceMappingURL=options-Dxxx0aOz.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"options-Dxxx0aOz.js","names":[],"sources":["../src/plugin/options.ts"],"sourcesContent":["import { createJiti } from 'jiti';\nimport { existsSync } from 'node:fs';\nimport { resolve } from 'node:path';\n\nexport type PluginOptions = { compiled?: boolean; config?: string; includeDependencies?: boolean; };\n\nexport function loadOptions(\n options: PluginOptions = {},\n root = process.cwd(),\n): PluginOptions & { configFile?: string; } {\n const file = options.config\n ? resolve(root, options.config)\n : ['i18n.config.ts', 'i18n.config.js', 'i18n.config.mjs'].map((name) => resolve(root, name)).find(existsSync);\n\n const config = file\n ? createJiti(import.meta.url, { moduleCache: false })(file) as { default?: PluginOptions; } & PluginOptions\n : {};\n\n return { ...((config.default ?? config) as PluginOptions), ...options, configFile: file };\n}\n\nexport function accepts(id: string, options: PluginOptions) {\n return /\\.[cm]?[jt]sx?$/.test(id.split('?')[0]) && (options.includeDependencies || !id.includes('/node_modules/'));\n}\n"],"mappings":";;;;AAMA,SAAgB,YACd,UAAyB,CAAC,GAC1B,OAAO,QAAQ,IAAI,GACuB;CAC1C,MAAM,OAAO,QAAQ,SACjB,QAAQ,MAAM,QAAQ,MAAM,IAC5B;EAAC;EAAkB;EAAkB;CAAiB,CAAC,CAAC,KAAK,SAAS,QAAQ,MAAM,IAAI,CAAC,CAAC,CAAC,KAAK,UAAU;CAE9G,MAAM,SAAS,OACX,WAAW,YAAY,KAAK,EAAE,aAAa,MAAM,CAAC,CAAC,CAAC,IAAI,IACxD,CAAC;CAEL,OAAO;EAAE,GAAK,OAAO,WAAW;EAA2B,GAAG;EAAS,YAAY;CAAK;AAC1F;AAEA,SAAgB,QAAQ,IAAY,SAAwB;CAC1D,OAAO,kBAAkB,KAAK,GAAG,MAAM,GAAG,CAAC,CAAC,EAAE,MAAM,QAAQ,uBAAuB,CAAC,GAAG,SAAS,gBAAgB;AAClH"}
|
package/dist/plugin/babel.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { t as PluginOptions } from "../options-DE7vYj0e.js";
|
|
2
|
-
/** Owns parsing even when a host (e.g. Metro) passes an already parsed AST. */
|
|
3
|
-
declare function fluenticBabel(_api: unknown, options?: PluginOptions): {
|
|
4
|
-
name: string;
|
|
5
|
-
parserOverride(code: string, parserOptions: {
|
|
6
|
-
sourceFilename?: string;
|
|
7
|
-
}): import("@babel/parser").ParseResult<import("@babel/types").File> | undefined;
|
|
8
|
-
pre(file: any): void;
|
|
9
|
-
};
|
|
10
|
-
export { fluenticBabel as default };
|
|
11
|
-
//# sourceMappingURL=babel.d.ts.map
|
package/dist/plugin/babel.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { c as traverse, t as compileProgram } from "../compiler-BZtB9WLi.js";
|
|
2
|
-
import { n as loadOptions } from "../options-Dxxx0aOz.js";
|
|
3
|
-
// src/plugin/babel.ts
|
|
4
|
-
/** Owns parsing even when a host (e.g. Metro) passes an already parsed AST. */
|
|
5
|
-
function fluenticBabel(_api, options = {}) {
|
|
6
|
-
const config = loadOptions(options);
|
|
7
|
-
const handled = /* @__PURE__ */ new WeakSet();
|
|
8
|
-
const enabled = (code) => config.compiled && code.includes("@fluentic/i18n");
|
|
9
|
-
const compile = (code, filename) => {
|
|
10
|
-
const { ast } = compileProgram(code, filename, config);
|
|
11
|
-
traverse.cache.clear();
|
|
12
|
-
handled.add(ast.program);
|
|
13
|
-
return ast;
|
|
14
|
-
};
|
|
15
|
-
return {
|
|
16
|
-
name: "fluentic-i18n",
|
|
17
|
-
parserOverride(code, parserOptions) {
|
|
18
|
-
if (!enabled(code)) return void 0;
|
|
19
|
-
return compile(code, parserOptions.sourceFilename ?? "source.tsx");
|
|
20
|
-
},
|
|
21
|
-
pre(file) {
|
|
22
|
-
if (!enabled(file.code) || handled.has(file.path.node)) return;
|
|
23
|
-
const ast = compile(file.code, file.opts.filename ?? "source.tsx");
|
|
24
|
-
file.path.replaceWith(ast.program);
|
|
25
|
-
file.scope.crawl();
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
export { fluenticBabel as default };
|
|
30
|
-
|
|
31
|
-
//# sourceMappingURL=babel.js.map
|
package/dist/plugin/babel.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"babel.js","names":[],"sources":["../../src/plugin/babel.ts"],"sourcesContent":["import { compileProgram } from '../compiler';\nimport { traverse } from '../compiler/analyze';\nimport { loadOptions, type PluginOptions } from './options';\n/** Owns parsing even when a host (e.g. Metro) passes an already parsed AST. */\nexport default function fluenticBabel(_api: unknown, options: PluginOptions = {}) {\n const config = loadOptions(options);\n const handled = new WeakSet<object>();\n const enabled = (code: string) => config.compiled && code.includes('@fluentic/i18n');\n\n const compile = (code: string, filename: string) => {\n const { ast } = compileProgram(code, filename, config);\n // Standalone paths have a default Hub. Babel must create its own paths for presets.\n traverse.cache.clear();\n handled.add(ast.program);\n\n return ast;\n };\n\n return {\n name: 'fluentic-i18n',\n parserOverride(code: string, parserOptions: { sourceFilename?: string; }) {\n if (!enabled(code)) return undefined;\n\n return compile(code, parserOptions.sourceFilename ?? 'source.tsx');\n },\n pre(file: any) {\n if (!enabled(file.code) || handled.has(file.path.node)) return;\n\n const ast = compile(file.code, file.opts.filename ?? 'source.tsx');\n file.path.replaceWith(ast.program);\n file.scope.crawl();\n },\n };\n}\n"],"mappings":";;;;AAIA,SAAwB,cAAc,MAAe,UAAyB,CAAC,GAAG;CAChF,MAAM,SAAS,YAAY,OAAO;CAClC,MAAM,0BAAU,IAAI,QAAgB;CACpC,MAAM,WAAW,SAAiB,OAAO,YAAY,KAAK,SAAS,gBAAgB;CAEnF,MAAM,WAAW,MAAc,aAAqB;EAClD,MAAM,EAAE,QAAQ,eAAe,MAAM,UAAU,MAAM;EAErD,SAAS,MAAM,MAAM;EACrB,QAAQ,IAAI,IAAI,OAAO;EAEvB,OAAO;CACT;CAEA,OAAO;EACL,MAAM;EACN,eAAe,MAAc,eAA6C;GACxE,IAAI,CAAC,QAAQ,IAAI,GAAG,OAAO,KAAA;GAE3B,OAAO,QAAQ,MAAM,cAAc,kBAAkB,YAAY;EACnE;EACA,IAAI,MAAW;GACb,IAAI,CAAC,QAAQ,KAAK,IAAI,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,GAAG;GAExD,MAAM,MAAM,QAAQ,KAAK,MAAM,KAAK,KAAK,YAAY,YAAY;GACjE,KAAK,KAAK,YAAY,IAAI,OAAO;GACjC,KAAK,MAAM,MAAM;EACnB;CACF;AACF"}
|
package/dist/plugin/esbuild.d.ts
DELETED
package/dist/plugin/esbuild.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { n as transform } from "../compiler-BZtB9WLi.js";
|
|
2
|
-
import { n as loadOptions, t as accepts } from "../options-Dxxx0aOz.js";
|
|
3
|
-
import { readFile } from "node:fs/promises";
|
|
4
|
-
// src/plugin/esbuild.ts
|
|
5
|
-
function fluentic(options = {}) {
|
|
6
|
-
return {
|
|
7
|
-
name: "fluentic-i18n",
|
|
8
|
-
setup(build) {
|
|
9
|
-
let config = loadOptions(options, build.initialOptions.absWorkingDir);
|
|
10
|
-
build.onStart(() => {
|
|
11
|
-
config = loadOptions(options, build.initialOptions.absWorkingDir);
|
|
12
|
-
});
|
|
13
|
-
build.onLoad({ filter: /\.jsonl$/ }, async ({ path }) => ({
|
|
14
|
-
contents: await readFile(path, "utf8"),
|
|
15
|
-
loader: "text",
|
|
16
|
-
watchFiles: [path]
|
|
17
|
-
}));
|
|
18
|
-
build.onLoad({ filter: /\.[cm]?[jt]sx?$/ }, async ({ path }) => {
|
|
19
|
-
if (!config.compiled || !accepts(path, config)) return;
|
|
20
|
-
const result = transform(await readFile(path, "utf8"), {
|
|
21
|
-
...config,
|
|
22
|
-
filename: path
|
|
23
|
-
});
|
|
24
|
-
if (!result) return;
|
|
25
|
-
const loader = /\.tsx$/.test(path) ? "tsx" : /\.[cm]?ts$/.test(path) ? "ts" : /\.jsx$/.test(path) ? "jsx" : "js";
|
|
26
|
-
return {
|
|
27
|
-
contents: result.code + "\n//# sourceMappingURL=data:application/json;base64," + Buffer.from(JSON.stringify(result.map)).toString("base64"),
|
|
28
|
-
loader,
|
|
29
|
-
watchFiles: [path, ...config.configFile ? [config.configFile] : []]
|
|
30
|
-
};
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
export { fluentic as default };
|
|
36
|
-
|
|
37
|
-
//# sourceMappingURL=esbuild.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"esbuild.js","names":[],"sources":["../../src/plugin/esbuild.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { transform } from '../compiler';\nimport { accepts, loadOptions, type PluginOptions } from './options';\n\nexport default function fluentic(options: PluginOptions = {}) {\n return {\n name: 'fluentic-i18n',\n setup(build: any) {\n let config = loadOptions(options, build.initialOptions.absWorkingDir);\n build.onStart(() => {\n config = loadOptions(options, build.initialOptions.absWorkingDir);\n });\n build.onLoad(\n { filter: /\\.jsonl$/ },\n async ({ path }: { path: string; }) => ({\n contents: await readFile(path, 'utf8'),\n loader: 'text',\n watchFiles: [path],\n }),\n );\n build.onLoad({ filter: /\\.[cm]?[jt]sx?$/ }, async ({ path }: { path: string; }) => {\n if (!config.compiled || !accepts(path, config)) return;\n\n const result = transform(await readFile(path, 'utf8'), { ...config, filename: path });\n\n if (!result) return;\n\n const loader = /\\.tsx$/.test(path)\n ? 'tsx'\n : /\\.[cm]?ts$/.test(path)\n ? 'ts'\n : /\\.jsx$/.test(path)\n ? 'jsx'\n : 'js';\n\n return {\n contents: result.code + '\\n//# sourceMappingURL=data:application/json;base64,' +\n Buffer.from(JSON.stringify(result.map)).toString('base64'),\n loader,\n watchFiles: [path, ...(config.configFile ? [config.configFile] : [])],\n };\n });\n },\n };\n}\n"],"mappings":";;;;AAIA,SAAwB,SAAS,UAAyB,CAAC,GAAG;CAC5D,OAAO;EACL,MAAM;EACN,MAAM,OAAY;GAChB,IAAI,SAAS,YAAY,SAAS,MAAM,eAAe,aAAa;GACpE,MAAM,cAAc;IAClB,SAAS,YAAY,SAAS,MAAM,eAAe,aAAa;GAClE,CAAC;GACD,MAAM,OACJ,EAAE,QAAQ,WAAW,GACrB,OAAO,EAAE,YAA+B;IACtC,UAAU,MAAM,SAAS,MAAM,MAAM;IACrC,QAAQ;IACR,YAAY,CAAC,IAAI;GACnB,EACF;GACA,MAAM,OAAO,EAAE,QAAQ,kBAAkB,GAAG,OAAO,EAAE,WAA8B;IACjF,IAAI,CAAC,OAAO,YAAY,CAAC,QAAQ,MAAM,MAAM,GAAG;IAEhD,MAAM,SAAS,UAAU,MAAM,SAAS,MAAM,MAAM,GAAG;KAAE,GAAG;KAAQ,UAAU;IAAK,CAAC;IAEpF,IAAI,CAAC,QAAQ;IAEb,MAAM,SAAS,SAAS,KAAK,IAAI,IAC7B,QACA,aAAa,KAAK,IAAI,IACtB,OACA,SAAS,KAAK,IAAI,IAClB,QACA;IAEJ,OAAO;KACL,UAAU,OAAO,OAAO,yDACtB,OAAO,KAAK,KAAK,UAAU,OAAO,GAAG,CAAC,CAAC,CAAC,SAAS,QAAQ;KAC3D;KACA,YAAY,CAAC,MAAM,GAAI,OAAO,aAAa,CAAC,OAAO,UAAU,IAAI,CAAC,CAAE;IACtE;GACF,CAAC;EACH;CACF;AACF"}
|
package/dist/plugin/rollup.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { t as ExtractedMessage } from "../analyze-CdXCxQDg.js";
|
|
2
|
-
import { t as PluginOptions } from "../options-DE7vYj0e.js";
|
|
3
|
-
declare function fluentic(options?: PluginOptions): {
|
|
4
|
-
name: string;
|
|
5
|
-
buildStart(this: {
|
|
6
|
-
addWatchFile(file: string): void;
|
|
7
|
-
}): void;
|
|
8
|
-
watchChange(id: string): void;
|
|
9
|
-
load(id: string): Promise<{
|
|
10
|
-
code: string;
|
|
11
|
-
map: {
|
|
12
|
-
mappings: string;
|
|
13
|
-
};
|
|
14
|
-
} | null>;
|
|
15
|
-
transform(code: string, id: string): {
|
|
16
|
-
code: string;
|
|
17
|
-
map: {
|
|
18
|
-
version: number;
|
|
19
|
-
sources: string[];
|
|
20
|
-
names: string[];
|
|
21
|
-
sourceRoot?: string | undefined;
|
|
22
|
-
sourcesContent?: string[] | undefined;
|
|
23
|
-
mappings: string;
|
|
24
|
-
file: string;
|
|
25
|
-
} | null;
|
|
26
|
-
messages: ExtractedMessage[];
|
|
27
|
-
} | null;
|
|
28
|
-
};
|
|
29
|
-
export { fluentic as default };
|
|
30
|
-
//# sourceMappingURL=rollup.d.ts.map
|
package/dist/plugin/rollup.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { n as transform } from "../compiler-BZtB9WLi.js";
|
|
2
|
-
import { n as loadOptions, t as accepts } from "../options-Dxxx0aOz.js";
|
|
3
|
-
import { readFile } from "node:fs/promises";
|
|
4
|
-
// src/plugin/rollup.ts
|
|
5
|
-
function fluentic(options = {}) {
|
|
6
|
-
let config = loadOptions(options);
|
|
7
|
-
return {
|
|
8
|
-
name: "fluentic-i18n",
|
|
9
|
-
buildStart() {
|
|
10
|
-
if (config.configFile) this.addWatchFile(config.configFile);
|
|
11
|
-
},
|
|
12
|
-
watchChange(id) {
|
|
13
|
-
if (id === config.configFile) config = loadOptions(options);
|
|
14
|
-
},
|
|
15
|
-
async load(id) {
|
|
16
|
-
if (!id.endsWith(".jsonl")) return null;
|
|
17
|
-
const content = await readFile(id, "utf8");
|
|
18
|
-
return {
|
|
19
|
-
code: "export default " + JSON.stringify(content),
|
|
20
|
-
map: { mappings: "" }
|
|
21
|
-
};
|
|
22
|
-
},
|
|
23
|
-
transform(code, id) {
|
|
24
|
-
if (!config.compiled || !accepts(id, config)) return null;
|
|
25
|
-
return transform(code, {
|
|
26
|
-
...config,
|
|
27
|
-
filename: id.split("?")[0]
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
export { fluentic as default };
|
|
33
|
-
|
|
34
|
-
//# sourceMappingURL=rollup.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rollup.js","names":[],"sources":["../../src/plugin/rollup.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { transform } from '../compiler';\nimport { accepts, loadOptions, type PluginOptions } from './options';\n\nexport default function fluentic(options: PluginOptions = {}) {\n let config = loadOptions(options);\n\n return {\n name: 'fluentic-i18n',\n buildStart(this: { addWatchFile(file: string): void; }) {\n if (config.configFile) this.addWatchFile(config.configFile);\n },\n watchChange(id: string) {\n if (id === config.configFile) config = loadOptions(options);\n },\n async load(id: string) {\n if (!id.endsWith('.jsonl')) return null;\n\n const content = await readFile(id, 'utf8');\n\n return { code: 'export default ' + JSON.stringify(content), map: { mappings: '' } };\n },\n transform(code: string, id: string) {\n if (!config.compiled || !accepts(id, config)) return null;\n\n return transform(code, { ...config, filename: id.split('?')[0] });\n },\n };\n}\n"],"mappings":";;;;AAIA,SAAwB,SAAS,UAAyB,CAAC,GAAG;CAC5D,IAAI,SAAS,YAAY,OAAO;CAEhC,OAAO;EACL,MAAM;EACN,aAAwD;GACtD,IAAI,OAAO,YAAY,KAAK,aAAa,OAAO,UAAU;EAC5D;EACA,YAAY,IAAY;GACtB,IAAI,OAAO,OAAO,YAAY,SAAS,YAAY,OAAO;EAC5D;EACA,MAAM,KAAK,IAAY;GACrB,IAAI,CAAC,GAAG,SAAS,QAAQ,GAAG,OAAO;GAEnC,MAAM,UAAU,MAAM,SAAS,IAAI,MAAM;GAEzC,OAAO;IAAE,MAAM,oBAAoB,KAAK,UAAU,OAAO;IAAG,KAAK,EAAE,UAAU,GAAG;GAAE;EACpF;EACA,UAAU,MAAc,IAAY;GAClC,IAAI,CAAC,OAAO,YAAY,CAAC,QAAQ,IAAI,MAAM,GAAG,OAAO;GAErD,OAAO,UAAU,MAAM;IAAE,GAAG;IAAQ,UAAU,GAAG,MAAM,GAAG,CAAC,CAAC;GAAG,CAAC;EAClE;CACF;AACF"}
|
package/dist/plugin/vite.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { t as ExtractedMessage } from "../analyze-CdXCxQDg.js";
|
|
2
|
-
import { t as PluginOptions } from "../options-DE7vYj0e.js";
|
|
3
|
-
declare function fluentic(options?: PluginOptions): {
|
|
4
|
-
enforce: "pre";
|
|
5
|
-
name: string;
|
|
6
|
-
buildStart(this: {
|
|
7
|
-
addWatchFile(file: string): void;
|
|
8
|
-
}): void;
|
|
9
|
-
watchChange(id: string): void;
|
|
10
|
-
load(id: string): Promise<{
|
|
11
|
-
code: string;
|
|
12
|
-
map: {
|
|
13
|
-
mappings: string;
|
|
14
|
-
};
|
|
15
|
-
} | null>;
|
|
16
|
-
transform(code: string, id: string): {
|
|
17
|
-
code: string;
|
|
18
|
-
map: {
|
|
19
|
-
version: number;
|
|
20
|
-
sources: string[];
|
|
21
|
-
names: string[];
|
|
22
|
-
sourceRoot?: string | undefined;
|
|
23
|
-
sourcesContent?: string[] | undefined;
|
|
24
|
-
mappings: string;
|
|
25
|
-
file: string;
|
|
26
|
-
} | null;
|
|
27
|
-
messages: ExtractedMessage[];
|
|
28
|
-
} | null;
|
|
29
|
-
};
|
|
30
|
-
export { fluentic as default };
|
|
31
|
-
//# sourceMappingURL=vite.d.ts.map
|
package/dist/plugin/vite.js
DELETED
package/dist/plugin/vite.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vite.js","names":["rollup"],"sources":["../../src/plugin/vite.ts"],"sourcesContent":["import type { PluginOptions } from './options';\nimport rollup from './rollup';\n\nexport default function fluentic(options: PluginOptions = {}) {\n return { ...rollup(options), enforce: 'pre' as const };\n}\n"],"mappings":";;AAGA,SAAwB,SAAS,UAAyB,CAAC,GAAG;CAC5D,OAAO;EAAE,GAAGA,WAAO,OAAO;EAAG,SAAS;CAAe;AACvD"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { n as transform } from "../compiler-BZtB9WLi.js";
|
|
2
|
-
import { n as loadOptions } from "../options-Dxxx0aOz.js";
|
|
3
|
-
import remapping from "@jridgewell/remapping";
|
|
4
|
-
// src/plugin/webpack-loader.ts
|
|
5
|
-
function loader(code, inputMap) {
|
|
6
|
-
this.cacheable?.();
|
|
7
|
-
const options = loadOptions(this.getOptions?.() ?? {}, this.rootContext);
|
|
8
|
-
if (options.configFile) this.addDependency(options.configFile);
|
|
9
|
-
if (this.resourcePath.endsWith(".jsonl")) {
|
|
10
|
-
this.callback(null, "export default " + JSON.stringify(code));
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
const result = options.compiled ? transform(code, {
|
|
14
|
-
filename: this.resourcePath,
|
|
15
|
-
...options
|
|
16
|
-
}) : null;
|
|
17
|
-
this.callback(null, result?.code ?? code, result?.map && inputMap ? remapping([result.map, inputMap], () => null) : result?.map ?? inputMap);
|
|
18
|
-
}
|
|
19
|
-
export { loader as default };
|
|
20
|
-
|
|
21
|
-
//# sourceMappingURL=webpack-loader.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"webpack-loader.js","names":[],"sources":["../../src/plugin/webpack-loader.ts"],"sourcesContent":["import remapping from '@jridgewell/remapping';\nimport { transform } from '../compiler';\nimport { loadOptions } from './options';\n\nexport default function loader(this: any, code: string, inputMap: unknown) {\n this.cacheable?.();\n const options = loadOptions(this.getOptions?.() ?? {}, this.rootContext);\n\n if (options.configFile) this.addDependency(options.configFile);\n if (this.resourcePath.endsWith('.jsonl')) {\n this.callback(null, 'export default ' + JSON.stringify(code));\n\n return;\n }\n\n const result = options.compiled ? transform(code, { filename: this.resourcePath, ...options }) : null;\n this.callback(\n null,\n result?.code ?? code,\n result?.map && inputMap ? remapping([result.map as any, inputMap as any], () => null) : result?.map ?? inputMap,\n );\n}\n"],"mappings":";;;;AAIA,SAAwB,OAAkB,MAAc,UAAmB;CACzE,KAAK,YAAY;CACjB,MAAM,UAAU,YAAY,KAAK,aAAa,KAAK,CAAC,GAAG,KAAK,WAAW;CAEvE,IAAI,QAAQ,YAAY,KAAK,cAAc,QAAQ,UAAU;CAC7D,IAAI,KAAK,aAAa,SAAS,QAAQ,GAAG;EACxC,KAAK,SAAS,MAAM,oBAAoB,KAAK,UAAU,IAAI,CAAC;EAE5D;CACF;CAEA,MAAM,SAAS,QAAQ,WAAW,UAAU,MAAM;EAAE,UAAU,KAAK;EAAc,GAAG;CAAQ,CAAC,IAAI;CACjG,KAAK,SACH,MACA,QAAQ,QAAQ,MAChB,QAAQ,OAAO,WAAW,UAAU,CAAC,OAAO,KAAY,QAAe,SAAS,IAAI,IAAI,QAAQ,OAAO,QACzG;AACF"}
|
package/dist/plugin/webpack.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { t as PluginOptions } from "../options-DE7vYj0e.js";
|
|
2
|
-
declare class FluenticI18nPlugin {
|
|
3
|
-
private options;
|
|
4
|
-
constructor(options?: PluginOptions);
|
|
5
|
-
apply(compiler: any): void;
|
|
6
|
-
}
|
|
7
|
-
export { FluenticI18nPlugin as default };
|
|
8
|
-
//# sourceMappingURL=webpack.d.ts.map
|
package/dist/plugin/webpack.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { createRequire } from "node:module";
|
|
2
|
-
// src/plugin/webpack.ts
|
|
3
|
-
const require = createRequire(import.meta.url);
|
|
4
|
-
var FluenticI18nPlugin = class {
|
|
5
|
-
constructor(options = {}) {
|
|
6
|
-
this.options = options;
|
|
7
|
-
}
|
|
8
|
-
apply(compiler) {
|
|
9
|
-
compiler.options.module.rules.push({
|
|
10
|
-
test: /(?:\.[cm]?[jt]sx?|\.jsonl)$/,
|
|
11
|
-
enforce: "pre",
|
|
12
|
-
...this.options.includeDependencies ? {} : { exclude: /node_modules/ },
|
|
13
|
-
use: [{
|
|
14
|
-
loader: require.resolve("@fluentic/i18n/plugin/webpack-loader"),
|
|
15
|
-
options: this.options
|
|
16
|
-
}]
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
export { FluenticI18nPlugin as default };
|
|
21
|
-
|
|
22
|
-
//# sourceMappingURL=webpack.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"webpack.js","names":[],"sources":["../../src/plugin/webpack.ts"],"sourcesContent":["import { createRequire } from 'node:module';\nimport type { PluginOptions } from './options';\n\nconst require = createRequire(import.meta.url);\nexport default class FluenticI18nPlugin {\n constructor(private options: PluginOptions = {}) {}\n apply(compiler: any) {\n compiler.options.module.rules.push({\n test: /(?:\\.[cm]?[jt]sx?|\\.jsonl)$/,\n enforce: 'pre',\n ...(this.options.includeDependencies ? {} : { exclude: /node_modules/ }),\n use: [{ loader: require.resolve('@fluentic/i18n/plugin/webpack-loader'), options: this.options }],\n });\n }\n}\n"],"mappings":";;AAGA,MAAM,UAAU,cAAc,YAAY,GAAG;AAC7C,IAAqB,qBAArB,MAAwC;CACtC,YAAY,UAAiC,CAAC,GAAG;EAA7B,KAAA,UAAA;CAA8B;CAClD,MAAM,UAAe;EACnB,SAAS,QAAQ,OAAO,MAAM,KAAK;GACjC,MAAM;GACN,SAAS;GACT,GAAI,KAAK,QAAQ,sBAAsB,CAAC,IAAI,EAAE,SAAS,eAAe;GACtE,KAAK,CAAC;IAAE,QAAQ,QAAQ,QAAQ,sCAAsC;IAAG,SAAS,KAAK;GAAQ,CAAC;EAClG,CAAC;CACH;AACF"}
|
package/dist/src-BovRx-mX.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"src-BovRx-mX.js","names":["formatting"],"sources":["../src/core/i18n.ts","../src/core/format.ts","../src/index.ts"],"sourcesContent":["import type { Formatting } from '../shared/formatting';\nimport { createTagHandler, getRuntime, noTranslate } 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, params?: MessageParams) {\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] : 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 { sha256 } from '@noble/hashes/sha256';\nimport { bytesToHex } from '@noble/hashes/utils';\nimport { IntlMessageFormat } from 'intl-messageformat';\nimport { createFormatting } from '../shared/formatting';\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) => bytesToHex(sha256(context ? `${context}\\0${message}` : message)).slice(0, 24),\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":";;;;;;;;;;;;;;;;;;AAkDA,SAAgB,QAAQ,EAAE,S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mB,GAAG,SACjC,WAAW,gBAAgB,GAAG,IAAI;AACpC,MAAa,gBAAgB;;ACpC7B,MAAa,IAAoB,wBAAQA,cAAU"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"translation-manager-C79eKu2K.js","names":[],"sources":["../src/shared/runtime.ts","../src/translation.ts","../src/translation-manager.ts"],"sourcesContent":["import type { MessageFormatOptions, MessageTagHandler, TranslationGetter } from '../core/types';\n\nexport type Formats = {\n number: Record<string, Intl.NumberFormatOptions>;\n date: Record<string, Intl.DateTimeFormatOptions>;\n time: Record<string, Intl.DateTimeFormatOptions>;\n};\n\nexport type FormatContext = { languageId: string; };\nexport type FormatFactory<T> = T | ((context: FormatContext) => T);\nexport type RegistryConfig = { [K in keyof Formats]: Record<string, FormatFactory<Formats[K][string]>>; };\nexport type PartsRenderer = (runtime?: Runtime) => unknown[];\n\nexport type Runtime = {\n languageId: string;\n ready: boolean;\n translationsEnabled: boolean;\n translationGetter: TranslationGetter | null;\n formats: Partial<Formats>;\n registry: RegistryConfig;\n jsxLineBreak: unknown;\n jsxHandler: ((options: MessageFormatOptions, render: PartsRenderer) => unknown) | null;\n tagElement: ((element: unknown) => (chunks: unknown[]) => unknown) | null;\n subscribe: (listener: () => void) => () => void;\n getSnapshot: () => unknown;\n};\n\nexport function createRuntime(): Runtime {\n return {\n languageId: 'en',\n ready: false,\n translationsEnabled: true,\n translationGetter: null,\n formats: {},\n registry: { number: {}, date: {}, time: {} },\n jsxLineBreak: '\\n',\n jsxHandler: null,\n tagElement: null,\n subscribe: () => () => {},\n getSnapshot: () => null,\n };\n}\n\nexport const defaultRuntime = createRuntime();\nlet resolver = () => defaultRuntime;\n\nexport function setRuntimeResolver(next: () => Runtime): void {\n resolver = next;\n}\n\nexport function getRuntime(): Runtime {\n return resolver();\n}\n\nexport function setTranslationGetter(getter: TranslationGetter | null): void {\n getRuntime().translationGetter = getter;\n}\n\nexport function setLanguageId(languageId: string): void {\n getRuntime().languageId = languageId;\n}\n\nexport function setFormats(formats: Partial<Formats>): void {\n getRuntime().formats = formats;\n}\n\nexport function setGetJsxHandler(handler: Runtime['jsxHandler']): void {\n getRuntime().jsxHandler = handler;\n}\n\nexport const I18nRegistry = {\n addNumberFormat(name: string, format: FormatFactory<Intl.NumberFormatOptions>) {\n getRuntime().registry.number[name] = format;\n },\n addDateFormat(name: string, format: FormatFactory<Intl.DateTimeFormatOptions>) {\n getRuntime().registry.date[name] = format;\n },\n addTimeFormat(name: string, format: FormatFactory<Intl.DateTimeFormatOptions>) {\n getRuntime().registry.time[name] = format;\n },\n setLanguageId,\n getConfig(): RegistryConfig {\n const r = getRuntime().registry;\n\n return { number: { ...r.number }, date: { ...r.date }, time: { ...r.time } };\n },\n};\n\nexport function getFormats(runtime: Runtime, languageId: string): Partial<Formats> {\n const resolve = <T>(entries: Record<string, FormatFactory<T>>) =>\n Object.fromEntries(\n Object.entries(entries).map((\n [key, value],\n ) => [key, typeof value === 'function' ? (value as (context: FormatContext) => T)({ languageId }) : value]),\n );\n\n return {\n number: { ...runtime.formats.number, ...resolve(runtime.registry.number) },\n date: { ...runtime.formats.date, ...resolve(runtime.registry.date) },\n time: { ...runtime.formats.time, ...resolve(runtime.registry.time) },\n };\n}\n\nexport function noTranslate<T>(fn: () => T): T {\n const runtime = getRuntime();\n const previous = runtime.translationsEnabled;\n runtime.translationsEnabled = false;\n\n try {\n return fn();\n } finally {\n runtime.translationsEnabled = previous;\n }\n}\n\nexport function createTagHandler<T, R>(handler: (chunks: Array<string | T>) => R): MessageTagHandler<T, R> {\n Object.defineProperty(handler, '__fluenticTagHandler', { value: true });\n\n return handler as MessageTagHandler<T, R>;\n}\n/** Synchronous binding only: async callers must keep and use their own instance. */\nexport function withRuntime<T>(runtime: Runtime, fn: () => T): T {\n const previous = resolver;\n resolver = () => runtime;\n\n try {\n return fn();\n } finally {\n resolver = previous;\n }\n}\n","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>;\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 { catalogs, compiledCatalogs, setTranslationLoader, loadTranslations, getTranslation };\n}\n"],"mappings":";;AA2BA,SAAgB,gBAAyB;CACvC,OAAO;EACL,YAAY;EACZ,OAAO;EACP,qBAAqB;EACrB,mBAAmB;EACnB,SAAS,CAAC;EACV,UAAU;GAAE,QAAQ,CAAC;GAAG,MAAM,CAAC;GAAG,MAAM,CAAC;EAAE;EAC3C,cAAc;EACd,YAAY;EACZ,YAAY;EACZ,uBAAuB,CAAC;EACxB,mBAAmB;CACrB;AACF;AAEA,MAAa,iBAAiB,cAAc;AAC5C,IAAI,iBAAiB;AAErB,SAAgB,mBAAmB,MAA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,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;EAAE;EAAU;EAAkB;EAAsB;EAAkB;CAAe;AAC9F"}
|
package/dist/types-BuGoCU3P.d.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { n as CompactMessage } from "./compact-CJ0OWoIv.js";
|
|
2
|
-
interface I18nJsxConfig {}
|
|
3
|
-
type I18nJsxOutput = I18nJsxConfig extends {
|
|
4
|
-
JSX: infer Output;
|
|
5
|
-
} ? NonNullable<Output> : unknown;
|
|
6
|
-
type I18nTagElement = I18nJsxConfig extends {
|
|
7
|
-
Element: infer Element;
|
|
8
|
-
} ? Element : never;
|
|
9
|
-
type I18nTagValue = I18nJsxConfig extends {
|
|
10
|
-
Value: infer Value;
|
|
11
|
-
} ? Value : unknown;
|
|
12
|
-
type PrimitiveType = string | number | boolean | null | undefined;
|
|
13
|
-
type LanguageId = string;
|
|
14
|
-
type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
15
|
-
[key: string]: JsonValue;
|
|
16
|
-
};
|
|
17
|
-
type MessageMeta = JsonValue;
|
|
18
|
-
type MessageContext = string;
|
|
19
|
-
type MessageSchemaValue = StringConstructor | NumberConstructor | BooleanConstructor | DateConstructor;
|
|
20
|
-
type MessageSchema = Partial<Record<string, MessageSchemaValue>>;
|
|
21
|
-
type InferMessageSchema<Schema extends MessageSchema> = { [Key in keyof Schema]: Schema[Key] extends StringConstructor ? string : Schema[Key] extends NumberConstructor ? number : Schema[Key] extends BooleanConstructor ? boolean : Schema[Key] extends DateConstructor ? Date : never; };
|
|
22
|
-
type MessageDescriptor<Text extends string = string, Schema extends MessageSchema | undefined = MessageSchema> = {
|
|
23
|
-
readonly __fluenticMessage: true;
|
|
24
|
-
readonly text: Text;
|
|
25
|
-
readonly compiled?: readonly [string, CompactMessage];
|
|
26
|
-
readonly context: MessageContext | null;
|
|
27
|
-
readonly schema: Schema extends MessageSchema ? Schema : MessageSchema;
|
|
28
|
-
readonly notes: readonly string[];
|
|
29
|
-
readonly meta: MessageMeta | undefined;
|
|
30
|
-
};
|
|
31
|
-
type AnyMessageDescriptor = MessageDescriptor<string, MessageSchema | undefined>;
|
|
32
|
-
type MessageValueContext = {
|
|
33
|
-
languageId: LanguageId;
|
|
34
|
-
};
|
|
35
|
-
type MessageValueFactory<T = unknown> = (context: MessageValueContext) => T;
|
|
36
|
-
type MessageTagHandler<T = unknown, R = unknown> = ((chunks: Array<string | T>) => R) & {
|
|
37
|
-
readonly __fluenticTagHandler: true;
|
|
38
|
-
};
|
|
39
|
-
type MessageRuntimeValue = PrimitiveType | Date | AnyMessageDescriptor | MessageValueFactory | Pick<MessageTagHandler, '__fluenticTagHandler'>;
|
|
40
|
-
type MessageParam = MessageRuntimeValue;
|
|
41
|
-
type MessageParams = Record<string, MessageParam>;
|
|
42
|
-
type MessageInput = string | AnyMessageDescriptor;
|
|
43
|
-
type InferRuntimeParams<Schema extends MessageSchema> = { [Key in keyof InferMessageSchema<Schema>]: InferMessageSchema<Schema>[Key] | MessageValueFactory<InferMessageSchema<Schema>[Key]>; };
|
|
44
|
-
type DescriptorRenderArgs<Schema extends MessageSchema | undefined> = Schema extends undefined ? [params?: MessageParams] : keyof Schema extends never ? [] : Schema extends MessageSchema ? [params: InferRuntimeParams<Schema>] : never;
|
|
45
|
-
type TryRenderArgs<Value> = Value extends {
|
|
46
|
-
readonly __fluenticMessage: true;
|
|
47
|
-
} ? Value extends MessageDescriptor<string, infer Schema> ? Schema extends MessageSchema | undefined ? DescriptorRenderArgs<Schema> : [params: MessageParams] : [params: MessageParams] : [params?: MessageParams];
|
|
48
|
-
type TextRenderer = {
|
|
49
|
-
<Text extends string>(message: Text, params?: MessageParams): string;
|
|
50
|
-
<Text extends string, Schema extends MessageSchema | undefined>(message: MessageDescriptor<Text, Schema>, ...args: DescriptorRenderArgs<Schema>): string;
|
|
51
|
-
};
|
|
52
|
-
type JsxRenderer<Output = unknown> = {
|
|
53
|
-
<Text extends string>(message: Text, params?: MessageParams): Output;
|
|
54
|
-
<Text extends string, Schema extends MessageSchema | undefined>(message: MessageDescriptor<Text, Schema>, ...args: DescriptorRenderArgs<Schema>): Output;
|
|
55
|
-
};
|
|
56
|
-
type MessageFormatOptions = {
|
|
57
|
-
msg: MessageInput;
|
|
58
|
-
params?: MessageParams;
|
|
59
|
-
languageId?: LanguageId;
|
|
60
|
-
};
|
|
61
|
-
type GetJsxHandler<Output = unknown> = (options: MessageFormatOptions) => Output;
|
|
62
|
-
type CompiledTranslation = {
|
|
63
|
-
compiled: CompactMessage;
|
|
64
|
-
};
|
|
65
|
-
type TranslationGetter = (args: {
|
|
66
|
-
languageId: LanguageId;
|
|
67
|
-
context: MessageContext | null;
|
|
68
|
-
message: string;
|
|
69
|
-
getCompiledId?: () => string;
|
|
70
|
-
}) => CompactMessage | CompiledTranslation | null;
|
|
71
|
-
declare function isMessageDescriptor(value: unknown): value is AnyMessageDescriptor;
|
|
72
|
-
declare function isMessageTagHandler(value: unknown): value is MessageTagHandler;
|
|
73
|
-
declare function isMessageSchemaValue(value: unknown): value is MessageSchemaValue;
|
|
74
|
-
export { isMessageDescriptor as A, MessageTagHandler as C, TextRenderer as D, PrimitiveType as E, isMessageTagHandler as M, I18nJsxConfig as N, TranslationGetter as O, MessageSchemaValue as S, MessageValueFactory as T, MessageMeta as _, I18nJsxOutput as a, MessageRuntimeValue as b, InferMessageSchema as c, JsxRenderer as d, LanguageId as f, MessageInput as g, MessageFormatOptions as h, GetJsxHandler as i, isMessageSchemaValue as j, TryRenderArgs as k, InferRuntimeParams as l, MessageDescriptor as m, CompiledTranslation as n, I18nTagElement as o, MessageContext as p, DescriptorRenderArgs as r, I18nTagValue as s, AnyMessageDescriptor as t, JsonValue as u, MessageParam as v, MessageValueContext as w, MessageSchema as x, MessageParams as y };
|
|
75
|
-
//# sourceMappingURL=types-BuGoCU3P.d.ts.map
|