@fluentic/i18n 0.0.0-stage → 0.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/LICENSE +21 -0
  3. package/README.md +21 -2
  4. package/dist/adapter-CWC8rng-.d.ts +178 -0
  5. package/dist/adapter.d.ts +4 -0
  6. package/dist/adapter.js +4 -0
  7. package/dist/analyze-CdXCxQDg.d.ts +14 -0
  8. package/dist/compact-CJ0OWoIv.d.ts +7 -0
  9. package/dist/compact-E3zj3Z8d.js +34 -0
  10. package/dist/compact-E3zj3Z8d.js.map +1 -0
  11. package/dist/compiled.d.ts +27 -0
  12. package/dist/compiled.js +51 -0
  13. package/dist/compiled.js.map +1 -0
  14. package/dist/compiler-BZtB9WLi.js +365 -0
  15. package/dist/compiler-BZtB9WLi.js.map +1 -0
  16. package/dist/compiler.d.ts +35 -0
  17. package/dist/compiler.js +3 -0
  18. package/dist/core/index.d.ts +5 -0
  19. package/dist/core/index.js +4 -0
  20. package/dist/i18n-CfYNwubL.d.ts +25 -0
  21. package/dist/index.d.ts +6 -0
  22. package/dist/index.js +4 -0
  23. package/dist/interpreter-Dld8QyOI.js +186 -0
  24. package/dist/interpreter-Dld8QyOI.js.map +1 -0
  25. package/dist/manager-BW778X1Y.js +193 -0
  26. package/dist/manager-BW778X1Y.js.map +1 -0
  27. package/dist/options-DE7vYj0e.d.ts +7 -0
  28. package/dist/options-Dxxx0aOz.js +23 -0
  29. package/dist/options-Dxxx0aOz.js.map +1 -0
  30. package/dist/plugin/babel.d.ts +11 -0
  31. package/dist/plugin/babel.js +31 -0
  32. package/dist/plugin/babel.js.map +1 -0
  33. package/dist/plugin/esbuild.d.ts +7 -0
  34. package/dist/plugin/esbuild.js +37 -0
  35. package/dist/plugin/esbuild.js.map +1 -0
  36. package/dist/plugin/rollup.d.ts +30 -0
  37. package/dist/plugin/rollup.js +34 -0
  38. package/dist/plugin/rollup.js.map +1 -0
  39. package/dist/plugin/vite.d.ts +31 -0
  40. package/dist/plugin/vite.js +11 -0
  41. package/dist/plugin/vite.js.map +1 -0
  42. package/dist/plugin/webpack-loader.d.ts +3 -0
  43. package/dist/plugin/webpack-loader.js +21 -0
  44. package/dist/plugin/webpack-loader.js.map +1 -0
  45. package/dist/plugin/webpack.d.ts +8 -0
  46. package/dist/plugin/webpack.js +22 -0
  47. package/dist/plugin/webpack.js.map +1 -0
  48. package/dist/react.d.ts +53 -0
  49. package/dist/react.js +60 -0
  50. package/dist/react.js.map +1 -0
  51. package/dist/src-BovRx-mX.js +142 -0
  52. package/dist/src-BovRx-mX.js.map +1 -0
  53. package/dist/translation-manager-C79eKu2K.js +213 -0
  54. package/dist/translation-manager-C79eKu2K.js.map +1 -0
  55. package/dist/types-BkDsJfVD.js +13 -0
  56. package/dist/types-BkDsJfVD.js.map +1 -0
  57. package/dist/types-BuGoCU3P.d.ts +75 -0
  58. package/dist/types.d.ts +2 -0
  59. package/dist/types.js +1 -0
  60. package/dist-cjs/babel.cjs +379 -0
  61. package/dist-cjs/babel.cjs.map +1 -0
  62. package/package.json +130 -3
  63. package/src/adapter.ts +6 -0
  64. package/src/compiled.ts +116 -0
  65. package/src/compiler/analyze.ts +182 -0
  66. package/src/compiler/index.ts +208 -0
  67. package/src/compiler/message.ts +74 -0
  68. package/src/core/format.ts +40 -0
  69. package/src/core/i18n.ts +124 -0
  70. package/src/core/index.ts +1 -0
  71. package/src/core/types.ts +121 -0
  72. package/src/index.ts +9 -0
  73. package/src/manager.ts +175 -0
  74. package/src/plugin/babel.ts +34 -0
  75. package/src/plugin/esbuild.ts +45 -0
  76. package/src/plugin/options.ts +24 -0
  77. package/src/plugin/rollup.ts +29 -0
  78. package/src/plugin/vite.ts +6 -0
  79. package/src/plugin/webpack-loader.ts +22 -0
  80. package/src/plugin/webpack.ts +15 -0
  81. package/src/react.ts +97 -0
  82. package/src/registry-manager.ts +3 -0
  83. package/src/shared/compact.ts +51 -0
  84. package/src/shared/formatting.ts +121 -0
  85. package/src/shared/interpreter.ts +128 -0
  86. package/src/shared/runtime.ts +131 -0
  87. package/src/state-manager.ts +29 -0
  88. package/src/state.ts +20 -0
  89. package/src/storage-manager.ts +47 -0
  90. package/src/translation-manager.ts +82 -0
  91. package/src/translation.ts +106 -0
  92. package/src/types.ts +2 -0
