@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
@@ -0,0 +1,145 @@
1
+ //#region src/core/ir/pseudo.ts
2
+ /**
3
+ * Accented look-alikes of `A–Z` then `a–z` (one precomposed code point each),
4
+ * readable at a glance yet impossible to mistake for untranslated text.
5
+ */
6
+ const ACCENTED = "ÁƁÇÐÉƑĜĤÍĴĶĻṀÑÓÞǪŔŠŢÚṼŴẊÝŽáƀçðéƒĝĥíĵķļɱñóþǫŕšţúṽŵẋýž";
7
+ const ACCENTED_BY_CODE = (() => {
8
+ const table = [];
9
+ for (let i = 0; i < 26; i++) {
10
+ table[65 + i] = ACCENTED.charAt(i);
11
+ table[97 + i] = ACCENTED.charAt(26 + i);
12
+ }
13
+ return table;
14
+ })();
15
+ const IS_VOWEL = (() => {
16
+ const table = [];
17
+ for (const vowel of "AEIOUaeiou") table[vowel.charCodeAt(0)] = true;
18
+ return table;
19
+ })();
20
+ /**
21
+ * A pseudo-localised copy of a source message (INTERNALS §2.3).
22
+ *
23
+ * Only literal text changes: arguments, option keys, tags and `#` are kept, so
24
+ * the result has the source's structure and renders with the same values.
25
+ * `en-XA` accents ASCII letters and lengthens each literal that has letters by
26
+ * ⌈35 %⌉ of its length (PLAN §4.7), the typical growth from English to German
27
+ * or French, so layouts meet the overflow real translations cause; `ar-XB` keeps
28
+ * the letters and forces right-to-left display. Both bracket the whole
29
+ * message, so text on screen without brackets was not translated and brackets
30
+ * inside a sentence reveal concatenation (PLAN §5.21).
31
+ */
32
+ function pseudoLocalize(message, locale) {
33
+ return locale === "en-XA" ? wrap(mapNodes(message, accent), "[", "]") : wrap(mapNodes(message, identity), "[‮", "‬]");
34
+ }
35
+ /**
36
+ * Rebuilds a node with `text` applied to its literal text. Output nodes carry
37
+ * no `loc`: offsets into the source mean nothing for generated text.
38
+ */
39
+ function mapNode(node, text) {
40
+ switch (node.type) {
41
+ case "literal": return {
42
+ type: "literal",
43
+ value: text(node.value)
44
+ };
45
+ case "argument": return {
46
+ type: "argument",
47
+ name: node.name
48
+ };
49
+ case "pound": return { type: "pound" };
50
+ case "number":
51
+ case "date":
52
+ case "time": return {
53
+ type: node.type,
54
+ name: node.name,
55
+ style: node.style === null ? null : { ...node.style },
56
+ options: node.options === null ? null : { ...node.options }
57
+ };
58
+ case "select": return {
59
+ type: "select",
60
+ name: node.name,
61
+ options: mapOptions(node.options, text)
62
+ };
63
+ case "plural": return {
64
+ type: "plural",
65
+ pluralType: node.pluralType,
66
+ name: node.name,
67
+ offset: node.offset,
68
+ options: mapOptions(node.options, text)
69
+ };
70
+ case "tag": return {
71
+ type: "tag",
72
+ name: node.name,
73
+ children: node.children === null ? null : mapNodes(node.children, text)
74
+ };
75
+ }
76
+ }
77
+ function mapNodes(nodes, text) {
78
+ const out = [];
79
+ for (const node of nodes) out.push(mapNode(node, text));
80
+ return out;
81
+ }
82
+ function mapOptions(options, text) {
83
+ const out = [];
84
+ for (const option of options) out.push({
85
+ key: option.key,
86
+ value: mapNodes(option.value, text)
87
+ });
88
+ return out;
89
+ }
90
+ function identity(value) {
91
+ return value;
92
+ }
93
+ /** Extra characters per literal, in percent of its length (PLAN §4.7). */
94
+ const EXPANSION_PERCENT = 35;
95
+ function accent(value) {
96
+ const chars = Array.from(value);
97
+ let letters = 0;
98
+ let vowels = 0;
99
+ for (const char of chars) {
100
+ const code = char.charCodeAt(0);
101
+ if (char.length !== 1 || code >= 128 || ACCENTED_BY_CODE[code] === void 0) continue;
102
+ letters++;
103
+ if (IS_VOWEL[code] === true) vowels++;
104
+ }
105
+ const extra = letters === 0 ? 0 : Math.ceil(chars.length * EXPANSION_PERCENT / 100);
106
+ const byVowel = vowels > 0 && extra <= 2 * vowels;
107
+ const carriers = byVowel ? vowels : letters;
108
+ let out = "";
109
+ let seen = 0;
110
+ for (const char of chars) {
111
+ const code = char.charCodeAt(0);
112
+ const mapped = char.length === 1 && code < 128 ? ACCENTED_BY_CODE[code] : void 0;
113
+ if (mapped === void 0) {
114
+ out += char;
115
+ continue;
116
+ }
117
+ out += mapped;
118
+ if (byVowel && IS_VOWEL[code] !== true) continue;
119
+ const copies = Math.floor((seen + 1) * extra / carriers) - Math.floor(seen * extra / carriers);
120
+ seen++;
121
+ if (copies > 0) out += mapped.repeat(copies);
122
+ }
123
+ return out;
124
+ }
125
+ /**
126
+ * Adds the brackets as literal text, merged into a literal at either end so
127
+ * the result keeps the AST invariant that adjacent literals are one node.
128
+ */
129
+ function wrap(nodes, open, close) {
130
+ const first = nodes[0];
131
+ if (first?.type === "literal") first.value = open + first.value;
132
+ else nodes.unshift({
133
+ type: "literal",
134
+ value: open
135
+ });
136
+ const last = nodes[nodes.length - 1];
137
+ if (last.type === "literal") last.value += close;
138
+ else nodes.push({
139
+ type: "literal",
140
+ value: close
141
+ });
142
+ return nodes;
143
+ }
144
+ //#endregion
145
+ export { pseudoLocalize as t };