@lokascript/i18n 1.0.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 (96) hide show
  1. package/README.md +286 -0
  2. package/dist/browser.cjs +7669 -0
  3. package/dist/browser.cjs.map +1 -0
  4. package/dist/browser.d.cts +50 -0
  5. package/dist/browser.d.ts +50 -0
  6. package/dist/browser.js +7592 -0
  7. package/dist/browser.js.map +1 -0
  8. package/dist/hyperfixi-i18n.min.js +2 -0
  9. package/dist/hyperfixi-i18n.min.js.map +1 -0
  10. package/dist/hyperfixi-i18n.mjs +8558 -0
  11. package/dist/hyperfixi-i18n.mjs.map +1 -0
  12. package/dist/index.cjs +14205 -0
  13. package/dist/index.cjs.map +1 -0
  14. package/dist/index.d.cts +947 -0
  15. package/dist/index.d.ts +947 -0
  16. package/dist/index.js +14095 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/transformer-Ckask-yw.d.cts +1041 -0
  19. package/dist/transformer-Ckask-yw.d.ts +1041 -0
  20. package/package.json +84 -0
  21. package/src/browser.ts +122 -0
  22. package/src/compatibility/browser-tests/grammar-demo.spec.ts +169 -0
  23. package/src/constants.ts +366 -0
  24. package/src/dictionaries/ar.ts +233 -0
  25. package/src/dictionaries/bn.ts +156 -0
  26. package/src/dictionaries/de.ts +233 -0
  27. package/src/dictionaries/derive.ts +515 -0
  28. package/src/dictionaries/en.ts +237 -0
  29. package/src/dictionaries/es.ts +233 -0
  30. package/src/dictionaries/fr.ts +233 -0
  31. package/src/dictionaries/hi.ts +270 -0
  32. package/src/dictionaries/id.ts +233 -0
  33. package/src/dictionaries/index.ts +238 -0
  34. package/src/dictionaries/it.ts +233 -0
  35. package/src/dictionaries/ja.ts +233 -0
  36. package/src/dictionaries/ko.ts +233 -0
  37. package/src/dictionaries/ms.ts +276 -0
  38. package/src/dictionaries/pl.ts +239 -0
  39. package/src/dictionaries/pt.ts +237 -0
  40. package/src/dictionaries/qu.ts +233 -0
  41. package/src/dictionaries/ru.ts +270 -0
  42. package/src/dictionaries/sw.ts +233 -0
  43. package/src/dictionaries/th.ts +156 -0
  44. package/src/dictionaries/tl.ts +276 -0
  45. package/src/dictionaries/tr.ts +233 -0
  46. package/src/dictionaries/uk.ts +270 -0
  47. package/src/dictionaries/vi.ts +210 -0
  48. package/src/dictionaries/zh.ts +233 -0
  49. package/src/enhanced-i18n.test.ts +454 -0
  50. package/src/enhanced-i18n.ts +713 -0
  51. package/src/examples/new-languages.ts +326 -0
  52. package/src/formatting.test.ts +213 -0
  53. package/src/formatting.ts +416 -0
  54. package/src/grammar/direct-mappings.ts +353 -0
  55. package/src/grammar/grammar.test.ts +1053 -0
  56. package/src/grammar/index.ts +59 -0
  57. package/src/grammar/profiles/index.ts +860 -0
  58. package/src/grammar/transformer.ts +1318 -0
  59. package/src/grammar/types.ts +630 -0
  60. package/src/index.ts +202 -0
  61. package/src/new-languages.test.ts +389 -0
  62. package/src/parser/analyze-conflicts.test.ts +229 -0
  63. package/src/parser/ar.ts +40 -0
  64. package/src/parser/create-provider.ts +309 -0
  65. package/src/parser/de.ts +36 -0
  66. package/src/parser/es.ts +31 -0
  67. package/src/parser/fr.ts +31 -0
  68. package/src/parser/id.ts +34 -0
  69. package/src/parser/index.ts +50 -0
  70. package/src/parser/ja.ts +36 -0
  71. package/src/parser/ko.ts +37 -0
  72. package/src/parser/locale-manager.test.ts +198 -0
  73. package/src/parser/locale-manager.ts +197 -0
  74. package/src/parser/parser-integration.test.ts +439 -0
  75. package/src/parser/pt.ts +37 -0
  76. package/src/parser/qu.ts +37 -0
  77. package/src/parser/sw.ts +37 -0
  78. package/src/parser/tr.ts +38 -0
  79. package/src/parser/types.ts +113 -0
  80. package/src/parser/zh.ts +38 -0
  81. package/src/plugins/vite.ts +224 -0
  82. package/src/plugins/webpack.ts +124 -0
  83. package/src/pluralization.test.ts +197 -0
  84. package/src/pluralization.ts +393 -0
  85. package/src/runtime.ts +441 -0
  86. package/src/ssr-integration.ts +225 -0
  87. package/src/test-setup.ts +195 -0
  88. package/src/translation-validation.test.ts +171 -0
  89. package/src/translator.test.ts +252 -0
  90. package/src/translator.ts +297 -0
  91. package/src/types.ts +209 -0
  92. package/src/utils/locale.ts +190 -0
  93. package/src/utils/tokenizer-adapter.ts +469 -0
  94. package/src/utils/tokenizer.ts +19 -0
  95. package/src/validators/index.ts +174 -0
  96. package/src/validators/schema.ts +129 -0