@@ -0,0 +1,365 @@
1
+ import * as generatorModule from "@babel/generator";
2
+ import * as b from "@babel/types";
3
+ import { parse } from "@babel/parser";
4
+ import * as traverseModule from "@babel/traverse";
5
+ import { TYPE, parse as parse$1 } from "@formatjs/icu-messageformat-parser";
6
+ import { createHash } from "node:crypto";
7
+ // src/compiler/analyze.ts
8
+ const traverse = traverseModule.default.default ?? traverseModule.default;
9
+ const importMap = {
10
+ "@fluentic/i18n": "@fluentic/i18n/compiled",
11
+ "@fluentic/i18n/core": "@fluentic/i18n/compiled"
12
+ };
13
+ function parseSource(code, filename) {
14
+ return parse(code, {
15
+ sourceFilename: filename,
16
+ sourceType: "unambiguous",
17
+ plugins: [
18
+ .../\.[cm]?tsx?$/.test(filename) ? ["typescript"] : [],
19
+ ...!/\.[cm]?ts$/.test(filename) ? ["jsx"] : [],
20
+ "decorators-legacy",
21
+ "importAttributes"
22
+ ]
23
+ });
24
+ }
25
+ function unwrap(path) {
26
+ while (path.isTSAsExpression() || path.isTSSatisfiesExpression() || path.isTSNonNullExpression() || path.isTypeCastExpression() || path.isParenthesizedExpression()) path = path.get("expression");
27
+ return path;
28
+ }
29
+ function literal(path, seen = /* @__PURE__ */ new Set()) {
30
+ path = unwrap(path);
31
+ if (path.isStringLiteral()) return path.node.value;
32
+ if (path.isTemplateLiteral() && !path.node.expressions.length) return path.node.quasis[0].value.cooked ?? "";
33
+ if (path.isIdentifier()) {
34
+ const binding = path.scope.getBinding(path.node.name);
35
+ if (binding?.constant && binding.path.isVariableDeclarator() && !seen.has(binding)) {
36
+ seen.add(binding);
37
+ return literal(binding.path.get("init"), seen);
38
+ }
39
+ }
40
+ return null;
41
+ }
42
+ function memberName(path) {
43
+ if (!path.isMemberExpression()) return null;
44
+ const property = path.get("property");
45
+ return !path.node.computed && property.isIdentifier() ? property.node.name : property.isStringLiteral() ? property.node.value : null;
46
+ }
47
+ function analyzer(imports = Object.keys(importMap)) {
48
+ const memo = /* @__PURE__ */ new Map();
49
+ const scopedBindings = /* @__PURE__ */ new Set();
50
+ const scopeCalls = /* @__PURE__ */ new Set();
51
+ const resolve = (path, visiting = /* @__PURE__ */ new Set()) => {
52
+ path = unwrap(path);
53
+ if (path.isIdentifier()) {
54
+ const binding = path.scope.getBinding(path.node.name);
55
+ if (!binding) return null;
56
+ if (memo.has(binding)) return memo.get(binding);
57
+ if (visiting.has(binding)) throw new Error("[i18n] circular translator alias");
58
+ if (binding.path.isImportSpecifier()) {
59
+ const declaration = binding.path.parentPath;
60
+ const imported = binding.path.node.imported;
61
+ return declaration.isImportDeclaration() && imports.includes(declaration.node.source.value) && (b.isIdentifier(imported) ? imported.name : imported.value) === "t" && declaration.node.importKind !== "type" ? {
62
+ context: null,
63
+ notes: []
64
+ } : null;
65
+ }
66
+ if (binding.path.isVariableDeclarator()) {
67
+ visiting.add(binding);
68
+ const scope = resolve(binding.path.get("init"), visiting);
69
+ visiting.delete(binding);
70
+ if (scope && !binding.constant) throw new Error("[i18n] translator aliases must not be reassigned: " + path.node.name);
71
+ memo.set(binding, scope);
72
+ if (scope) scopedBindings.add(binding);
73
+ return scope;
74
+ }
75
+ return null;
76
+ }
77
+ if (path.isMemberExpression() && memberName(path) === "t") {
78
+ const object = path.get("object");
79
+ if (!object.isIdentifier()) return null;
80
+ const binding = object.scope.getBinding(object.node.name);
81
+ const declaration = binding?.path.parentPath;
82
+ if (binding?.path.isImportNamespaceSpecifier() && declaration?.isImportDeclaration() && imports.includes(declaration.node.source.value)) return {
83
+ context: null,
84
+ notes: []
85
+ };
86
+ }
87
+ if (!path.isCallExpression()) return null;
88
+ const callee = path.get("callee");
89
+ const method = memberName(callee);
90
+ if (!method || ![
91
+ "context",
92
+ "note",
93
+ "meta"
94
+ ].includes(method)) return null;
95
+ const parent = resolve(callee.get("object"), visiting);
96
+ if (!parent) return null;
97
+ if (path.node.arguments.length !== 1) throw new Error("[i18n] scope methods require one static argument");
98
+ const argument = path.get("arguments.0");
99
+ scopeCalls.add(path);
100
+ if (method === "meta") {
101
+ const evaluated = argument.evaluate();
102
+ if (!evaluated.confident) throw new Error("[i18n] metadata must be statically known");
103
+ return {
104
+ ...parent,
105
+ meta: evaluated.value
106
+ };
107
+ }
108
+ const value = literal(argument);
109
+ if (value === null) throw new Error("[i18n] " + method + " must be a static string");
110
+ return method === "note" ? {
111
+ ...parent,
112
+ notes: [...parent.notes, value]
113
+ } : {
114
+ ...parent,
115
+ context: parent.context ? `${parent.context}.${value}` : value
116
+ };
117
+ };
118
+ return {
119
+ resolve,
120
+ scopedBindings,
121
+ scopeCalls
122
+ };
123
+ }
124
+ function collectMessages(code, filename, imports) {
125
+ const ast = parseSource(code, filename);
126
+ const { resolve } = analyzer(imports);
127
+ const messages = [];
128
+ traverse(ast, { CallExpression(path) {
129
+ const callee = path.get("callee");
130
+ const method = memberName(callee);
131
+ if (!method || ![
132
+ "msg",
133
+ "text",
134
+ "jsx"
135
+ ].includes(method)) return;
136
+ const scope = resolve(callee.get("object"));
137
+ if (!scope) return;
138
+ const source = literal(path.get("arguments.0"));
139
+ if (source === null) {
140
+ if (method === "msg") throw new Error(`[i18n] ${filename}:${path.node.loc?.start.line}: t.msg requires a static message`);
141
+ return;
142
+ }
143
+ messages.push({
144
+ ...scope,
145
+ id: scope.context ? `${scope.context}\0${source}` : source,
146
+ source
147
+ });
148
+ } });
149
+ return [...new Map(messages.map((message) => [message.id, message])).values()];
150
+ }
151
+ // src/compiler/message.ts
152
+ function messageIdentity(context, source) {
153
+ return context ? `${context}\0${source}` : source;
154
+ }
155
+ function messageId(context, source) {
156
+ return createHash("sha256").update(messageIdentity(context, source)).digest("hex").slice(0, 24);
157
+ }
158
+ function compileMessage(source) {
159
+ const compact = (elements) => {
160
+ const result = elements.map((element) => {
161
+ switch (element.type) {
162
+ case TYPE.literal: return element.value;
163
+ case TYPE.argument: return [0, element.value];
164
+ case TYPE.number:
165
+ case TYPE.date:
166
+ case TYPE.time: return [
167
+ element.type === TYPE.number ? 1 : element.type === TYPE.date ? 2 : 3,
168
+ element.value,
169
+ typeof element.style === "object" && element.style ? element.style.parsedOptions : element.style ?? null
170
+ ];
171
+ case TYPE.select: return [
172
+ 4,
173
+ element.value,
174
+ Object.fromEntries(Object.entries(element.options).map(([key, option]) => [key, compact(option.value)]))
175
+ ];
176
+ case TYPE.plural: return [
177
+ 5,
178
+ element.value,
179
+ element.offset,
180
+ element.pluralType === "ordinal" ? 1 : 0,
181
+ Object.fromEntries(Object.entries(element.options).map(([key, option]) => [key, compact(option.value)]))
182
+ ];
183
+ case TYPE.pound: return [6];
184
+ case TYPE.tag: return [
185
+ 7,
186
+ element.value,
187
+ compact(element.children)
188
+ ];
189
+ }
190
+ });
191
+ return result.every((part) => typeof part === "string") ? result.join("") : result;
192
+ };
193
+ return compact(parse$1(source, { captureLocation: false }));
194
+ }
195
+ function compileCatalog(records) {
196
+ const seen = /* @__PURE__ */ new Map();
197
+ return records.flatMap((record) => {
198
+ const id = messageId(record.context, record.source);
199
+ const identity = messageIdentity(record.context, record.source);
200
+ if (seen.has(id) && seen.get(id) !== identity) throw new Error("[i18n] message hash collision: " + id);
201
+ seen.set(id, identity);
202
+ return record.translation === "" ? [] : [[id, compileMessage(record.translation)]];
203
+ });
204
+ }
205
+ // src/compiler/index.ts
206
+ const generate = generatorModule.default.default ?? generatorModule.default;
207
+ function compileProgram(code, filename, options = {}) {
208
+ const ast = parseSource(code, filename);
209
+ const messages = [];
210
+ if (options.compiled === false) return {
211
+ ast,
212
+ messages,
213
+ changed: false
214
+ };
215
+ const analysis = analyzer();
216
+ const plans = [];
217
+ const declarations = [];
218
+ let program;
219
+ traverse(ast, {
220
+ Program(path) {
221
+ program = path;
222
+ },
223
+ ExportAllDeclaration(path) {
224
+ if (importMap[path.node.source.value]) throw new Error("[i18n] do not re-export the translator in compiled mode; import t directly at each use");
225
+ },
226
+ ExportNamedDeclaration(path) {
227
+ if (path.node.source && importMap[path.node.source.value] && path.node.specifiers.some((specifier) => b.isExportSpecifier(specifier) && (b.isIdentifier(specifier.local) ? specifier.local.name : "") === "t")) throw new Error("[i18n] do not re-export the translator in compiled mode; export message descriptors instead");
228
+ },
229
+ ImportDeclaration(path) {
230
+ if (importMap[path.node.source.value] && path.node.importKind !== "type") declarations.push(path);
231
+ },
232
+ CallExpression(path) {
233
+ const callee = path.get("callee");
234
+ const method = memberName(callee);
235
+ if (!method || ![
236
+ "msg",
237
+ "jsx",
238
+ "text"
239
+ ].includes(method)) return;
240
+ const scope = analysis.resolve(callee.get("object"));
241
+ if (!scope) return;
242
+ const source = literal(path.get("arguments.0"));
243
+ if (source === null && method === "msg") throw new Error(`[i18n] ${filename}:${path.node.loc?.start.line}: t.msg requires a static message`);
244
+ plans.push({
245
+ path,
246
+ source,
247
+ scope
248
+ });
249
+ if (source !== null) messages.push({
250
+ ...scope,
251
+ source,
252
+ id: scope.context ? `${scope.context}\0${source}` : source
253
+ });
254
+ }
255
+ });
256
+ traverse(ast, {
257
+ VariableDeclarator(path) {
258
+ analysis.resolve(path.get("id"));
259
+ },
260
+ CallExpression(path) {
261
+ const name = memberName(path.get("callee"));
262
+ if (name && [
263
+ "context",
264
+ "note",
265
+ "meta"
266
+ ].includes(name)) analysis.resolve(path);
267
+ }
268
+ });
269
+ const expressionUse = (path) => {
270
+ while (path.parentPath && (path.parentPath.isTSAsExpression() || path.parentPath.isTSSatisfiesExpression() || path.parentPath.isTSNonNullExpression() || path.parentPath.isTypeCastExpression() || path.parentPath.isParenthesizedExpression())) path = path.parentPath;
271
+ return path;
272
+ };
273
+ for (const path of analysis.scopeCalls) {
274
+ const use = expressionUse(path);
275
+ const parent = use.parentPath;
276
+ if (parent?.isVariableDeclarator() || parent?.isExpressionStatement()) continue;
277
+ if (parent?.isMemberExpression() && parent.get("object") === use && parent.parentPath?.isCallExpression()) continue;
278
+ throw new Error("[i18n] scoped translator escapes same-file message calls");
279
+ }
280
+ for (const binding of analysis.scopedBindings) {
281
+ if (binding.path.parentPath?.parentPath?.isExportNamedDeclaration()) throw new Error("[i18n] scoped translators cannot be exported; repeat the context in the consuming file");
282
+ for (const reference of binding.referencePaths) {
283
+ if (reference.findParent((parent) => parent.isTSType())) continue;
284
+ const use = expressionUse(reference);
285
+ const parent = use.parentPath;
286
+ if (parent?.isVariableDeclarator() && parent.get("init") === use) continue;
287
+ if (parent?.isMemberExpression() && parent.get("object") === use) {
288
+ const method = memberName(parent);
289
+ if (method && [
290
+ "msg",
291
+ "text",
292
+ "jsx",
293
+ "context",
294
+ "note",
295
+ "meta"
296
+ ].includes(method) && parent.parentPath?.isCallExpression()) continue;
297
+ }
298
+ throw new Error("[i18n] scoped translator escapes same-file message calls: " + binding.identifier.name);
299
+ }
300
+ }
301
+ if (!declarations.length) return {
302
+ ast,
303
+ messages,
304
+ changed: false
305
+ };
306
+ const helper = program.scope.generateUidIdentifier("tc");
307
+ if (plans.length) program.unshiftContainer("body", b.importDeclaration([b.importSpecifier(helper, b.identifier("t"))], b.stringLiteral("@fluentic/i18n/compiled")));
308
+ for (const { path, source, scope } of plans) {
309
+ path.get("callee").get("object").replaceWith(b.cloneNode(helper));
310
+ if (source !== null) {
311
+ const replacement = b.valueToNode([messageId(scope.context, source), compileMessage(source)]);
312
+ b.inherits(replacement, path.node.arguments[0]);
313
+ path.node.arguments[0] = replacement;
314
+ }
315
+ }
316
+ let removed = true;
317
+ while (removed) {
318
+ removed = false;
319
+ program.scope.crawl();
320
+ for (const binding of analysis.scopedBindings) {
321
+ if (binding.path.removed) continue;
322
+ const current = binding.path.scope.getBinding(binding.identifier.name);
323
+ if (current && !current.referenced) {
324
+ binding.path.remove();
325
+ removed = true;
326
+ }
327
+ }
328
+ }
329
+ for (const path of analysis.scopeCalls) if (!path.removed) {
330
+ const use = expressionUse(path);
331
+ if (use.parentPath?.isExpressionStatement()) use.parentPath.remove();
332
+ }
333
+ for (const declaration of declarations) declaration.node.source.value = importMap[declaration.node.source.value];
334
+ program.scope.crawl();
335
+ for (const declaration of declarations) {
336
+ declaration.node.specifiers = declaration.node.specifiers.filter((specifier) => {
337
+ if (!b.isImportSpecifier(specifier) || (b.isIdentifier(specifier.imported) ? specifier.imported.name : specifier.imported.value) !== "t") return true;
338
+ return Boolean(program.scope.getBinding(specifier.local.name)?.referenced);
339
+ });
340
+ if (!declaration.node.specifiers.length) declaration.remove();
341
+ }
342
+ return {
343
+ ast,
344
+ messages,
345
+ changed: true
346
+ };
347
+ }
348
+ function transform(code, options = {}) {
349
+ const filename = options.filename ?? "source.tsx";
350
+ const result = compileProgram(code, filename, options);
351
+ if (!result.changed) return null;
352
+ const output = generate(result.ast, {
353
+ sourceMaps: true,
354
+ sourceFileName: filename,
355
+ comments: true
356
+ }, code);
357
+ return {
358
+ code: output.code,
359
+ map: output.map,
360
+ messages: result.messages
361
+ };
362
+ }
363
+ export { messageId as a, traverse as c, compileMessage as i, transform as n, messageIdentity as o, compileCatalog as r, collectMessages as s, compileProgram as t };
364
+
365
+ //# sourceMappingURL=compiler-BZtB9WLi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiler-BZtB9WLi.js","names":["parse"],"sources":["../src/compiler/analyze.ts","../src/compiler/message.ts","../src/compiler/index.ts"],"sourcesContent":["import { parse } from '@babel/parser';\nimport * as traverseModule from '@babel/traverse';\nimport type { Binding, NodePath } from '@babel/traverse';\nimport * as b from '@babel/types';\n\nconst traverse = ((traverseModule.default as unknown as { default?: typeof traverseModule.default; }).default ??\n traverseModule.default) as typeof traverseModule.default;\nexport { traverse };\n\nexport const importMap: Record<string, string> = {\n '@fluentic/i18n': '@fluentic/i18n/compiled',\n '@fluentic/i18n/core': '@fluentic/i18n/compiled',\n};\nexport type Scope = { context: string | null; notes: string[]; meta?: unknown; };\nexport type ExtractedMessage = Scope & { id: string; source: string; };\n\nexport function parseSource(code: string, filename: string) {\n return parse(code, {\n sourceFilename: filename,\n sourceType: 'unambiguous',\n plugins: [\n ...(/\\.[cm]?tsx?$/.test(filename) ? ['typescript' as const] : []),\n ...(!/\\.[cm]?ts$/.test(filename) ? ['jsx' as const] : []),\n 'decorators-legacy',\n 'importAttributes',\n ],\n });\n}\n\nexport function unwrap(path: NodePath): NodePath {\n while (\n path.isTSAsExpression() || path.isTSSatisfiesExpression() || path.isTSNonNullExpression() ||\n path.isTypeCastExpression() || path.isParenthesizedExpression()\n ) path = path.get('expression') as NodePath;\n\n return path;\n}\n\nexport function literal(path: NodePath, seen = new Set<Binding>()): string | null {\n path = unwrap(path);\n if (path.isStringLiteral()) return path.node.value;\n if (path.isTemplateLiteral() && !path.node.expressions.length) return path.node.quasis[0].value.cooked ?? '';\n if (path.isIdentifier()) {\n const binding = path.scope.getBinding(path.node.name);\n\n if (binding?.constant && binding.path.isVariableDeclarator() && !seen.has(binding)) {\n seen.add(binding);\n\n return literal(binding.path.get('init') as NodePath, seen);\n }\n }\n\n return null;\n}\n\nexport function memberName(path: NodePath): string | null {\n if (!path.isMemberExpression()) return null;\n\n const property = path.get('property');\n\n return !path.node.computed && property.isIdentifier()\n ? property.node.name\n : property.isStringLiteral()\n ? property.node.value\n : null;\n}\n\nexport function analyzer(imports = Object.keys(importMap)) {\n const memo = new Map<Binding, Scope | null>();\n const scopedBindings = new Set<Binding>();\n const scopeCalls = new Set<NodePath>();\n\n const resolve = (path: NodePath, visiting = new Set<Binding>()): Scope | null => {\n path = unwrap(path);\n if (path.isIdentifier()) {\n const binding = path.scope.getBinding(path.node.name);\n\n if (!binding) return null;\n if (memo.has(binding)) return memo.get(binding)!;\n if (visiting.has(binding)) throw new Error('[i18n] circular translator alias');\n if (binding.path.isImportSpecifier()) {\n const declaration = binding.path.parentPath;\n const imported = binding.path.node.imported;\n\n return declaration.isImportDeclaration() && imports.includes(declaration.node.source.value) &&\n (b.isIdentifier(imported) ? imported.name : imported.value) === 't' &&\n declaration.node.importKind !== 'type'\n ? { context: null, notes: [] }\n : null;\n }\n if (binding.path.isVariableDeclarator()) {\n visiting.add(binding);\n const scope = resolve(binding.path.get('init') as NodePath, visiting);\n visiting.delete(binding);\n if (scope && !binding.constant) {\n throw new Error('[i18n] translator aliases must not be reassigned: ' + path.node.name);\n }\n memo.set(binding, scope);\n if (scope) scopedBindings.add(binding);\n\n return scope;\n }\n\n return null;\n }\n if (path.isMemberExpression() && memberName(path) === 't') {\n const object = path.get('object');\n\n if (!object.isIdentifier()) return null;\n\n const binding = object.scope.getBinding(object.node.name);\n const declaration = binding?.path.parentPath;\n\n if (\n binding?.path.isImportNamespaceSpecifier() && declaration?.isImportDeclaration() &&\n imports.includes(declaration.node.source.value)\n ) return { context: null, notes: [] };\n }\n if (!path.isCallExpression()) return null;\n\n const callee = path.get('callee');\n const method = memberName(callee);\n\n if (!method || !['context', 'note', 'meta'].includes(method)) return null;\n\n const parent = resolve((callee as NodePath<b.MemberExpression>).get('object'), visiting);\n\n if (!parent) return null;\n if (path.node.arguments.length !== 1) throw new Error('[i18n] scope methods require one static argument');\n\n const argument = path.get('arguments.0') as NodePath;\n scopeCalls.add(path);\n if (method === 'meta') {\n const evaluated = argument.evaluate();\n\n if (!evaluated.confident) throw new Error('[i18n] metadata must be statically known');\n\n return { ...parent, meta: evaluated.value };\n }\n\n const value = literal(argument);\n\n if (value === null) throw new Error('[i18n] ' + method + ' must be a static string');\n\n return method === 'note'\n ? { ...parent, notes: [...parent.notes, value] }\n : { ...parent, context: parent.context ? `${parent.context}.${value}` : value };\n };\n\n return { resolve, scopedBindings, scopeCalls };\n}\n\nexport function collectMessages(code: string, filename: string, imports?: string[]): ExtractedMessage[] {\n const ast = parseSource(code, filename);\n const { resolve } = analyzer(imports);\n const messages: ExtractedMessage[] = [];\n traverse(ast, {\n CallExpression(path) {\n const callee = path.get('callee');\n const method = memberName(callee);\n\n if (!method || !['msg', 'text', 'jsx'].includes(method)) return;\n\n const scope = resolve((callee as NodePath<b.MemberExpression>).get('object'));\n\n if (!scope) return;\n\n const source = literal(path.get('arguments.0') as NodePath);\n\n if (source === null) {\n if (method === 'msg') {\n throw new Error(`[i18n] ${filename}:${path.node.loc?.start.line}: t.msg requires a static message`);\n }\n\n return;\n }\n messages.push({ ...scope, id: scope.context ? `${scope.context}\\0${source}` : source, source });\n },\n });\n\n return [...new Map(messages.map((message) => [message.id, message])).values()];\n}\n","import { type MessageFormatElement, parse, TYPE } from '@formatjs/icu-messageformat-parser';\nimport { createHash } from 'node:crypto';\nimport type { CompactMessage, CompactPart } from '../shared/compact';\n\nexport { COMPACT_VERSION } from '../shared/compact';\n\nexport function messageIdentity(context: string | null, source: string): string {\n return context ? `${context}\\0${source}` : source;\n}\n\nexport function messageId(context: string | null, source: string): string {\n return createHash('sha256').update(messageIdentity(context, source)).digest('hex').slice(0, 24);\n}\n\nexport function compileMessage(source: string): CompactMessage {\n const compact = (elements: MessageFormatElement[]): CompactMessage => {\n const result: CompactPart[] = elements.map((element): CompactPart => {\n switch (element.type) {\n case TYPE.literal:\n return element.value;\n case TYPE.argument:\n return [0, element.value];\n case TYPE.number:\n case TYPE.date:\n case TYPE.time:\n return [\n element.type === TYPE.number ? 1 : element.type === TYPE.date ? 2 : 3,\n element.value,\n typeof element.style === 'object' && element.style\n ? element.style.parsedOptions as Record<string, unknown>\n : element.style ?? null,\n ];\n case TYPE.select:\n return [\n 4,\n element.value,\n Object.fromEntries(Object.entries(element.options).map(([key, option]) => [key, compact(option.value)])),\n ];\n case TYPE.plural:\n return [\n 5,\n element.value,\n element.offset,\n element.pluralType === 'ordinal' ? 1 : 0,\n Object.fromEntries(Object.entries(element.options).map(([key, option]) => [key, compact(option.value)])),\n ];\n case TYPE.pound:\n return [6];\n case TYPE.tag:\n return [7, element.value, compact(element.children)];\n }\n });\n\n return result.every((part) => typeof part === 'string') ? result.join('') : result;\n };\n\n return compact(parse(source, { captureLocation: false }));\n}\n\nexport function compileCatalog(\n records: Array<{ source: string; context: string | null; translation: string; }>,\n): Array<[string, CompactMessage]> {\n const seen = new Map<string, string>();\n\n return records.flatMap((record) => {\n const id = messageId(record.context, record.source);\n const identity = messageIdentity(record.context, record.source);\n\n if (seen.has(id) && seen.get(id) !== identity) throw new Error('[i18n] message hash collision: ' + id);\n seen.set(id, identity);\n\n return record.translation === '' ? [] : [[id, compileMessage(record.translation)] as [string, CompactMessage]];\n });\n}\n","import * as generatorModule from '@babel/generator';\nimport type { NodePath } from '@babel/traverse';\nimport * as b from '@babel/types';\nimport {\n analyzer,\n collectMessages,\n type ExtractedMessage,\n importMap,\n literal,\n memberName,\n parseSource,\n traverse,\n} from './analyze';\nimport { compileMessage, messageId } from './message';\n\nexport { collectMessages } from './analyze';\nexport * from './message';\n\nconst generate = ((generatorModule.default as unknown as { default?: typeof generatorModule.default; }).default ??\n generatorModule.default) as typeof generatorModule.default;\nexport type CompilerOptions = { compiled?: boolean; filename?: string; };\n\nexport function compileProgram(code: string, filename: string, options: CompilerOptions = {}) {\n const ast = parseSource(code, filename);\n const messages: ExtractedMessage[] = [];\n\n if (options.compiled === false) return { ast, messages, changed: false };\n\n const analysis = analyzer();\n\n const plans: Array<\n {\n path: NodePath<b.CallExpression>;\n source: string | null;\n scope: NonNullable<ReturnType<typeof analysis.resolve>>;\n }\n > = [];\n const declarations: NodePath<b.ImportDeclaration>[] = [];\n\n let program: NodePath<b.Program> | undefined;\n traverse(ast, {\n Program(path) {\n program = path;\n },\n ExportAllDeclaration(path) {\n if (importMap[path.node.source.value]) {\n throw new Error('[i18n] do not re-export the translator in compiled mode; import t directly at each use');\n }\n },\n ExportNamedDeclaration(path) {\n if (\n path.node.source && importMap[path.node.source.value] &&\n path.node.specifiers.some((specifier) =>\n b.isExportSpecifier(specifier) && (b.isIdentifier(specifier.local) ? specifier.local.name : '') === 't'\n )\n ) throw new Error('[i18n] do not re-export the translator in compiled mode; export message descriptors instead');\n },\n ImportDeclaration(path) {\n if (importMap[path.node.source.value] && path.node.importKind !== 'type') declarations.push(path);\n },\n CallExpression(path) {\n const callee = path.get('callee');\n const method = memberName(callee);\n\n if (!method || !['msg', 'jsx', 'text'].includes(method)) return;\n\n const scope = analysis.resolve((callee as NodePath<b.MemberExpression>).get('object'));\n\n if (!scope) return;\n\n const source = literal(path.get('arguments.0') as NodePath);\n\n if (source === null && method === 'msg') {\n throw new Error(`[i18n] ${filename}:${path.node.loc?.start.line}: t.msg requires a static message`);\n }\n plans.push({ path, source, scope });\n if (source !== null) {\n messages.push({ ...scope, source, id: scope.context ? `${scope.context}\\0${source}` : source });\n }\n },\n });\n // Discover unused/escaping scopes as well as scopes reached by message calls.\n traverse(ast, {\n VariableDeclarator(path) {\n analysis.resolve(path.get('id') as NodePath);\n },\n CallExpression(path) {\n const name = memberName(path.get('callee'));\n\n if (name && ['context', 'note', 'meta'].includes(name)) analysis.resolve(path);\n },\n });\n const expressionUse = (path: NodePath): NodePath => {\n while (\n path.parentPath &&\n (path.parentPath.isTSAsExpression() || path.parentPath.isTSSatisfiesExpression() ||\n path.parentPath.isTSNonNullExpression() || path.parentPath.isTypeCastExpression() ||\n path.parentPath.isParenthesizedExpression())\n ) path = path.parentPath;\n\n return path;\n };\n\n for (const path of analysis.scopeCalls) {\n const use = expressionUse(path);\n const parent = use.parentPath;\n\n if (parent?.isVariableDeclarator() || parent?.isExpressionStatement()) continue;\n if (parent?.isMemberExpression() && parent.get('object') === use && parent.parentPath?.isCallExpression()) continue;\n throw new Error('[i18n] scoped translator escapes same-file message calls');\n }\n for (const binding of analysis.scopedBindings) {\n if (binding.path.parentPath?.parentPath?.isExportNamedDeclaration()) {\n throw new Error('[i18n] scoped translators cannot be exported; repeat the context in the consuming file');\n }\n\n for (const reference of binding.referencePaths) {\n if (reference.findParent((parent) => parent.isTSType())) continue;\n\n const use = expressionUse(reference);\n const parent = use.parentPath;\n\n if (parent?.isVariableDeclarator() && parent.get('init') === use) continue;\n if (parent?.isMemberExpression() && parent.get('object') === use) {\n const method = memberName(parent);\n\n if (\n method && ['msg', 'text', 'jsx', 'context', 'note', 'meta'].includes(method) &&\n parent.parentPath?.isCallExpression()\n ) continue;\n }\n throw new Error('[i18n] scoped translator escapes same-file message calls: ' + binding.identifier.name);\n }\n }\n if (!declarations.length) return { ast, messages, changed: false };\n\n const helper = program!.scope.generateUidIdentifier('tc');\n\n if (plans.length) {\n program!.unshiftContainer(\n 'body',\n b.importDeclaration([b.importSpecifier(helper, b.identifier('t'))], b.stringLiteral('@fluentic/i18n/compiled')),\n );\n }\n\n for (const { path, source, scope } of plans) {\n const callee = path.get('callee') as NodePath<b.MemberExpression>;\n callee.get('object').replaceWith(b.cloneNode(helper));\n if (source !== null) {\n const replacement = b.valueToNode([messageId(scope.context, source), compileMessage(source)]);\n b.inherits(replacement, path.node.arguments[0]);\n path.node.arguments[0] = replacement;\n }\n }\n // All scope uses were checked before mutation. Remove aliases from leaves to roots.\n let removed = true;\n\n while (removed) {\n removed = false;\n program!.scope.crawl();\n\n for (const binding of analysis.scopedBindings) {\n if (binding.path.removed) continue;\n\n const current = binding.path.scope.getBinding(binding.identifier.name);\n\n if (current && !current.referenced) {\n binding.path.remove();\n removed = true;\n }\n }\n }\n\n for (const path of analysis.scopeCalls) {\n if (!path.removed) {\n const use = expressionUse(path);\n\n if (use.parentPath?.isExpressionStatement()) use.parentPath.remove();\n }\n }\n for (const declaration of declarations) declaration.node.source.value = importMap[declaration.node.source.value];\n program!.scope.crawl();\n\n for (const declaration of declarations) {\n declaration.node.specifiers = declaration.node.specifiers.filter((specifier) => {\n if (\n !b.isImportSpecifier(specifier) ||\n (b.isIdentifier(specifier.imported) ? specifier.imported.name : specifier.imported.value) !== 't'\n ) return true;\n\n return Boolean(program!.scope.getBinding(specifier.local.name)?.referenced);\n });\n if (!declaration.node.specifiers.length) declaration.remove();\n }\n\n return { ast, messages, changed: true };\n}\n\nexport function transform(code: string, options: CompilerOptions = {}) {\n const filename = options.filename ?? 'source.tsx';\n const result = compileProgram(code, filename, options);\n\n if (!result.changed) return null;\n\n const output = generate(result.ast, { sourceMaps: true, sourceFileName: filename, comments: true }, code);\n\n return { code: output.code, map: output.map, messages: result.messages };\n}\n"],"mappings":";;;;;;;AAKA,MAAM,WAAa,eAAe,QAAoE,WACpG,eAAe;AAGjB,MAAa,YAAoC;CAC/C,kBAAkB;CAClB,uBAAuB;AACzB;AAIA,SAAgB,YAAY,MAAc,UAAkB;CAC1D,OAAO,MAAM,MAAM;EACjB,gBAAgB;EAChB,YAAY;EACZ,SAAS;GACP,GAAI,eAAe,KAAK,QAAQ,IAAI,CAAC,YAAqB,IAAI,CAAC;GAC/D,GAAI,CAAC,aAAa,KAAK,QAAQ,IAAI,CAAC,KAAc,IAAI,CAAC;GACvD;GACA;EACF;CACF,CAAC;AACH;AAEA,SAAgB,OAAO,MAA0B;CAC/C,OACE,KAAK,iBAAiB,KAAK,KAAK,wBAAwB,KAAK,KAAK,sBAAsB,KACxF,KAAK,qBAAqB,KAAK,KAAK,0BAA0B,GAC9D,OAAO,KAAK,IAAI,YAAY;CAE9B,OAAO;AACT;AAEA,SAAgB,QAAQ,MAAgB,uBAAO,IAAI,IAAa,GAAkB;CAChF,OAAO,OAAO,IAAI;CAClB,IAAI,KAAK,gBAAgB,GAAG,OAAO,KAAK,KAAK;CAC7C,IAAI,KAAK,kBAAkB,KAAK,CAAC,KAAK,KAAK,YAAY,QAAQ,OAAO,KAAK,KAAK,OAAO,EAAE,CAAC,MAAM,UAAU;CAC1G,IAAI,KAAK,aAAa,GAAG;EACvB,MAAM,UAAU,KAAK,MAAM,WAAW,KAAK,KAAK,IAAI;EAEpD,IAAI,SAAS,YAAY,QAAQ,KAAK,qBAAqB,KAAK,CAAC,KAAK,IAAI,OAAO,GAAG;GAClF,KAAK,IAAI,OAAO;GAEhB,OAAO,QAAQ,QAAQ,KAAK,IAAI,MAAM,GAAe,IAAI;EAC3D;CACF;CAEA,OAAO;AACT;AA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gB;EAAU,UAAU;CAAK,GAAG,IAAI;CAExG,OAAO;EAAE,MAAM,OAAO;EAAM,KAAK,OAAO;EAAK,UAAU,OAAO;CAAS;AACzE"}
@@ -0,0 +1,35 @@
1
+ import { n as CompactMessage, t as COMPACT_VERSION } from "./compact-CJ0OWoIv.js";
2
+ import { n as collectMessages, t as ExtractedMessage } from "./analyze-CdXCxQDg.js";
3
+ import * as b from "@babel/types";
4
+ declare function messageIdentity(context: string | null, source: string): string;
5
+ declare function messageId(context: string | null, source: string): string;
6
+ declare function compileMessage(source: string): CompactMessage;
7
+ declare function compileCatalog(records: Array<{
8
+ source: string;
9
+ context: string | null;
10
+ translation: string;
11
+ }>): Array<[string, CompactMessage]>;
12
+ type CompilerOptions = {
13
+ compiled?: boolean;
14
+ filename?: string;
15
+ };
16
+ declare function compileProgram(code: string, filename: string, options?: CompilerOptions): {
17
+ ast: import("@babel/parser").ParseResult<b.File>;
18
+ messages: ExtractedMessage[];
19
+ changed: boolean;
20
+ };
21
+ declare function transform(code: string, options?: CompilerOptions): {
22
+ code: string;
23
+ map: {
24
+ version: number;
25
+ sources: string[];
26
+ names: string[];
27
+ sourceRoot?: string | undefined;
28
+ sourcesContent?: string[] | undefined;
29
+ mappings: string;
30
+ file: string;
31
+ } | null;
32
+ messages: ExtractedMessage[];
33
+ } | null;
34
+ export { COMPACT_VERSION, CompilerOptions, collectMessages, compileCatalog, compileMessage, compileProgram, messageId, messageIdentity, transform };
35
+ //# sourceMappingURL=compiler.d.ts.map
@@ -0,0 +1,3 @@
1
+ import { t as COMPACT_VERSION } from "./compact-E3zj3Z8d.js";
2
+ import { a as messageId, i as compileMessage, n as transform, o as messageIdentity, r as compileCatalog, s as collectMessages, t as compileProgram } from "./compiler-BZtB9WLi.js";
3
+ export { COMPACT_VERSION, collectMessages, compileCatalog, compileMessage, compileProgram, messageId, messageIdentity, transform };
@@ -0,0 +1,5 @@
1
+ import { A as isMessageDescriptor, C as MessageTagHandler, D as TextRenderer, E as PrimitiveType, M as isMessageTagHandler, N as I18nJsxConfig, O as TranslationGetter, S as MessageSchemaValue, T as MessageValueFactory, _ as MessageMeta, a as I18nJsxOutput, b as MessageRuntimeValue, c as InferMessageSchema, d as JsxRenderer, f as LanguageId, g as MessageInput, h as MessageFormatOptions, i as GetJsxHandler, j as isMessageSchemaValue, k as TryRenderArgs, l as InferRuntimeParams, m as MessageDescriptor, n as CompiledTranslation, o as I18nTagElement, p as MessageContext, r as DescriptorRenderArgs, s as I18nTagValue, t as AnyMessageDescriptor, u as JsonValue, v as MessageParam, w as MessageValueContext, x as MessageSchema, y as MessageParams } from "../types-BuGoCU3P.js";
2
+ import { C as TranslationData, G as noTranslate, I as I18nRegistry, K as setFormats, d as TranslationLoader, m as TranslationLoaderMap, w as TranslationItem, y as defineTranslationLoader } from "../adapter-CWC8rng-.js";
3
+ import { n as TApi, t as MessageApi } from "../i18n-CfYNwubL.js";
4
+ import { t } from "../index.js";
5
+ export { AnyMessageDescriptor, CompiledTranslation, DescriptorRenderArgs, GetJsxHandler, type I18nJsxConfig, I18nJsxOutput, I18nRegistry, I18nTagElement, I18nTagValue, InferMessageSchema, InferRuntimeParams, JsonValue, JsxRenderer, LanguageId, type MessageApi, MessageContext, MessageDescriptor, MessageFormatOptions, MessageInput, MessageMeta, MessageParam, MessageParams, MessageRuntimeValue, MessageSchema, MessageSchemaValue, MessageTagHandler, MessageValueContext, MessageValueFactory, PrimitiveType, type TApi, TextRenderer, type TranslationData, TranslationGetter, type TranslationItem, type TranslationLoader, type TranslationLoaderMap, TryRenderArgs, defineTranslationLoader, isMessageDescriptor, isMessageSchemaValue, isMessageTagHandler, noTranslate, setFormats, t };
@@ -0,0 +1,4 @@
1
+ import { t } from "../src-BovRx-mX.js";
2
+ import { l as noTranslate, n as defineTranslationLoader, r as I18nRegistry, u as setFormats } from "../translation-manager-C79eKu2K.js";
3
+ import { n as isMessageSchemaValue, r as isMessageTagHandler, t as isMessageDescriptor } from "../types-BkDsJfVD.js";
4
+ export { I18nRegistry, defineTranslationLoader, isMessageDescriptor, isMessageSchemaValue, isMessageTagHandler, noTranslate, setFormats, t };
@@ -0,0 +1,25 @@
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
@@ -0,0 +1,6 @@
1
+ import { A as isMessageDescriptor, C as MessageTagHandler, D as TextRenderer, E as PrimitiveType, M as isMessageTagHandler, N as I18nJsxConfig, O as TranslationGetter, S as MessageSchemaValue, T as MessageValueFactory, _ as MessageMeta, a as I18nJsxOutput, b as MessageRuntimeValue, c as InferMessageSchema, d as JsxRenderer, f as LanguageId, g as MessageInput, h as MessageFormatOptions, i as GetJsxHandler, j as isMessageSchemaValue, k as TryRenderArgs, l as InferRuntimeParams, m as MessageDescriptor, n as CompiledTranslation, o as I18nTagElement, p as MessageContext, r as DescriptorRenderArgs, s as I18nTagValue, t as AnyMessageDescriptor, u as JsonValue, v as MessageParam, w as MessageValueContext, x as MessageSchema, y as MessageParams } from "./types-BuGoCU3P.js";
2
+ import { C as TranslationData, G as noTranslate, I as I18nRegistry, K as setFormats, d as TranslationLoader, m as TranslationLoaderMap, w as TranslationItem, y as defineTranslationLoader } from "./adapter-CWC8rng-.js";
3
+ import { n as TApi, t as MessageApi } from "./i18n-CfYNwubL.js";
4
+ declare const t: TApi<import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>, import("react").ReactNode>;
5
+ export { AnyMessageDescriptor, CompiledTranslation, DescriptorRenderArgs, GetJsxHandler, type I18nJsxConfig, I18nJsxOutput, I18nRegistry, I18nTagElement, I18nTagValue, InferMessageSchema, InferRuntimeParams, JsonValue, JsxRenderer, LanguageId, type MessageApi, MessageContext, MessageDescriptor, MessageFormatOptions, MessageInput, MessageMeta, MessageParam, MessageParams, MessageRuntimeValue, MessageSchema, MessageSchemaValue, MessageTagHandler, MessageValueContext, MessageValueFactory, PrimitiveType, type TApi, TextRenderer, type TranslationData, TranslationGetter, type TranslationItem, type TranslationLoader, type TranslationLoaderMap, TryRenderArgs, defineTranslationLoader, isMessageDescriptor, isMessageSchemaValue, isMessageTagHandler, noTranslate, setFormats, t };
6
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,4 @@
1
+ import { t } from "./src-BovRx-mX.js";
2
+ import { l as noTranslate, n as defineTranslationLoader, r as I18nRegistry, u as setFormats } from "./translation-manager-C79eKu2K.js";
3
+ import { n as isMessageSchemaValue, r as isMessageTagHandler, t as isMessageDescriptor } from "./types-BkDsJfVD.js";
4
+ export { I18nRegistry, defineTranslationLoader, isMessageDescriptor, isMessageSchemaValue, isMessageTagHandler, noTranslate, setFormats, t };