@menapo/vi18n 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 +49 -0
- package/README.md +110 -2
- package/dist/apply-Bre-lY9J.js +228 -0
- package/dist/captured-Bj8bO6vd.js +1034 -0
- package/dist/check-D34P-S--.js +1 -0
- package/dist/check-DyrAbv73.js +201 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +41 -0
- package/dist/codec-DuvU2VQy.js +207 -0
- package/dist/collect-Cx4_SKOe.js +13 -0
- package/dist/collisions-CfpZU8e4.js +217 -0
- package/dist/compile-B5Mz6WJm.js +245 -0
- package/dist/compile-Cc97JaW2.js +2502 -0
- package/dist/concurrency-C9UUWuDC.js +96 -0
- package/dist/concurrency-DONL7t4V.js +1 -0
- package/dist/config.d.ts +21 -0
- package/dist/config.js +39 -0
- package/dist/dir-zw6bGMKQ.js +290 -0
- package/dist/duplicates-yuRljQ6h.js +185 -0
- package/dist/engine-B7p40M__.js +531 -0
- package/dist/engine.d.ts +43 -0
- package/dist/engine.js +1241 -0
- package/dist/exclude-Du-Zd_qI.js +26 -0
- package/dist/export-DGsMbcTZ.js +103 -0
- package/dist/extract-Dujlsgnk.js +298 -0
- package/dist/formats-KPIg-08V.js +781 -0
- package/dist/i18next-CrUnKFfh.js +1596 -0
- package/dist/i18next-Rgo-v9l0.js +1 -0
- package/dist/import-Cwdhcywt.js +225 -0
- package/dist/index.d.ts +156 -0
- package/dist/index.js +239 -0
- package/dist/init-BecCTvKi.js +792 -0
- package/dist/library-D5CWvTQs.js +1882 -0
- package/dist/lingui--PcOOYry.js +833 -0
- package/dist/lint.d.ts +105 -0
- package/dist/lint.js +971 -0
- package/dist/load-CQRz4PpM.js +2950 -0
- package/dist/load-gW-oJt1Q.js +747 -0
- package/dist/locales-DX4MOBFE.js +827 -0
- package/dist/lsp-Cq1Nuu-Q.js +31 -0
- package/dist/match-BGr8EXB3.js +89 -0
- package/dist/mcp-Cf0T7qPW.js +28 -0
- package/dist/merge-driver-CpiiSVIc.js +422 -0
- package/dist/messages-Cxa-5tR0.js +166 -0
- package/dist/migrate-CntqvrW4.js +1 -0
- package/dist/migrate-dPgq9uzy.js +1484 -0
- package/dist/openai-CTaMDcl-.js +346 -0
- package/dist/output-DsaHKHEt.js +164 -0
- package/dist/parse.d.ts +62 -0
- package/dist/parse.js +156 -0
- package/dist/pipeline-C7g11THL.js +2031 -0
- package/dist/pipeline-wxS0SApG.js +1 -0
- package/dist/project-Dwx7iPm6.js +381 -0
- package/dist/project-pXipT8iG.js +1046 -0
- package/dist/pseudo-DRv30iN5.js +145 -0
- package/dist/raw-C4Y6vyGY.js +4708 -0
- package/dist/react-intl-CaBVwJ9u.js +519 -0
- package/dist/restore-Btq66Tid.js +175 -0
- package/dist/rewrite-CiTRAICl.js +803 -0
- package/dist/rich-DCUKl5HM.js +97 -0
- package/dist/rolldown-runtime-D7D4PA-g.js +13 -0
- package/dist/run-DYD_VXKy.js +694 -0
- package/dist/runtime-DTMmliT1.js +64 -0
- package/dist/scan-worker.d.ts +62 -0
- package/dist/scan-worker.js +1 -0
- package/dist/scoped-BMYpSthj.js +44 -0
- package/dist/server-BDkykMjb.js +11823 -0
- package/dist/server-qv3mz70d.js +10485 -0
- package/dist/server.d.ts +169 -0
- package/dist/server.js +1234 -0
- package/dist/sitemap-DV3o8QD7.js +159 -0
- package/dist/sources-D19czDSA.js +2242 -0
- package/dist/status-DZArW5aE.js +149 -0
- package/dist/stdio-CVaJfxA7.js +29 -0
- package/dist/stdio-FPOKQAgu.js +95 -0
- package/dist/sync-CcVzger_.js +658 -0
- package/dist/t-DC-c9zE5.js +454 -0
- package/dist/test.d.ts +116 -0
- package/dist/test.js +319 -0
- package/dist/translate-DZR3MkSA.js +299 -0
- package/dist/ts-BaU5yOf0.js +4863 -0
- package/dist/types-CgUCkFU1.d.ts +707 -0
- package/dist/types-D3QGM8XO.js +146 -0
- package/dist/types-DsdWBG0b.d.ts +558 -0
- package/dist/types-DtvQ7UdD.js +1948 -0
- package/dist/types-wSh9fCBY.js +11 -0
- package/dist/units-CQ5Q99RC.js +150 -0
- package/dist/url-CRfCOhUI.js +172 -0
- package/dist/url-CsBkRaJy.js +225 -0
- package/dist/validate-BxpupdAf.js +2615 -0
- package/dist/validate-D6DJepZv.js +365 -0
- package/dist/version-BlyLGlOa.js +28 -0
- package/dist/vite-scan-B_YW4X_a.js +242 -0
- package/dist/vite.d.ts +34 -0
- package/dist/vite.js +7558 -0
- package/dist/vue-i18n-CEMnpv7k.js +651 -0
- package/dist/which-C6PFI1Dm.js +116 -0
- package/dist/worker-84U6uYB3.js +1656 -0
- package/package.json +97 -3
- package/schemas/catalog.json +57 -0
package/dist/parse.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { _ as DEV, b as trim, h as createScope, n as S, x as warnOnce } from "./dir-zw6bGMKQ.js";
|
|
2
|
+
import { o as formatMessage, r as t } from "./t-DC-c9zE5.js";
|
|
3
|
+
import { f as isDiagnosticError, i as normalizeSource, s as parseSource, t as compileMessage } from "./compile-Cc97JaW2.js";
|
|
4
|
+
import { n as validateTranslation, t as validateSource } from "./validate-D6DJepZv.js";
|
|
5
|
+
//#region src/parse/index.ts
|
|
6
|
+
/**
|
|
7
|
+
* `@menapo/vi18n/parse` (PLAN §4.1, INTERNALS §3.6): messages that are not in
|
|
8
|
+
* the code — a CMS, a database, a template an admin edits — parsed at
|
|
9
|
+
* runtime by the compiler's own parser, validation and IR compiler, then
|
|
10
|
+
* rendered by the runtime's interpreter. They follow every rule a compiled
|
|
11
|
+
* message follows: the same syntax (ICU, or MF2 lowered into it), the same
|
|
12
|
+
* hard errors, bidi isolation of string values, escaping in `richHtml()`,
|
|
13
|
+
* plural, select, number and date semantics.
|
|
14
|
+
*
|
|
15
|
+
* A message with errors never throws into rendering: it renders its source
|
|
16
|
+
* (`options.source`) when that is valid, as the build falls back along the
|
|
17
|
+
* chain, else its own text without bidi controls; dev warns once and
|
|
18
|
+
* `onParseError` handlers hear of it.
|
|
19
|
+
*
|
|
20
|
+
* Its own entry, never imported by `.`: the parsers are about 16 KB gzipped
|
|
21
|
+
* (PLAN §6), several times the runtime, and an app that compiles its
|
|
22
|
+
* messages never ships them.
|
|
23
|
+
*/
|
|
24
|
+
/** Codes that need the text's locale; without one, `und` would flag every category. */
|
|
25
|
+
const LOCALE_CODES = /* @__PURE__ */ new Set(["icu-plural-missing-category", "icu-plural-unused-category"]);
|
|
26
|
+
/**
|
|
27
|
+
* Parses per text and options, newest kept: components call `parse()` on
|
|
28
|
+
* every render, and a CMS page holds a bounded set of texts.
|
|
29
|
+
*/
|
|
30
|
+
const cache = /* @__PURE__ */ new Map();
|
|
31
|
+
const handlers = /* @__PURE__ */ new Set();
|
|
32
|
+
/**
|
|
33
|
+
* Parses and validates `message`. Never throws: errors are in `errors`, and
|
|
34
|
+
* the result still renders (see the module comment).
|
|
35
|
+
*/
|
|
36
|
+
function parse(message, options = {}) {
|
|
37
|
+
const { syntax = "auto", source, locale } = options;
|
|
38
|
+
const key = `${syntax}\0${locale ?? ""}\0${source === void 0 ? "" : "" + source}\0${message}`;
|
|
39
|
+
let parsed = cache.get(key);
|
|
40
|
+
if (parsed !== void 0) cache.delete(key);
|
|
41
|
+
else {
|
|
42
|
+
parsed = build(String(message), syntax, source, locale);
|
|
43
|
+
trim(cache, 499);
|
|
44
|
+
if (parsed.errors.length > 0) report(parsed);
|
|
45
|
+
}
|
|
46
|
+
cache.set(key, parsed);
|
|
47
|
+
return parsed;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Renders `message` as plain text (tags render their children): in the
|
|
51
|
+
* current locale, as `t(parse(message), values)` does, or in `locale` with
|
|
52
|
+
* the current time zone.
|
|
53
|
+
*/
|
|
54
|
+
function format(message, values, locale) {
|
|
55
|
+
const parsed = typeof message === "string" ? parse(message) : message;
|
|
56
|
+
if (locale === void 0) return t(parsed, values);
|
|
57
|
+
const resolver = S.serverResolver;
|
|
58
|
+
const current = resolver ? resolver() : S.resolve();
|
|
59
|
+
let tag;
|
|
60
|
+
try {
|
|
61
|
+
tag = Intl.getCanonicalLocales(locale)[0] ?? "und";
|
|
62
|
+
} catch {
|
|
63
|
+
if (DEV) warnOnce(`format(): ${JSON.stringify(locale)} is no locale; using the current one`);
|
|
64
|
+
tag = current?.locale ?? "und";
|
|
65
|
+
}
|
|
66
|
+
const scope = createScope("translator", tag, /* @__PURE__ */ new Map(), {
|
|
67
|
+
timeZone: current?.timeZone,
|
|
68
|
+
now: current?.now
|
|
69
|
+
});
|
|
70
|
+
return formatMessage(parsed.ir, values, scope);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Calls `handler` with every message `parse()` finds errors in, once per
|
|
74
|
+
* text and options while it is cached; returns the unsubscribe function.
|
|
75
|
+
*/
|
|
76
|
+
function onParseError(handler) {
|
|
77
|
+
handlers.add(handler);
|
|
78
|
+
return () => {
|
|
79
|
+
handlers.delete(handler);
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function build(text, syntax, sourceText, locale) {
|
|
83
|
+
const errors = [];
|
|
84
|
+
const warnings = [];
|
|
85
|
+
const ast = read(text, syntax, errors);
|
|
86
|
+
let source = null;
|
|
87
|
+
if (sourceText !== void 0) {
|
|
88
|
+
const problems = [];
|
|
89
|
+
source = read(sourceText, syntax, problems);
|
|
90
|
+
if (source !== null) {
|
|
91
|
+
for (const d of validateSource(source, {
|
|
92
|
+
locale: "und",
|
|
93
|
+
text: sourceText
|
|
94
|
+
})) if (d.severity === "error") problems.push(issue(d));
|
|
95
|
+
}
|
|
96
|
+
if (problems.length > 0) {
|
|
97
|
+
source = null;
|
|
98
|
+
for (const p of problems) warnings.push({
|
|
99
|
+
...p,
|
|
100
|
+
severity: "warning",
|
|
101
|
+
message: `In the source: ${p.message}`
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (ast !== null) {
|
|
106
|
+
const options = {
|
|
107
|
+
locale: locale ?? "und",
|
|
108
|
+
text
|
|
109
|
+
};
|
|
110
|
+
const found = source !== null ? validateTranslation(ast, source, options) : validateSource(ast, options);
|
|
111
|
+
for (const d of found) {
|
|
112
|
+
if (locale === void 0 && LOCALE_CODES.has(d.code)) continue;
|
|
113
|
+
(d.severity === "error" ? errors : warnings).push(issue(d));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
let ir;
|
|
117
|
+
if (errors.length === 0) ir = compileMessage(ast);
|
|
118
|
+
else if (source !== null) ir = compileMessage(source);
|
|
119
|
+
else ir = text.replace(/[--]/g, "");
|
|
120
|
+
return Object.freeze({
|
|
121
|
+
id: "",
|
|
122
|
+
message: text,
|
|
123
|
+
ir,
|
|
124
|
+
errors: Object.freeze(errors),
|
|
125
|
+
warnings: Object.freeze(warnings)
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
function read(text, syntax, errors) {
|
|
129
|
+
try {
|
|
130
|
+
return parseSource(normalizeSource(text), syntax);
|
|
131
|
+
} catch (error) {
|
|
132
|
+
if (!isDiagnosticError(error)) throw error;
|
|
133
|
+
errors.push(issue(error.diagnostic));
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function issue(d) {
|
|
138
|
+
const out = {
|
|
139
|
+
code: d.code,
|
|
140
|
+
severity: d.severity === "error" ? "error" : "warning",
|
|
141
|
+
message: d.message
|
|
142
|
+
};
|
|
143
|
+
if (d.line) out.line = d.line;
|
|
144
|
+
if (d.column) out.column = d.column;
|
|
145
|
+
return out;
|
|
146
|
+
}
|
|
147
|
+
function report(parsed) {
|
|
148
|
+
if (DEV) warnOnce(`parse(): ${JSON.stringify(parsed.message)} is invalid (${parsed.errors.map((e) => e.message).join("; ")}); rendering ${typeof parsed.ir === "string" ? JSON.stringify(parsed.ir) : "its source"}`);
|
|
149
|
+
for (const handler of handlers) try {
|
|
150
|
+
handler(parsed);
|
|
151
|
+
} catch (error) {
|
|
152
|
+
if (DEV) warnOnce(`onParseError handler threw: ${String(error)}`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
//#endregion
|
|
156
|
+
export { format, onParseError, parse };
|