@@ -0,0 +1,366 @@
1
+ // packages/i18n/src/constants.ts
2
+
3
+ /**
4
+ * Shared Constants for i18n Package
5
+ *
6
+ * Centralizes keyword definitions to eliminate duplication across
7
+ * transformer.ts, create-provider.ts, and other modules.
8
+ */
9
+
10
+ import type { SemanticRole } from './grammar/types';
11
+
12
+ // =============================================================================
13
+ // English Modifier → Semantic Role Mappings
14
+ // =============================================================================
15
+
16
+ /**
17
+ * Maps English modifier keywords to their semantic roles.
18
+ * Used by both the grammar transformer and keyword provider.
19
+ */
20
+ export const ENGLISH_MODIFIER_ROLES: Readonly<Record<string, SemanticRole>> = {
21
+ to: 'destination',
22
+ into: 'destination',
23
+ from: 'source',
24
+ with: 'style',
25
+ by: 'quantity',
26
+ as: 'method',
27
+ on: 'event',
28
+ over: 'duration',
29
+ for: 'duration',
30
+ } as const;
31
+
32
+ /**
33
+ * English modifier keywords (derived from ENGLISH_MODIFIER_ROLES)
34
+ */
35
+ export const ENGLISH_MODIFIERS: Set<string> = new Set([
36
+ 'to',
37
+ 'from',
38
+ 'into',
39
+ 'with',
40
+ 'at',
41
+ 'in',
42
+ 'of',
43
+ 'as',
44
+ 'by',
45
+ 'before',
46
+ 'after',
47
+ 'without',
48
+ ]);
49
+
50
+ // =============================================================================
51
+ // English Commands
52
+ // =============================================================================
53
+
54
+ /**
55
+ * English commands - the canonical set that the runtime understands.
56
+ */
57
+ export const ENGLISH_COMMANDS: Set<string> = new Set([
58
+ 'add',
59
+ 'append',
60
+ 'async',
61
+ 'beep',
62
+ 'break',
63
+ 'call',
64
+ 'continue',
65
+ 'decrement',
66
+ 'default',
67
+ 'exit',
68
+ 'fetch',
69
+ 'for',
70
+ 'get',
71
+ 'go',
72
+ 'halt',
73
+ 'hide',
74
+ 'if',
75
+ 'increment',
76
+ 'install',
77
+ 'js',
78
+ 'log',
79
+ 'make',
80
+ 'measure',
81
+ 'morph',
82
+ 'pick',
83
+ 'process',
84
+ 'push',
85
+ 'put',
86
+ 'remove',
87
+ 'render',
88
+ 'repeat',
89
+ 'replace',
90
+ 'return',
91
+ 'send',
92
+ 'set',
93
+ 'settle',
94
+ 'show',
95
+ 'swap',
96
+ 'take',
97
+ 'tell',
98
+ 'throw',
99
+ 'toggle',
100
+ 'transition',
101
+ 'trigger',
102
+ 'unless',
103
+ 'wait',
104
+ ]);
105
+
106
+ // =============================================================================
107
+ // English Keywords (Non-Commands)
108
+ // =============================================================================
109
+
110
+ /**
111
+ * English keywords that are not commands.
112
+ */
113
+ export const ENGLISH_KEYWORDS: Set<string> = new Set([
114
+ // Flow control
115
+ 'then',
116
+ 'else',
117
+ 'end',
118
+ 'and',
119
+ 'or',
120
+ 'not',
121
+ // Conditionals
122
+ 'if',
123
+ 'unless',
124
+ // Loops
125
+ 'for',
126
+ 'while',
127
+ 'until',
128
+ 'forever',
129
+ 'times',
130
+ 'each',
131
+ 'index',
132
+ // Prepositions
133
+ 'in',
134
+ 'to',
135
+ 'from',
136
+ 'into',
137
+ 'with',
138
+ 'without',
139
+ 'of',
140
+ 'at',
141
+ 'by',
142
+ // Conversion
143
+ 'as',
144
+ // Comparison
145
+ 'matches',
146
+ 'contains',
147
+ 'is',
148
+ 'exists',
149
+ // Events
150
+ 'on',
151
+ 'when',
152
+ 'every',
153
+ 'event',
154
+ // Definitions
155
+ 'init',
156
+ 'def',
157
+ 'behavior',
158
+ // Scope
159
+ 'global',
160
+ 'local',
161
+ // Articles
162
+ 'the',
163
+ 'a',
164
+ 'an',
165
+ 'first',
166
+ 'last',
167
+ // Position
168
+ 'start',
169
+ 'before',
170
+ 'after',
171
+ ]);
172
+
173
+ // =============================================================================
174
+ // Universal English Keywords (DOM/HTML Standards)
175
+ // =============================================================================
176
+
177
+ /**
178
+ * English keywords that should always be recognized, even in non-English locales.
179
+ * These are HTML/DOM standard terms that developers worldwide use.
180
+ */
181
+ export const UNIVERSAL_ENGLISH_KEYWORDS: Set<string> = new Set([
182
+ // DOM events (HTML spec)
183
+ 'click',
184
+ 'dblclick',
185
+ 'mousedown',
186
+ 'mouseup',
187
+ 'mouseenter',
188
+ 'mouseleave',
189
+ 'mouseover',
190
+ 'mouseout',
191
+ 'mousemove',
192
+ 'keydown',
193
+ 'keyup',
194
+ 'keypress',
195
+ 'focus',
196
+ 'blur',
197
+ 'change',
198
+ 'input',
199
+ 'submit',
200
+ 'reset',
201
+ 'load',
202
+ 'unload',
203
+ 'resize',
204
+ 'scroll',
205
+ 'touchstart',
206
+ 'touchend',
207
+ 'touchmove',
208
+ 'touchcancel',
209
+ 'dragstart',
210
+ 'dragend',
211
+ 'dragenter',
212
+ 'dragleave',
213
+ 'dragover',
214
+ 'drop',
215
+ 'contextmenu',
216
+ 'wheel',
217
+ 'pointerdown',
218
+ 'pointerup',
219
+ 'pointermove',
220
+ // Common abbreviations
221
+ 'ms',
222
+ 's',
223
+ ]);
224
+
225
+ // =============================================================================
226
+ // Logical Keywords
227
+ // =============================================================================
228
+
229
+ /**
230
+ * English logical operator keywords.
231
+ */
232
+ export const ENGLISH_LOGICAL_KEYWORDS: Set<string> = new Set([
233
+ 'and',
234
+ 'or',
235
+ 'not',
236
+ 'is',
237
+ 'exists',
238
+ 'matches',
239
+ 'contains',
240
+ 'then',
241
+ 'else',
242
+ ]);
243
+
244
+ // =============================================================================
245
+ // Value Keywords
246
+ // =============================================================================
247
+
248
+ /**
249
+ * English value keywords.
250
+ */
251
+ export const ENGLISH_VALUE_KEYWORDS: Set<string> = new Set([
252
+ 'true',
253
+ 'false',
254
+ 'null',
255
+ 'undefined',
256
+ 'it',
257
+ 'me',
258
+ 'my',
259
+ 'result',
260
+ ]);
261
+
262
+ // =============================================================================
263
+ // Expression Keywords
264
+ // =============================================================================
265
+
266
+ /**
267
+ * English expression keywords - positional, traversal, and string operations.
268
+ */
269
+ export const ENGLISH_EXPRESSION_KEYWORDS: Set<string> = new Set([
270
+ // Positional
271
+ 'first',
272
+ 'last',
273
+ 'next',
274
+ 'previous',
275
+ 'prev',
276
+ 'at',
277
+ 'random',
278
+ // DOM traversal
279
+ 'closest',
280
+ 'parent',
281
+ 'children',
282
+ 'within',
283
+ // Emptiness/existence
284
+ 'no',
285
+ 'empty',
286
+ 'some',
287
+ // String operations (multi-word)
288
+ 'starts with',
289
+ 'ends with',
290
+ ]);
291
+
292
+ // =============================================================================
293
+ // Conditional Keywords
294
+ // =============================================================================
295
+
296
+ /**
297
+ * Conditional keywords across languages (for statement type identification).
298
+ * Includes 'when'/'where' conditional modifiers and their translations.
299
+ */
300
+ export const CONDITIONAL_KEYWORDS: Set<string> = new Set([
301
+ // English
302
+ 'if',
303
+ 'unless',
304
+ 'when',
305
+ 'where',
306
+ // Japanese
307
+ 'もし',
308
+ '時に',
309
+ 'ときに',
310
+ 'どこで',
311
+ // Chinese
312
+ '如果',
313
+ '当',
314
+ // Arabic
315
+ 'إذا',
316
+ 'عندما',
317
+ 'حيث',
318
+ // Spanish
319
+ 'si',
320
+ 'cuando',
321
+ 'donde',
322
+ // German
323
+ 'wenn',
324
+ 'wann',
325
+ 'wo',
326
+ // French
327
+ 'quand',
328
+ 'lorsque',
329
+ 'où',
330
+ // Portuguese
331
+ 'quando',
332
+ 'onde',
333
+ // Turkish
334
+ 'eğer',
335
+ 'zaman',
336
+ 'nerede',
337
+ // Indonesian
338
+ 'ketika',
339
+ 'saat',
340
+ 'dimana',
341
+ // Korean
342
+ '때',
343
+ '어디서',
344
+ // Quechua
345
+ 'maypi',
346
+ // Swahili
347
+ 'wakati',
348
+ 'wapi',
349
+ ]);
350
+
351
+ /**
352
+ * "Then" keywords across languages (for conditional parsing).
353
+ */
354
+ export const THEN_KEYWORDS: Set<string> = new Set([
355
+ 'then',
356
+ 'それから',
357
+ '那么',
358
+ 'ثم',
359
+ 'entonces',
360
+ 'alors',
361
+ 'dann',
362
+ 'sonra',
363
+ 'lalu',
364
+ 'chayqa',
365
+ 'kisha',
366
+ ]);
@@ -0,0 +1,233 @@
1
+ // packages/i18n/src/dictionaries/ar.ts
2
+
3
+ import { Dictionary } from '../types';
4
+
5
+ export const ar: Dictionary = {
6
+ commands: {
7
+ // Event handling
8
+ on: 'على',
9
+ tell: 'أخبر',
10
+ trigger: 'تشغيل',
11
+ send: 'أرسل',
12
+
13
+ // DOM manipulation
14
+ take: 'خذ',
15
+ put: 'ضع',
16
+ set: 'اضبط',
17
+ get: 'احصل',
18
+ add: 'أضف',
19
+ remove: 'احذف',
20
+ toggle: 'بدل',
21
+ hide: 'اخف',
22
+ show: 'اظهر',
23
+
24
+ // Control flow
25
+ if: 'إذا',
26
+ unless: 'إلا إذا',
27
+ repeat: 'كرر',
28
+ for: 'لكل',
29
+ while: 'بينما',
30
+ until: 'حتى',
31
+ continue: 'واصل',
32
+ break: 'توقف',
33
+ halt: 'أوقف',
34
+
35
+ // Async
36
+ wait: 'انتظر',
37
+ fetch: 'احضر',
38
+ call: 'استدع',
39
+ return: 'ارجع',
40
+
41
+ // Other commands
42
+ make: 'اصنع',
43
+ log: 'سجل',
44
+ throw: 'ارم',
45
+ catch: 'التقط',
46
+ measure: 'قس',
47
+ transition: 'انتقال',
48
+
49
+ // Data Commands
50
+ increment: 'زِد',
51
+ decrement: 'أنقص',
52
+ bind: 'اربط',
53
+ default: 'افتراضي',
54
+ persist: 'احفظ',
55
+
56
+ // Navigation Commands
57
+ go: 'اذهب',
58
+ pushUrl: 'ادفع رابط',
59
+ replaceUrl: 'استبدل رابط',
60
+
61
+ // Utility Commands
62
+ copy: 'انسخ',
63
+ pick: 'اختر',
64
+ beep: 'صفّر',
65
+
66
+ // Advanced Commands
67
+ js: 'جافاسكربت',
68
+ async: 'متزامن',
69
+ render: 'ارسم',
70
+
71
+ // Animation Commands
72
+ swap: 'بدّل',
73
+ morph: 'حوّل',
74
+ settle: 'استقر',
75
+
76
+ // Content Commands
77
+ append: 'ألحق',
78
+
79
+ // Control Flow
80
+ exit: 'اخرج',
81
+
82
+ // Behaviors
83
+ install: 'ثبّت',
84
+ },
85
+
86
+ modifiers: {
87
+ to: 'إلى',
88
+ from: 'من',
89
+ into: 'في',
90
+ with: 'مع',
91
+ at: 'عند',
92
+ in: 'في',
93
+ of: 'من',
94
+ as: 'كـ',
95
+ by: 'بواسطة',
96
+ before: 'قبل',
97
+ after: 'بعد',
98
+ over: 'فوق',
99
+ under: 'تحت',
100
+ between: 'بين',
101
+ through: 'عبر',
102
+ without: 'بدون',
103
+ },
104
+
105
+ events: {
106
+ click: 'نقر',
107
+ dblclick: 'نقر مزدوج',
108
+ mousedown: 'فأرة أسفل',
109
+ mouseup: 'فأرة أعلى',
110
+ mouseenter: 'فأرة دخول',
111
+ mouseleave: 'فأرة خروج',
112
+ mouseover: 'فأرة فوق',
113
+ mouseout: 'فأرة خارج',
114
+ mousemove: 'فأرة تحرك',
115
+
116
+ keydown: 'مفتاح أسفل',
117
+ keyup: 'مفتاح أعلى',
118
+ keypress: 'مفتاح ضغط',
119
+
120
+ focus: 'تركيز',
121
+ blur: 'ضبابية',
122
+ change: 'تغيير',
123
+ input: 'إدخال',
124
+ submit: 'إرسال',
125
+ reset: 'إعادة تعيين',
126
+
127
+ load: 'تحميل',
128
+ unload: 'إلغاء تحميل',
129
+ resize: 'تغيير حجم',
130
+ scroll: 'تمرير',
131
+
132
+ touchstart: 'بداية لمس',
133
+ touchend: 'نهاية لمس',
134
+ touchmove: 'تحرك لمس',
135
+ touchcancel: 'إلغاء لمس',
136
+ },
137
+
138
+ logical: {
139
+ when: 'عندما',
140
+ where: 'أين',
141
+ and: 'و',
142
+ or: 'أو',
143
+ not: 'ليس',
144
+ is: 'هو',
145
+ exists: 'موجود',
146
+ matches: 'يطابق',
147
+ contains: 'يحتوي',
148
+ includes: 'يشمل',
149
+ equals: 'يساوي',
150
+ has: 'لديه', // third-person: he/it has
151
+ have: 'لدي', // first-person: I have
152
+ then: 'ثم',
153
+ else: 'وإلا',
154
+ otherwise: 'خلاف ذلك',
155
+ end: 'النهاية',
156
+ },
157
+
158
+ temporal: {
159
+ seconds: 'ثوانِ',
160
+ second: 'ثانية',
161
+ milliseconds: 'ميلي ثانية',
162
+ millisecond: 'ميلي ثانية',
163
+ minutes: 'دقائق',
164
+ minute: 'دقيقة',
165
+ hours: 'ساعات',
166
+ hour: 'ساعة',
167
+ ms: 'م.ث',
168
+ s: 'ث',
169
+ min: 'د',
170
+ h: 'س',
171
+ },
172
+
173
+ values: {
174
+ true: 'صحيح',
175
+ false: 'خطأ',
176
+ null: 'فارغ',
177
+ undefined: 'غير معرف',
178
+ it: 'هو',
179
+ its: 'له', // REVIEW: native speaker
180
+ me: 'أنا',
181
+ my: 'لي',
182
+ myself: 'نفسي',
183
+ you: 'أنت', // REVIEW: native speaker
184
+ your: 'لك', // REVIEW: native speaker
185
+ yourself: 'نفسك', // REVIEW: native speaker
186
+ element: 'عنصر',
187
+ target: 'هدف',
188
+ detail: 'تفاصيل',
189
+ event: 'حدث',
190
+ window: 'نافذة',
191
+ document: 'وثيقة',
192
+ body: 'جسم',
193
+ result: 'نتيجة',
194
+ value: 'قيمة',
195
+ },
196
+
197
+ attributes: {
198
+ class: 'فئة',
199
+ classes: 'فئات',
200
+ style: 'أسلوب',
201
+ styles: 'أساليب',
202
+ attribute: 'خاصية',
203
+ attributes: 'خصائص',
204
+ property: 'خاصية',
205
+ properties: 'خصائص',
206
+ },
207
+
208
+ expressions: {
209
+ // Positional
210
+ first: 'أول',
211
+ last: 'آخر',
212
+ next: 'التالي',
213
+ previous: 'السابق',
214
+ prev: 'سابق',
215
+ at: 'عند',
216
+ random: 'عشوائي',
217
+
218
+ // DOM Traversal
219
+ closest: 'الأقرب',
220
+ parent: 'والد',
221
+ children: 'أطفال',
222
+ within: 'داخل',
223
+
224
+ // Emptiness/Existence
225
+ no: 'لا يوجد',
226
+ empty: 'فارغ',
227
+ some: 'بعض',
228
+
229
+ // String operations
230
+ 'starts with': 'يبدأ بـ',
231
+ 'ends with': 'ينتهي بـ',
232
+ },
233
+ };