@babelize/engine 0.0.0-stage → 0.1.0
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/LICENSE +202 -0
- package/dist/BabelizeEngine.d.ts +12 -0
- package/dist/BabelizeEngine.js +47 -0
- package/dist/analysis/analyze.d.ts +106 -0
- package/dist/analysis/analyze.js +323 -0
- package/dist/config/env.d.ts +9 -0
- package/dist/config/env.js +16 -0
- package/dist/config.d.ts +74 -0
- package/dist/config.js +47 -0
- package/dist/index.d.ts +54 -0
- package/dist/index.js +126 -0
- package/dist/injection/InjectionStrategy.d.ts +62 -0
- package/dist/injection/InjectionStrategy.js +2 -0
- package/dist/injection/StrategyFactory.d.ts +4 -0
- package/dist/injection/StrategyFactory.js +29 -0
- package/dist/injection/django/django-template-injector.d.ts +29 -0
- package/dist/injection/django/django-template-injector.js +216 -0
- package/dist/injection/html/html-injector.d.ts +11 -0
- package/dist/injection/html/html-injector.js +173 -0
- package/dist/injection/strategies/NextIntlStrategy.d.ts +25 -0
- package/dist/injection/strategies/NextIntlStrategy.js +141 -0
- package/dist/injection/strategies/ReactI18nextStrategy.d.ts +19 -0
- package/dist/injection/strategies/ReactI18nextStrategy.js +116 -0
- package/dist/injection/strategies/VanillaStrategy.d.ts +11 -0
- package/dist/injection/strategies/VanillaStrategy.js +73 -0
- package/dist/injection/strategies/VueI18nStrategy.d.ts +11 -0
- package/dist/injection/strategies/VueI18nStrategy.js +84 -0
- package/dist/local/formatter.d.ts +26 -0
- package/dist/local/formatter.js +105 -0
- package/dist/local/git.d.ts +23 -0
- package/dist/local/git.js +136 -0
- package/dist/local/hosted-provider.d.ts +68 -0
- package/dist/local/hosted-provider.js +215 -0
- package/dist/local/index.d.ts +23 -0
- package/dist/local/index.js +75 -0
- package/dist/local/provider.d.ts +56 -0
- package/dist/local/provider.js +119 -0
- package/dist/local/pseudo-provider.d.ts +18 -0
- package/dist/local/pseudo-provider.js +207 -0
- package/dist/local/report.d.ts +177 -0
- package/dist/local/report.js +186 -0
- package/dist/local/translate-core.d.ts +215 -0
- package/dist/local/translate-core.js +461 -0
- package/dist/local/translate-messages.d.ts +49 -0
- package/dist/local/translate-messages.js +91 -0
- package/dist/local/workspace-copy.d.ts +91 -0
- package/dist/local/workspace-copy.js +355 -0
- package/dist/modules/extractor/extract.d.ts +20 -0
- package/dist/modules/extractor/extract.js +701 -0
- package/dist/modules/extractor/index.d.ts +2 -0
- package/dist/modules/extractor/index.js +63 -0
- package/dist/modules/finalization/django-finalize.d.ts +13 -0
- package/dist/modules/finalization/django-finalize.js +275 -0
- package/dist/modules/finalization/finalize.d.ts +36 -0
- package/dist/modules/finalization/finalize.js +717 -0
- package/dist/modules/finalization/index.d.ts +1 -0
- package/dist/modules/finalization/index.js +5 -0
- package/dist/modules/finalization/nextjs-finalize.d.ts +37 -0
- package/dist/modules/finalization/nextjs-finalize.js +329 -0
- package/dist/modules/finalization/static-runtime.d.ts +9 -0
- package/dist/modules/finalization/static-runtime.js +261 -0
- package/dist/modules/format-injection/index.d.ts +19 -0
- package/dist/modules/format-injection/index.js +272 -0
- package/dist/modules/format-injection/inject-formats.d.ts +31 -0
- package/dist/modules/format-injection/inject-formats.js +208 -0
- package/dist/modules/glossary/glossary.d.ts +9 -0
- package/dist/modules/glossary/glossary.js +27 -0
- package/dist/modules/glossary/index.d.ts +3 -0
- package/dist/modules/glossary/index.js +8 -0
- package/dist/modules/glossary/masker.d.ts +23 -0
- package/dist/modules/glossary/masker.js +56 -0
- package/dist/modules/glossary/types.d.ts +22 -0
- package/dist/modules/glossary/types.js +2 -0
- package/dist/modules/injection/index.d.ts +1 -0
- package/dist/modules/injection/index.js +6 -0
- package/dist/modules/injection/inject.d.ts +29 -0
- package/dist/modules/injection/inject.js +1066 -0
- package/dist/modules/keygen/index.d.ts +1 -0
- package/dist/modules/keygen/index.js +11 -0
- package/dist/modules/keygen/keygen.d.ts +4 -0
- package/dist/modules/keygen/keygen.js +116 -0
- package/dist/modules/keygen/locale-data.d.ts +7 -0
- package/dist/modules/keygen/locale-data.js +73 -0
- package/dist/modules/keygen/public.d.ts +2 -0
- package/dist/modules/keygen/public.js +12 -0
- package/dist/modules/locale-builder/index.d.ts +1 -0
- package/dist/modules/locale-builder/index.js +7 -0
- package/dist/modules/locale-builder/locales.d.ts +13 -0
- package/dist/modules/locale-builder/locales.js +107 -0
- package/dist/modules/locale-builder/po.d.ts +33 -0
- package/dist/modules/locale-builder/po.js +131 -0
- package/dist/modules/lockfile/hasher.d.ts +7 -0
- package/dist/modules/lockfile/hasher.js +13 -0
- package/dist/modules/lockfile/index.d.ts +3 -0
- package/dist/modules/lockfile/index.js +21 -0
- package/dist/modules/lockfile/lockfile-manager.d.ts +90 -0
- package/dist/modules/lockfile/lockfile-manager.js +482 -0
- package/dist/modules/lockfile/schema.d.ts +154 -0
- package/dist/modules/lockfile/schema.js +45 -0
- package/dist/modules/parser/index.d.ts +2 -0
- package/dist/modules/parser/index.js +9 -0
- package/dist/modules/summary/index.d.ts +1 -0
- package/dist/modules/summary/index.js +7 -0
- package/dist/modules/summary/summary.d.ts +9 -0
- package/dist/modules/summary/summary.js +195 -0
- package/dist/modules/sync-detector/index.d.ts +2 -0
- package/dist/modules/sync-detector/index.js +7 -0
- package/dist/modules/sync-detector/reporter.d.ts +3 -0
- package/dist/modules/sync-detector/reporter.js +16 -0
- package/dist/modules/sync-detector/sync-detector.d.ts +39 -0
- package/dist/modules/sync-detector/sync-detector.js +374 -0
- package/dist/modules/translator/batch-optimizer.d.ts +12 -0
- package/dist/modules/translator/batch-optimizer.js +30 -0
- package/dist/modules/translator/client/byok.provider.d.ts +64 -0
- package/dist/modules/translator/client/byok.provider.js +319 -0
- package/dist/modules/translator/client/direct-translator.client.d.ts +12 -0
- package/dist/modules/translator/client/direct-translator.client.js +71 -0
- package/dist/modules/translator/client/gemini.provider.d.ts +1 -0
- package/dist/modules/translator/client/gemini.provider.js +110 -0
- package/dist/modules/translator/client/groq.provider.d.ts +1 -0
- package/dist/modules/translator/client/groq.provider.js +111 -0
- package/dist/modules/translator/client/request.types.d.ts +1 -0
- package/dist/modules/translator/client/request.types.js +2 -0
- package/dist/modules/translator/client/retry.d.ts +29 -0
- package/dist/modules/translator/client/retry.js +94 -0
- package/dist/modules/translator/client/test-utils/mock.client.d.ts +31 -0
- package/dist/modules/translator/client/test-utils/mock.client.js +59 -0
- package/dist/modules/translator/client/translator.interface.d.ts +1 -0
- package/dist/modules/translator/client/translator.interface.js +2 -0
- package/dist/modules/translator/language-codes/errors.d.ts +10 -0
- package/dist/modules/translator/language-codes/errors.js +18 -0
- package/dist/modules/translator/language-codes/flores-map.d.ts +1 -0
- package/dist/modules/translator/language-codes/flores-map.js +107 -0
- package/dist/modules/translator/language-codes/index.d.ts +11 -0
- package/dist/modules/translator/language-codes/index.js +24 -0
- package/dist/modules/translator/language-codes/language-mapper.d.ts +25 -0
- package/dist/modules/translator/language-codes/language-mapper.js +132 -0
- package/dist/modules/translator/language-codes/rtl-languages.d.ts +2 -0
- package/dist/modules/translator/language-codes/rtl-languages.js +9 -0
- package/dist/modules/translator/memory/memory-matcher.d.ts +8 -0
- package/dist/modules/translator/memory/memory-matcher.js +218 -0
- package/dist/modules/translator/memory/types.d.ts +22 -0
- package/dist/modules/translator/memory/types.js +2 -0
- package/dist/modules/translator/translate.d.ts +38 -0
- package/dist/modules/translator/translate.js +932 -0
- package/dist/modules/translator/translator.d.ts +5 -0
- package/dist/modules/translator/translator.js +46 -0
- package/dist/modules/vue/migrate.d.ts +13 -0
- package/dist/modules/vue/migrate.js +40 -0
- package/dist/modules/vue/script-inject.d.ts +16 -0
- package/dist/modules/vue/script-inject.js +115 -0
- package/dist/modules/vue/sfc.d.ts +11 -0
- package/dist/modules/vue/sfc.js +51 -0
- package/dist/modules/vue/template-rewrite.d.ts +25 -0
- package/dist/modules/vue/template-rewrite.js +76 -0
- package/dist/modules/vue/template-scan.d.ts +29 -0
- package/dist/modules/vue/template-scan.js +264 -0
- package/dist/modules/workspace/index.d.ts +1 -0
- package/dist/modules/workspace/index.js +5 -0
- package/dist/modules/workspace/validate.d.ts +13 -0
- package/dist/modules/workspace/validate.js +298 -0
- package/dist/orchestrator.d.ts +8 -0
- package/dist/orchestrator.js +616 -0
- package/dist/providers/default-translation-provider.d.ts +20 -0
- package/dist/providers/default-translation-provider.js +30 -0
- package/dist/providers/index.d.ts +2 -0
- package/dist/providers/index.js +21 -0
- package/dist/providers/types.d.ts +145 -0
- package/dist/providers/types.js +2 -0
- package/dist/qa/check-project.d.ts +49 -0
- package/dist/qa/check-project.js +150 -0
- package/dist/qa/locale-files.d.ts +44 -0
- package/dist/qa/locale-files.js +159 -0
- package/dist/qa/locale-qa.d.ts +61 -0
- package/dist/qa/locale-qa.js +325 -0
- package/dist/qa/review.d.ts +43 -0
- package/dist/qa/review.js +175 -0
- package/dist/runtime/config.d.ts +8 -0
- package/dist/runtime/config.js +36 -0
- package/dist/runtime/index.d.ts +3 -0
- package/dist/runtime/index.js +8 -0
- package/dist/runtime/types.d.ts +363 -0
- package/dist/runtime/types.js +38 -0
- package/dist/types.d.ts +134 -0
- package/dist/types.js +12 -0
- package/dist/utils/ast-helpers.d.ts +57 -0
- package/dist/utils/ast-helpers.js +608 -0
- package/dist/utils/cache-keys.d.ts +8 -0
- package/dist/utils/cache-keys.js +18 -0
- package/dist/utils/circuit-breaker.d.ts +43 -0
- package/dist/utils/circuit-breaker.js +119 -0
- package/dist/utils/concurrent-map.d.ts +4 -0
- package/dist/utils/concurrent-map.js +21 -0
- package/dist/utils/detect-format.d.ts +5 -0
- package/dist/utils/detect-format.js +125 -0
- package/dist/utils/dtl-mask.d.ts +25 -0
- package/dist/utils/dtl-mask.js +58 -0
- package/dist/utils/extraction-options.d.ts +23 -0
- package/dist/utils/extraction-options.js +23 -0
- package/dist/utils/file-utils.d.ts +33 -0
- package/dist/utils/file-utils.js +262 -0
- package/dist/utils/glossary-match.d.ts +9 -0
- package/dist/utils/glossary-match.js +25 -0
- package/dist/utils/html-extractor.d.ts +8 -0
- package/dist/utils/html-extractor.js +317 -0
- package/dist/utils/i18next-icu.d.ts +38 -0
- package/dist/utils/i18next-icu.js +159 -0
- package/dist/utils/icu-message.d.ts +65 -0
- package/dist/utils/icu-message.js +346 -0
- package/dist/utils/icu-spans.d.ts +10 -0
- package/dist/utils/icu-spans.js +126 -0
- package/dist/utils/jsx-message.d.ts +93 -0
- package/dist/utils/jsx-message.js +621 -0
- package/dist/utils/key-usage.d.ts +35 -0
- package/dist/utils/key-usage.js +247 -0
- package/dist/utils/logger.d.ts +24 -0
- package/dist/utils/logger.js +33 -0
- package/dist/utils/metadata.d.ts +80 -0
- package/dist/utils/metadata.js +255 -0
- package/dist/utils/module-constants.d.ts +30 -0
- package/dist/utils/module-constants.js +265 -0
- package/dist/utils/not-injected.d.ts +6 -0
- package/dist/utils/not-injected.js +36 -0
- package/dist/utils/placeholder-protection.d.ts +57 -0
- package/dist/utils/placeholder-protection.js +136 -0
- package/dist/utils/pseudo-markers.d.ts +9 -0
- package/dist/utils/pseudo-markers.js +16 -0
- package/dist/utils/py-extractor.d.ts +14 -0
- package/dist/utils/py-extractor.js +285 -0
- package/dist/utils/string-utils.d.ts +52 -0
- package/dist/utils/string-utils.js +270 -0
- package/dist/utils/translation-quality.d.ts +34 -0
- package/dist/utils/translation-quality.js +156 -0
- package/dist/utils/translation-sanitizer.d.ts +10 -0
- package/dist/utils/translation-sanitizer.js +57 -0
- package/dist/utils/translator-caller.d.ts +32 -0
- package/dist/utils/translator-caller.js +217 -0
- package/dist/utils/translator-load-balancer.d.ts +73 -0
- package/dist/utils/translator-load-balancer.js +293 -0
- package/dist/utils/ui-copy.d.ts +32 -0
- package/dist/utils/ui-copy.js +126 -0
- package/dist/utils/workspace.d.ts +14 -0
- package/dist/utils/workspace.js +89 -0
- package/package.json +64 -4
- package/schemas/translate-report.schema.json +297 -0
- package/README.md +0 -3
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.branchSpanProblems = branchSpanProblems;
|
|
4
|
+
exports.describeBranchSpanProblem = describeBranchSpanProblem;
|
|
5
|
+
/**
|
|
6
|
+
* Per-branch check of the protected spans (tags, URLs, emails, code,
|
|
7
|
+
* never-translate terms) of an ICU translation. Shared by the translate
|
|
8
|
+
* phase and locale QA.
|
|
9
|
+
*
|
|
10
|
+
* Each combination of plural/select branches the translation can render
|
|
11
|
+
* (a "variant") must carry exactly the spans of the matching source variant:
|
|
12
|
+
* same branch keys where the source has them, the source's `other` branch for
|
|
13
|
+
* categories only the target language has, and the whole source when a plain
|
|
14
|
+
* source was turned into a plural. So `<b>` dropped from one branch, or kept
|
|
15
|
+
* in only one branch of an added plural, is caught — not just a span missing
|
|
16
|
+
* from every branch.
|
|
17
|
+
*/
|
|
18
|
+
const icu_message_1 = require("./icu-message");
|
|
19
|
+
const placeholder_protection_1 = require("./placeholder-protection");
|
|
20
|
+
/** Variants beyond this are not expanded (deeply nested selects); the check is skipped. */
|
|
21
|
+
const MAX_VARIANTS = 256;
|
|
22
|
+
class TooManyVariants extends Error {
|
|
23
|
+
}
|
|
24
|
+
function expand(nodes) {
|
|
25
|
+
let variants = [{ path: new Map(), text: '' }];
|
|
26
|
+
for (const node of nodes) {
|
|
27
|
+
if (node.type === 'text') {
|
|
28
|
+
for (const v of variants)
|
|
29
|
+
v.text += node.value;
|
|
30
|
+
}
|
|
31
|
+
else if (node.type === 'pound') {
|
|
32
|
+
for (const v of variants)
|
|
33
|
+
v.text += '#';
|
|
34
|
+
}
|
|
35
|
+
else if (node.type === 'argument') {
|
|
36
|
+
for (const v of variants)
|
|
37
|
+
v.text += `{${node.name}}`;
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
const next = [];
|
|
41
|
+
for (const v of variants) {
|
|
42
|
+
for (const [key, branch] of Object.entries(node.options)) {
|
|
43
|
+
for (const b of expand(branch)) {
|
|
44
|
+
const path = new Map([...v.path, [node.name, key], ...b.path]);
|
|
45
|
+
next.push({ path, text: v.text + b.text });
|
|
46
|
+
if (next.length > MAX_VARIANTS)
|
|
47
|
+
throw new TooManyVariants();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
variants = next;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return variants;
|
|
55
|
+
}
|
|
56
|
+
function spans(text, neverTranslate) {
|
|
57
|
+
const counts = new Map();
|
|
58
|
+
for (const t of (0, placeholder_protection_1.protectText)(text, neverTranslate, { icu: true }).tokens) {
|
|
59
|
+
const k = t.toLowerCase();
|
|
60
|
+
counts.set(k, (counts.get(k) ?? 0) + 1);
|
|
61
|
+
}
|
|
62
|
+
return counts;
|
|
63
|
+
}
|
|
64
|
+
/** The source variant a target variant is checked against. */
|
|
65
|
+
function matchSource(source, target) {
|
|
66
|
+
const score = (s) => {
|
|
67
|
+
let exact = 0;
|
|
68
|
+
for (const [name, key] of s.path) {
|
|
69
|
+
const want = target.path.get(name);
|
|
70
|
+
if (want === key)
|
|
71
|
+
exact += 2;
|
|
72
|
+
else if (key !== 'other')
|
|
73
|
+
return -1;
|
|
74
|
+
}
|
|
75
|
+
return exact;
|
|
76
|
+
};
|
|
77
|
+
// Prefer the variant with the most matching branch keys; unmatched selectors fall back to `other`.
|
|
78
|
+
let best = source[0];
|
|
79
|
+
let bestScore = -Infinity;
|
|
80
|
+
for (const s of source) {
|
|
81
|
+
const sc = score(s);
|
|
82
|
+
if (sc > bestScore) {
|
|
83
|
+
best = s;
|
|
84
|
+
bestScore = sc;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return best;
|
|
88
|
+
}
|
|
89
|
+
function label(v) {
|
|
90
|
+
return v.path.size ? [...v.path].map(([n, k]) => `${n}=${k}`).join(', ') : 'message';
|
|
91
|
+
}
|
|
92
|
+
/** Span differences of `target` per branch combination (empty when fine). */
|
|
93
|
+
function branchSpanProblems(source, target, neverTranslate = []) {
|
|
94
|
+
let src;
|
|
95
|
+
let tgt;
|
|
96
|
+
try {
|
|
97
|
+
src = expand((0, icu_message_1.parseIcu)(source));
|
|
98
|
+
tgt = expand((0, icu_message_1.parseIcu)(target));
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
// Unparseable (reported by the ICU checks) or too many branch combinations to expand.
|
|
102
|
+
return [];
|
|
103
|
+
}
|
|
104
|
+
const problems = new Map();
|
|
105
|
+
for (const t of tgt) {
|
|
106
|
+
const s = matchSource(src, t);
|
|
107
|
+
const want = spans(s.text, neverTranslate);
|
|
108
|
+
const have = spans(t.text, neverTranslate);
|
|
109
|
+
const lost = [];
|
|
110
|
+
const added = [];
|
|
111
|
+
for (const [span, n] of want)
|
|
112
|
+
if ((have.get(span) ?? 0) < n)
|
|
113
|
+
lost.push(span);
|
|
114
|
+
for (const [span, n] of have)
|
|
115
|
+
if ((want.get(span) ?? 0) < n)
|
|
116
|
+
added.push(span);
|
|
117
|
+
if (lost.length || added.length)
|
|
118
|
+
problems.set(label(t), { branch: label(t), lost, added });
|
|
119
|
+
}
|
|
120
|
+
return [...problems.values()];
|
|
121
|
+
}
|
|
122
|
+
/** "count=other: lost <b>, </b>" */
|
|
123
|
+
function describeBranchSpanProblem(p) {
|
|
124
|
+
const parts = [p.lost.length ? `lost ${p.lost.join(', ')}` : '', p.added.length ? `added ${p.added.join(', ')}` : ''].filter(Boolean);
|
|
125
|
+
return `${p.branch}: ${parts.join('; ')}`;
|
|
126
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
/**
|
|
3
|
+
* JSX sentences as one message.
|
|
4
|
+
*
|
|
5
|
+
* `<h1>Welcome back, {user}</h1>` used to be extracted as the fragment
|
|
6
|
+
* "Welcome back," and injected as `{t('…')} {user}`. A translation can't move
|
|
7
|
+
* words around a variable it never sees, and a count can't be pluralized. This
|
|
8
|
+
* module turns an element's mixed children — text, `{expressions}` and inline
|
|
9
|
+
* elements — into a single ICU message:
|
|
10
|
+
*
|
|
11
|
+
* <h1>Welcome back, {user}</h1> → "Welcome back, {user}"
|
|
12
|
+
* <p>Hi {user.name}</p> → "Hi {userName}"
|
|
13
|
+
* <p>Total: {format(sum)} today</p> → "Total: {0} today"
|
|
14
|
+
* <p>Read the <Link href="/t">terms</Link></p> → "Read the <link>terms</link>"
|
|
15
|
+
* <p>You have {count} items</p> → "You have {count, plural, one {# item} other {# items}}"
|
|
16
|
+
*
|
|
17
|
+
* The extractor and the injector both call {@link buildJsxMessage} on the same
|
|
18
|
+
* untouched source, so they agree on the text (and so on the extraction id).
|
|
19
|
+
*/
|
|
20
|
+
export interface MessagePlaceholder {
|
|
21
|
+
kind: 'placeholder';
|
|
22
|
+
/** Argument name used in the message and in the values object. */
|
|
23
|
+
name: string;
|
|
24
|
+
expression: t.Expression;
|
|
25
|
+
}
|
|
26
|
+
export interface MessageTag {
|
|
27
|
+
kind: 'tag';
|
|
28
|
+
/** Tag name used in the message (`<link>…</link>`) and as the rich-text key. */
|
|
29
|
+
name: string;
|
|
30
|
+
element: t.JSXElement;
|
|
31
|
+
}
|
|
32
|
+
export interface JsxMessage {
|
|
33
|
+
/** The ICU message, e.g. "Welcome back, {user}". */
|
|
34
|
+
text: string;
|
|
35
|
+
/** Placeholders and tags in order of first appearance (each name once). */
|
|
36
|
+
entries: Array<MessagePlaceholder | MessageTag>;
|
|
37
|
+
/** Source nodes folded into the message (text, literal expressions, inline elements). */
|
|
38
|
+
consumed: t.Node[];
|
|
39
|
+
/** Name of the placeholder turned into an ICU plural, if any. */
|
|
40
|
+
plural?: string;
|
|
41
|
+
}
|
|
42
|
+
export type JsxMessageResult = {
|
|
43
|
+
kind: 'message';
|
|
44
|
+
message: JsxMessage;
|
|
45
|
+
}
|
|
46
|
+
/** Not a sentence: plain text, only expressions, block-level children, … */
|
|
47
|
+
| {
|
|
48
|
+
kind: 'none';
|
|
49
|
+
}
|
|
50
|
+
/** Reads like a sentence but can't be moved safely; extract fragments as before. */
|
|
51
|
+
| {
|
|
52
|
+
kind: 'unsafe';
|
|
53
|
+
reason: string;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Names that suggest a React node rather than text or a number — such a value
|
|
57
|
+
* can't be a message argument. Matched case-insensitively against the last
|
|
58
|
+
* name segment (`user.avatar`, `statusIcon`, `renderBadge()`). Extendable.
|
|
59
|
+
*/
|
|
60
|
+
export declare const ELEMENT_LIKE_NAMES: RegExp[];
|
|
61
|
+
/** Rendered text of a JSXText node, with JSX's whitespace rules (same as Babel's cleanJSXElementLiteralChild). */
|
|
62
|
+
export declare function cleanJsxText(value: string): string;
|
|
63
|
+
/**
|
|
64
|
+
* Whether the expression is very likely a string or number. Message values
|
|
65
|
+
* must be: next-intl throws on a React element, i18next prints [object Object].
|
|
66
|
+
*/
|
|
67
|
+
export declare function isLikelyPrimitive(expr: t.Node): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Build the single message for `node`'s children, or say why there is none.
|
|
70
|
+
* Pure: reads the AST, never changes it.
|
|
71
|
+
*/
|
|
72
|
+
export declare function buildJsxMessage(node: t.JSXElement | t.JSXFragment, options?: {
|
|
73
|
+
/**
|
|
74
|
+
* Turn "{count} items" into an ICU plural. Only when an LLM translator is
|
|
75
|
+
* configured: the NLLB service can't translate ICU plural messages.
|
|
76
|
+
*/
|
|
77
|
+
plurals?: boolean;
|
|
78
|
+
}): JsxMessageResult;
|
|
79
|
+
/**
|
|
80
|
+
* Text used to name the key: the message without arguments and tags, with a
|
|
81
|
+
* plural's `other` branch standing in for it. "Welcome back, {user}" →
|
|
82
|
+
* "Welcome back,"; "{count, plural, one {# item} other {# items}} left" → "items left".
|
|
83
|
+
*/
|
|
84
|
+
export declare function messageKeyText(message: string): string;
|
|
85
|
+
/** `{ user, userName: user.name, 0: format(x) }` — placeholders only. */
|
|
86
|
+
export declare function placeholderValues(message: JsxMessage): t.ObjectProperty[];
|
|
87
|
+
/** next-intl rich values: `b: (chunks) => <b>{chunks}</b>`. Moves the element into the callback. */
|
|
88
|
+
export declare function richTagValue(tag: MessageTag): t.ObjectProperty;
|
|
89
|
+
/** react-i18next Trans components: `b: <b />`. */
|
|
90
|
+
export declare function transComponent(tag: MessageTag): t.ObjectProperty;
|
|
91
|
+
export declare function hasTags(message: JsxMessage): boolean;
|
|
92
|
+
/** `t("key")` or `t("key", { …values })`. */
|
|
93
|
+
export declare function createMessageTCall(key: string, message: JsxMessage, callee?: t.Expression): t.CallExpression;
|