@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.
Files changed (100) hide show
  1. package/LICENSE +49 -0
  2. package/README.md +110 -2
  3. package/dist/apply-Bre-lY9J.js +228 -0
  4. package/dist/captured-Bj8bO6vd.js +1034 -0
  5. package/dist/check-D34P-S--.js +1 -0
  6. package/dist/check-DyrAbv73.js +201 -0
  7. package/dist/cli.d.ts +1 -0
  8. package/dist/cli.js +41 -0
  9. package/dist/codec-DuvU2VQy.js +207 -0
  10. package/dist/collect-Cx4_SKOe.js +13 -0
  11. package/dist/collisions-CfpZU8e4.js +217 -0
  12. package/dist/compile-B5Mz6WJm.js +245 -0
  13. package/dist/compile-Cc97JaW2.js +2502 -0
  14. package/dist/concurrency-C9UUWuDC.js +96 -0
  15. package/dist/concurrency-DONL7t4V.js +1 -0
  16. package/dist/config.d.ts +21 -0
  17. package/dist/config.js +39 -0
  18. package/dist/dir-zw6bGMKQ.js +290 -0
  19. package/dist/duplicates-yuRljQ6h.js +185 -0
  20. package/dist/engine-B7p40M__.js +531 -0
  21. package/dist/engine.d.ts +43 -0
  22. package/dist/engine.js +1241 -0
  23. package/dist/exclude-Du-Zd_qI.js +26 -0
  24. package/dist/export-DGsMbcTZ.js +103 -0
  25. package/dist/extract-Dujlsgnk.js +298 -0
  26. package/dist/formats-KPIg-08V.js +781 -0
  27. package/dist/i18next-CrUnKFfh.js +1596 -0
  28. package/dist/i18next-Rgo-v9l0.js +1 -0
  29. package/dist/import-Cwdhcywt.js +225 -0
  30. package/dist/index.d.ts +156 -0
  31. package/dist/index.js +239 -0
  32. package/dist/init-BecCTvKi.js +792 -0
  33. package/dist/library-D5CWvTQs.js +1882 -0
  34. package/dist/lingui--PcOOYry.js +833 -0
  35. package/dist/lint.d.ts +105 -0
  36. package/dist/lint.js +971 -0
  37. package/dist/load-CQRz4PpM.js +2950 -0
  38. package/dist/load-gW-oJt1Q.js +747 -0
  39. package/dist/locales-DX4MOBFE.js +827 -0
  40. package/dist/lsp-Cq1Nuu-Q.js +31 -0
  41. package/dist/match-BGr8EXB3.js +89 -0
  42. package/dist/mcp-Cf0T7qPW.js +28 -0
  43. package/dist/merge-driver-CpiiSVIc.js +422 -0
  44. package/dist/messages-Cxa-5tR0.js +166 -0
  45. package/dist/migrate-CntqvrW4.js +1 -0
  46. package/dist/migrate-dPgq9uzy.js +1484 -0
  47. package/dist/openai-CTaMDcl-.js +346 -0
  48. package/dist/output-DsaHKHEt.js +164 -0
  49. package/dist/parse.d.ts +62 -0
  50. package/dist/parse.js +156 -0
  51. package/dist/pipeline-C7g11THL.js +2031 -0
  52. package/dist/pipeline-wxS0SApG.js +1 -0
  53. package/dist/project-Dwx7iPm6.js +381 -0
  54. package/dist/project-pXipT8iG.js +1046 -0
  55. package/dist/pseudo-DRv30iN5.js +145 -0
  56. package/dist/raw-C4Y6vyGY.js +4708 -0
  57. package/dist/react-intl-CaBVwJ9u.js +519 -0
  58. package/dist/restore-Btq66Tid.js +175 -0
  59. package/dist/rewrite-CiTRAICl.js +803 -0
  60. package/dist/rich-DCUKl5HM.js +97 -0
  61. package/dist/rolldown-runtime-D7D4PA-g.js +13 -0
  62. package/dist/run-DYD_VXKy.js +694 -0
  63. package/dist/runtime-DTMmliT1.js +64 -0
  64. package/dist/scan-worker.d.ts +62 -0
  65. package/dist/scan-worker.js +1 -0
  66. package/dist/scoped-BMYpSthj.js +44 -0
  67. package/dist/server-BDkykMjb.js +11823 -0
  68. package/dist/server-qv3mz70d.js +10485 -0
  69. package/dist/server.d.ts +169 -0
  70. package/dist/server.js +1234 -0
  71. package/dist/sitemap-DV3o8QD7.js +159 -0
  72. package/dist/sources-D19czDSA.js +2242 -0
  73. package/dist/status-DZArW5aE.js +149 -0
  74. package/dist/stdio-CVaJfxA7.js +29 -0
  75. package/dist/stdio-FPOKQAgu.js +95 -0
  76. package/dist/sync-CcVzger_.js +658 -0
  77. package/dist/t-DC-c9zE5.js +454 -0
  78. package/dist/test.d.ts +116 -0
  79. package/dist/test.js +319 -0
  80. package/dist/translate-DZR3MkSA.js +299 -0
  81. package/dist/ts-BaU5yOf0.js +4863 -0
  82. package/dist/types-CgUCkFU1.d.ts +707 -0
  83. package/dist/types-D3QGM8XO.js +146 -0
  84. package/dist/types-DsdWBG0b.d.ts +558 -0
  85. package/dist/types-DtvQ7UdD.js +1948 -0
  86. package/dist/types-wSh9fCBY.js +11 -0
  87. package/dist/units-CQ5Q99RC.js +150 -0
  88. package/dist/url-CRfCOhUI.js +172 -0
  89. package/dist/url-CsBkRaJy.js +225 -0
  90. package/dist/validate-BxpupdAf.js +2615 -0
  91. package/dist/validate-D6DJepZv.js +365 -0
  92. package/dist/version-BlyLGlOa.js +28 -0
  93. package/dist/vite-scan-B_YW4X_a.js +242 -0
  94. package/dist/vite.d.ts +34 -0
  95. package/dist/vite.js +7558 -0
  96. package/dist/vue-i18n-CEMnpv7k.js +651 -0
  97. package/dist/which-C6PFI1Dm.js +116 -0
  98. package/dist/worker-84U6uYB3.js +1656 -0
  99. package/package.json +97 -3
  100. 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 };