@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.
- package/README.md +286 -0
- package/dist/browser.cjs +7669 -0
- package/dist/browser.cjs.map +1 -0
- package/dist/browser.d.cts +50 -0
- package/dist/browser.d.ts +50 -0
- package/dist/browser.js +7592 -0
- package/dist/browser.js.map +1 -0
- package/dist/hyperfixi-i18n.min.js +2 -0
- package/dist/hyperfixi-i18n.min.js.map +1 -0
- package/dist/hyperfixi-i18n.mjs +8558 -0
- package/dist/hyperfixi-i18n.mjs.map +1 -0
- package/dist/index.cjs +14205 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +947 -0
- package/dist/index.d.ts +947 -0
- package/dist/index.js +14095 -0
- package/dist/index.js.map +1 -0
- package/dist/transformer-Ckask-yw.d.cts +1041 -0
- package/dist/transformer-Ckask-yw.d.ts +1041 -0
- package/package.json +84 -0
- package/src/browser.ts +122 -0
- package/src/compatibility/browser-tests/grammar-demo.spec.ts +169 -0
- package/src/constants.ts +366 -0
- package/src/dictionaries/ar.ts +233 -0
- package/src/dictionaries/bn.ts +156 -0
- package/src/dictionaries/de.ts +233 -0
- package/src/dictionaries/derive.ts +515 -0
- package/src/dictionaries/en.ts +237 -0
- package/src/dictionaries/es.ts +233 -0
- package/src/dictionaries/fr.ts +233 -0
- package/src/dictionaries/hi.ts +270 -0
- package/src/dictionaries/id.ts +233 -0
- package/src/dictionaries/index.ts +238 -0
- package/src/dictionaries/it.ts +233 -0
- package/src/dictionaries/ja.ts +233 -0
- package/src/dictionaries/ko.ts +233 -0
- package/src/dictionaries/ms.ts +276 -0
- package/src/dictionaries/pl.ts +239 -0
- package/src/dictionaries/pt.ts +237 -0
- package/src/dictionaries/qu.ts +233 -0
- package/src/dictionaries/ru.ts +270 -0
- package/src/dictionaries/sw.ts +233 -0
- package/src/dictionaries/th.ts +156 -0
- package/src/dictionaries/tl.ts +276 -0
- package/src/dictionaries/tr.ts +233 -0
- package/src/dictionaries/uk.ts +270 -0
- package/src/dictionaries/vi.ts +210 -0
- package/src/dictionaries/zh.ts +233 -0
- package/src/enhanced-i18n.test.ts +454 -0
- package/src/enhanced-i18n.ts +713 -0
- package/src/examples/new-languages.ts +326 -0
- package/src/formatting.test.ts +213 -0
- package/src/formatting.ts +416 -0
- package/src/grammar/direct-mappings.ts +353 -0
- package/src/grammar/grammar.test.ts +1053 -0
- package/src/grammar/index.ts +59 -0
- package/src/grammar/profiles/index.ts +860 -0
- package/src/grammar/transformer.ts +1318 -0
- package/src/grammar/types.ts +630 -0
- package/src/index.ts +202 -0
- package/src/new-languages.test.ts +389 -0
- package/src/parser/analyze-conflicts.test.ts +229 -0
- package/src/parser/ar.ts +40 -0
- package/src/parser/create-provider.ts +309 -0
- package/src/parser/de.ts +36 -0
- package/src/parser/es.ts +31 -0
- package/src/parser/fr.ts +31 -0
- package/src/parser/id.ts +34 -0
- package/src/parser/index.ts +50 -0
- package/src/parser/ja.ts +36 -0
- package/src/parser/ko.ts +37 -0
- package/src/parser/locale-manager.test.ts +198 -0
- package/src/parser/locale-manager.ts +197 -0
- package/src/parser/parser-integration.test.ts +439 -0
- package/src/parser/pt.ts +37 -0
- package/src/parser/qu.ts +37 -0
- package/src/parser/sw.ts +37 -0
- package/src/parser/tr.ts +38 -0
- package/src/parser/types.ts +113 -0
- package/src/parser/zh.ts +38 -0
- package/src/plugins/vite.ts +224 -0
- package/src/plugins/webpack.ts +124 -0
- package/src/pluralization.test.ts +197 -0
- package/src/pluralization.ts +393 -0
- package/src/runtime.ts +441 -0
- package/src/ssr-integration.ts +225 -0
- package/src/test-setup.ts +195 -0
- package/src/translation-validation.test.ts +171 -0
- package/src/translator.test.ts +252 -0
- package/src/translator.ts +297 -0
- package/src/types.ts +209 -0
- package/src/utils/locale.ts +190 -0
- package/src/utils/tokenizer-adapter.ts +469 -0
- package/src/utils/tokenizer.ts +19 -0
- package/src/validators/index.ts +174 -0
- package/src/validators/schema.ts +129 -0
|
@@ -0,0 +1,1041 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* KeywordProvider interface for locale-aware parsing.
|
|
3
|
+
*
|
|
4
|
+
* This interface allows the parser to resolve non-English keywords
|
|
5
|
+
* to their canonical English equivalents, enabling multilingual
|
|
6
|
+
* hyperscript syntax.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { esKeywords } from '@lokascript/i18n/parser/es';
|
|
11
|
+
* const parser = new Parser({ keywords: esKeywords });
|
|
12
|
+
* parser.parse('en clic alternar .active'); // Works!
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
interface KeywordProvider {
|
|
16
|
+
/** The locale code for this provider (e.g., 'es', 'ja') */
|
|
17
|
+
readonly locale: string;
|
|
18
|
+
/**
|
|
19
|
+
* Resolve a token to its canonical (English) keyword.
|
|
20
|
+
* Returns undefined if the token is not a recognized keyword.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* esKeywords.resolve('alternar') // 'toggle'
|
|
24
|
+
* esKeywords.resolve('en') // 'on'
|
|
25
|
+
* esKeywords.resolve('unknown') // undefined
|
|
26
|
+
*/
|
|
27
|
+
resolve(token: string): string | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Check if the token is a command in this locale.
|
|
30
|
+
* Includes both locale keywords and English fallbacks.
|
|
31
|
+
*/
|
|
32
|
+
isCommand(token: string): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Check if the token is a keyword (non-command) in this locale.
|
|
35
|
+
* Includes modifiers, logical operators, events, etc.
|
|
36
|
+
*/
|
|
37
|
+
isKeyword(token: string): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Check if the token is an event name in this locale.
|
|
40
|
+
*/
|
|
41
|
+
isEvent(token: string): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Check if the token is a modifier/preposition in this locale.
|
|
44
|
+
*/
|
|
45
|
+
isModifier(token: string): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Check if the token is a logical operator in this locale.
|
|
48
|
+
*/
|
|
49
|
+
isLogical(token: string): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Check if the token is a value keyword (me, it, true, etc.) in this locale.
|
|
52
|
+
*/
|
|
53
|
+
isValue(token: string): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Check if the token is an expression keyword (first, last, closest, etc.) in this locale.
|
|
56
|
+
*/
|
|
57
|
+
isExpression(token: string): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Get all command names in this locale (for completions).
|
|
60
|
+
*/
|
|
61
|
+
getCommands(): string[];
|
|
62
|
+
/**
|
|
63
|
+
* Get all keywords in this locale (for completions).
|
|
64
|
+
*/
|
|
65
|
+
getKeywords(): string[];
|
|
66
|
+
/**
|
|
67
|
+
* Get the locale keyword for an English canonical keyword.
|
|
68
|
+
* Useful for error messages and IDE completions in native language.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* esKeywords.toLocale('toggle') // 'alternar'
|
|
72
|
+
*/
|
|
73
|
+
toLocale(englishKeyword: string): string | undefined;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Options for creating a keyword provider.
|
|
77
|
+
*/
|
|
78
|
+
interface KeywordProviderOptions {
|
|
79
|
+
/**
|
|
80
|
+
* When true, English keywords are always accepted alongside locale keywords.
|
|
81
|
+
* This allows mixing: "en click alternar .active"
|
|
82
|
+
* @default true
|
|
83
|
+
*/
|
|
84
|
+
allowEnglishFallback?: boolean;
|
|
85
|
+
/**
|
|
86
|
+
* Categories to include. If not specified, all categories are included.
|
|
87
|
+
*/
|
|
88
|
+
categories?: Array<'commands' | 'modifiers' | 'events' | 'logical' | 'temporal' | 'values' | 'attributes' | 'expressions'>;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Dictionary category names as a union type for type-safe access.
|
|
93
|
+
*/
|
|
94
|
+
type DictionaryCategory = 'commands' | 'modifiers' | 'events' | 'logical' | 'temporal' | 'values' | 'attributes' | 'expressions';
|
|
95
|
+
/**
|
|
96
|
+
* All valid dictionary categories.
|
|
97
|
+
*/
|
|
98
|
+
declare const DICTIONARY_CATEGORIES: readonly DictionaryCategory[];
|
|
99
|
+
/**
|
|
100
|
+
* Dictionary structure for i18n translations.
|
|
101
|
+
* Maps English canonical keywords to locale-specific translations.
|
|
102
|
+
*
|
|
103
|
+
* Note: Index signature removed for stricter type safety.
|
|
104
|
+
* Use DICTIONARY_CATEGORIES to iterate over categories.
|
|
105
|
+
*/
|
|
106
|
+
interface Dictionary {
|
|
107
|
+
commands: Record<string, string>;
|
|
108
|
+
modifiers: Record<string, string>;
|
|
109
|
+
events: Record<string, string>;
|
|
110
|
+
logical: Record<string, string>;
|
|
111
|
+
temporal: Record<string, string>;
|
|
112
|
+
values: Record<string, string>;
|
|
113
|
+
attributes: Record<string, string>;
|
|
114
|
+
expressions: Record<string, string>;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Type guard to check if a string is a valid dictionary category.
|
|
118
|
+
*/
|
|
119
|
+
declare function isDictionaryCategory(key: string): key is DictionaryCategory;
|
|
120
|
+
/**
|
|
121
|
+
* Safely get a category from a dictionary with type narrowing.
|
|
122
|
+
* Returns undefined if the category doesn't exist.
|
|
123
|
+
*/
|
|
124
|
+
declare function getDictionaryCategory(dict: Dictionary, category: string): Record<string, string> | undefined;
|
|
125
|
+
/**
|
|
126
|
+
* Iterate over all categories in a dictionary with proper typing.
|
|
127
|
+
*/
|
|
128
|
+
declare function forEachCategory(dict: Dictionary, callback: (category: DictionaryCategory, entries: Record<string, string>) => void): void;
|
|
129
|
+
/**
|
|
130
|
+
* Find a translation in any category of a dictionary.
|
|
131
|
+
* Returns the English key if found, undefined otherwise.
|
|
132
|
+
*/
|
|
133
|
+
declare function findInDictionary(dict: Dictionary, localizedWord: string): {
|
|
134
|
+
category: DictionaryCategory;
|
|
135
|
+
englishKey: string;
|
|
136
|
+
} | undefined;
|
|
137
|
+
/**
|
|
138
|
+
* Find a translation for an English word in any category.
|
|
139
|
+
* Returns the localized word if found, undefined otherwise.
|
|
140
|
+
*/
|
|
141
|
+
declare function translateFromEnglish(dict: Dictionary, englishWord: string): string | undefined;
|
|
142
|
+
interface I18nConfig {
|
|
143
|
+
locale: string;
|
|
144
|
+
fallbackLocale?: string;
|
|
145
|
+
dictionaries?: Record<string, Dictionary>;
|
|
146
|
+
detectLocale?: boolean;
|
|
147
|
+
rtlLocales?: string[];
|
|
148
|
+
preserveOriginalAttribute?: string;
|
|
149
|
+
}
|
|
150
|
+
interface TranslationOptions {
|
|
151
|
+
from?: string;
|
|
152
|
+
to: string;
|
|
153
|
+
preserveOriginal?: boolean;
|
|
154
|
+
validate?: boolean;
|
|
155
|
+
}
|
|
156
|
+
interface ValidationResult {
|
|
157
|
+
valid: boolean;
|
|
158
|
+
errors: ValidationError[];
|
|
159
|
+
warnings: ValidationWarning[];
|
|
160
|
+
coverage: {
|
|
161
|
+
total: number;
|
|
162
|
+
translated: number;
|
|
163
|
+
missing: string[];
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
interface ValidationError {
|
|
167
|
+
type: 'missing' | 'invalid' | 'duplicate';
|
|
168
|
+
key: string;
|
|
169
|
+
message: string;
|
|
170
|
+
}
|
|
171
|
+
interface ValidationWarning {
|
|
172
|
+
type: 'unused' | 'deprecated' | 'inconsistent';
|
|
173
|
+
key: string;
|
|
174
|
+
message: string;
|
|
175
|
+
}
|
|
176
|
+
interface LocaleMetadata {
|
|
177
|
+
code: string;
|
|
178
|
+
name: string;
|
|
179
|
+
nativeName: string;
|
|
180
|
+
rtl: boolean;
|
|
181
|
+
pluralRules?: (n: number) => string;
|
|
182
|
+
}
|
|
183
|
+
interface TranslationContext {
|
|
184
|
+
locale: string;
|
|
185
|
+
direction: 'ltr' | 'rtl';
|
|
186
|
+
dictionary: Dictionary;
|
|
187
|
+
metadata: LocaleMetadata;
|
|
188
|
+
}
|
|
189
|
+
type TokenType = 'command' | 'modifier' | 'event' | 'logical' | 'temporal' | 'value' | 'attribute' | 'expression' | 'identifier' | 'operator' | 'literal';
|
|
190
|
+
interface Token {
|
|
191
|
+
type: TokenType;
|
|
192
|
+
value: string;
|
|
193
|
+
translated?: string;
|
|
194
|
+
position: {
|
|
195
|
+
start: number;
|
|
196
|
+
end: number;
|
|
197
|
+
line: number;
|
|
198
|
+
column: number;
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
interface TranslationResult {
|
|
202
|
+
translated: string;
|
|
203
|
+
original?: string;
|
|
204
|
+
tokens: Token[];
|
|
205
|
+
locale: {
|
|
206
|
+
from: string;
|
|
207
|
+
to: string;
|
|
208
|
+
};
|
|
209
|
+
warnings?: string[];
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Generalized Grammar System for Multilingual Hyperscript
|
|
214
|
+
*
|
|
215
|
+
* This system abstracts grammatical patterns across language families,
|
|
216
|
+
* enabling deep multilingual support without per-language hardcoding.
|
|
217
|
+
*
|
|
218
|
+
* Key Linguistic Concepts:
|
|
219
|
+
* - Word Order: SVO, SOV, VSO (and variations)
|
|
220
|
+
* - Adposition Type: Preposition (English) vs Postposition (Japanese/Korean)
|
|
221
|
+
* - Morphology: Isolating (Chinese) vs Agglutinative (Turkish) vs Fusional (Arabic)
|
|
222
|
+
* - Text Direction: LTR vs RTL
|
|
223
|
+
*/
|
|
224
|
+
/**
|
|
225
|
+
* Semantic roles in hyperscript commands.
|
|
226
|
+
* These are universal across all 13 supported languages - only the surface form changes.
|
|
227
|
+
*
|
|
228
|
+
* ## Core Thematic Roles (from linguistic theory)
|
|
229
|
+
* | Role | Usage | Purpose | Example |
|
|
230
|
+
* |-------------|-------|-----------------------------|---------------------------|
|
|
231
|
+
* | action | 100% | Command verb | toggle, put, fetch |
|
|
232
|
+
* | patient | 90% | What is acted upon | .active, #count |
|
|
233
|
+
* | destination | 40% | Where something goes | into #output, to .class |
|
|
234
|
+
* | source | 13% | Where something comes from | from #input, from URL |
|
|
235
|
+
* | event | 106% | Trigger events | click, keydown, submit |
|
|
236
|
+
* | condition | 8% | Boolean expressions | if x > 5, when visible |
|
|
237
|
+
* | agent | 0% | Who performs action | Reserved for future use |
|
|
238
|
+
* | goal | 1% | Target value/state | to 'red' (in transition) |
|
|
239
|
+
*
|
|
240
|
+
* ## Quantitative Roles (answer "how much/long")
|
|
241
|
+
* | Role | Usage | Purpose | Example |
|
|
242
|
+
* |----------|-------|----------------|----------------------|
|
|
243
|
+
* | quantity | 7% | Numeric amount | by 5, 3 times |
|
|
244
|
+
* | duration | 1% | Time span | for 5 seconds, 500ms |
|
|
245
|
+
*
|
|
246
|
+
* ## Adverbial/Modifier Roles (answer "how/by what means")
|
|
247
|
+
* | Role | Usage | Purpose | Example |
|
|
248
|
+
* |--------------|-------|---------------------------|-------------------|
|
|
249
|
+
* | style | 2% | Animation/behavior | with fade |
|
|
250
|
+
* | manner | 2% | Insertion position | before, after |
|
|
251
|
+
* | method | 1% | HTTP method/technique | via POST, as GET |
|
|
252
|
+
* | responseType | 1% | Response format | as json, as html |
|
|
253
|
+
*
|
|
254
|
+
* ## Control Flow Roles
|
|
255
|
+
* | Role | Usage | Purpose | Example |
|
|
256
|
+
* |----------|-------|--------------|-----------------------|
|
|
257
|
+
* | loopType | 6% | Loop variant | forever, until, times |
|
|
258
|
+
*
|
|
259
|
+
* ## Design Notes
|
|
260
|
+
* - Low-usage roles (agent, goal, method, responseType) are intentionally kept for:
|
|
261
|
+
* - Linguistic completeness across all 13 languages
|
|
262
|
+
* - Future extensibility (AI agents, server-side execution)
|
|
263
|
+
* - Command-specific semantics (fetch, transition)
|
|
264
|
+
* - Each role has distinct grammatical markers per language (see profiles/index.ts)
|
|
265
|
+
* - Usage percentages based on pattern database analysis
|
|
266
|
+
*/
|
|
267
|
+
type SemanticRole = 'action' | 'agent' | 'patient' | 'source' | 'destination' | 'goal' | 'event' | 'condition' | 'quantity' | 'duration' | 'responseType' | 'method' | 'style' | 'manner' | 'loopType' | 'continues';
|
|
268
|
+
/**
|
|
269
|
+
* Word order patterns
|
|
270
|
+
* These represent the major typological categories
|
|
271
|
+
*/
|
|
272
|
+
type WordOrder = 'SVO' | 'SOV' | 'VSO' | 'VOS' | 'OVS' | 'OSV' | 'free';
|
|
273
|
+
/**
|
|
274
|
+
* Where grammatical markers appear relative to their noun/verb
|
|
275
|
+
*/
|
|
276
|
+
type AdpositionType = 'preposition' | 'postposition' | 'circumposition' | 'none';
|
|
277
|
+
/**
|
|
278
|
+
* Morphological typology - how words are constructed
|
|
279
|
+
*/
|
|
280
|
+
type MorphologyType = 'isolating' | 'agglutinative' | 'fusional' | 'polysynthetic';
|
|
281
|
+
/**
|
|
282
|
+
* A grammatical marker (particle, case ending, preposition)
|
|
283
|
+
*/
|
|
284
|
+
interface GrammaticalMarker {
|
|
285
|
+
form: string;
|
|
286
|
+
role: SemanticRole;
|
|
287
|
+
position: AdpositionType;
|
|
288
|
+
required: boolean;
|
|
289
|
+
alternatives?: string[];
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Complete grammatical profile for a language
|
|
293
|
+
* This captures the essential typological features needed for transformation
|
|
294
|
+
*/
|
|
295
|
+
interface LanguageProfile {
|
|
296
|
+
code: string;
|
|
297
|
+
name: string;
|
|
298
|
+
wordOrder: WordOrder;
|
|
299
|
+
adpositionType: AdpositionType;
|
|
300
|
+
morphology: MorphologyType;
|
|
301
|
+
direction: 'ltr' | 'rtl';
|
|
302
|
+
markers: GrammaticalMarker[];
|
|
303
|
+
canonicalOrder: SemanticRole[];
|
|
304
|
+
rules?: GrammarRule[];
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Pattern for transforming hyperscript structures
|
|
308
|
+
*/
|
|
309
|
+
interface GrammarRule {
|
|
310
|
+
name: string;
|
|
311
|
+
description: string;
|
|
312
|
+
match: PatternMatcher;
|
|
313
|
+
transform: PatternTransform;
|
|
314
|
+
priority: number;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Matches a hyperscript pattern
|
|
318
|
+
*/
|
|
319
|
+
interface PatternMatcher {
|
|
320
|
+
commands?: string[];
|
|
321
|
+
requiredRoles: SemanticRole[];
|
|
322
|
+
optionalRoles?: SemanticRole[];
|
|
323
|
+
predicate?: (parsed: ParsedStatement) => boolean;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Defines how to transform a matched pattern
|
|
327
|
+
*/
|
|
328
|
+
interface PatternTransform {
|
|
329
|
+
roleOrder: SemanticRole[];
|
|
330
|
+
insertMarkers?: boolean;
|
|
331
|
+
custom?: (parsed: ParsedStatement, profile: LanguageProfile) => string;
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* A parsed hyperscript statement broken into semantic components
|
|
335
|
+
*/
|
|
336
|
+
interface ParsedStatement {
|
|
337
|
+
type: 'event-handler' | 'command' | 'conditional' | 'loop';
|
|
338
|
+
roles: Map<SemanticRole, ParsedElement>;
|
|
339
|
+
original: string;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* A single element with its semantic role
|
|
343
|
+
*/
|
|
344
|
+
interface ParsedElement {
|
|
345
|
+
role: SemanticRole;
|
|
346
|
+
value: string;
|
|
347
|
+
translated?: string;
|
|
348
|
+
isSelector?: boolean;
|
|
349
|
+
isLiteral?: boolean;
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Universal templates for common hyperscript patterns
|
|
353
|
+
* These define the semantic structure independent of surface form
|
|
354
|
+
*/
|
|
355
|
+
declare const UNIVERSAL_PATTERNS: {
|
|
356
|
+
readonly eventIncrement: {
|
|
357
|
+
readonly name: "event-increment";
|
|
358
|
+
readonly roles: SemanticRole[];
|
|
359
|
+
readonly english: "on {event} {action} {patient}";
|
|
360
|
+
};
|
|
361
|
+
readonly putInto: {
|
|
362
|
+
readonly name: "put-into";
|
|
363
|
+
readonly roles: SemanticRole[];
|
|
364
|
+
readonly english: "{action} {patient} into {destination}";
|
|
365
|
+
};
|
|
366
|
+
readonly addTo: {
|
|
367
|
+
readonly name: "add-to";
|
|
368
|
+
readonly roles: SemanticRole[];
|
|
369
|
+
readonly english: "{action} {patient} to {destination}";
|
|
370
|
+
};
|
|
371
|
+
readonly toggleOn: {
|
|
372
|
+
readonly name: "toggle-on";
|
|
373
|
+
readonly roles: SemanticRole[];
|
|
374
|
+
readonly english: "{action} {patient} on {destination}";
|
|
375
|
+
};
|
|
376
|
+
readonly waitDuration: {
|
|
377
|
+
readonly name: "wait-duration";
|
|
378
|
+
readonly roles: SemanticRole[];
|
|
379
|
+
readonly english: "{action} {quantity}";
|
|
380
|
+
};
|
|
381
|
+
readonly conditional: {
|
|
382
|
+
readonly name: "conditional";
|
|
383
|
+
readonly roles: SemanticRole[];
|
|
384
|
+
readonly english: "{action} {condition} then ... end";
|
|
385
|
+
};
|
|
386
|
+
readonly fetchAs: {
|
|
387
|
+
readonly name: "fetch-as";
|
|
388
|
+
readonly roles: SemanticRole[];
|
|
389
|
+
readonly english: "{action} {source} as {method}";
|
|
390
|
+
};
|
|
391
|
+
readonly showWith: {
|
|
392
|
+
readonly name: "show-with";
|
|
393
|
+
readonly roles: SemanticRole[];
|
|
394
|
+
readonly english: "{action} {patient} with {style}";
|
|
395
|
+
};
|
|
396
|
+
readonly transitionOver: {
|
|
397
|
+
readonly name: "transition-over";
|
|
398
|
+
readonly roles: SemanticRole[];
|
|
399
|
+
readonly english: "{action} {patient} over {duration}";
|
|
400
|
+
};
|
|
401
|
+
};
|
|
402
|
+
/**
|
|
403
|
+
* Default profiles for major language families
|
|
404
|
+
* Individual languages inherit and override these
|
|
405
|
+
*/
|
|
406
|
+
declare const LANGUAGE_FAMILY_DEFAULTS: Record<string, Partial<LanguageProfile>>;
|
|
407
|
+
/**
|
|
408
|
+
* Reorder semantic roles according to target language.
|
|
409
|
+
* Includes a safety net to append any roles present in input
|
|
410
|
+
* but missing from the target order, preventing data loss.
|
|
411
|
+
*/
|
|
412
|
+
declare function reorderRoles(roles: Map<SemanticRole, ParsedElement>, targetOrder: SemanticRole[]): ParsedElement[];
|
|
413
|
+
/**
|
|
414
|
+
* Insert grammatical markers between elements
|
|
415
|
+
*/
|
|
416
|
+
declare function insertMarkers(elements: ParsedElement[], markers: GrammaticalMarker[], adpositionType: AdpositionType): string[];
|
|
417
|
+
/**
|
|
418
|
+
* Intelligently joins tokens, handling agglutinative suffixes and prefixes.
|
|
419
|
+
*
|
|
420
|
+
* Rules:
|
|
421
|
+
* 1. If a token ends with '-' (prefix marker), no space after it
|
|
422
|
+
* 2. If a token starts with '-' (suffix marker), no space before it
|
|
423
|
+
* 3. Removes the hyphen indicators from the final output
|
|
424
|
+
*
|
|
425
|
+
* Examples:
|
|
426
|
+
* - ['#count', '-ta'] → '#countta' (Quechua accusative suffix)
|
|
427
|
+
* - ['بـ-', 'الماوس'] → 'بـالماوس' (Arabic prefix attachment)
|
|
428
|
+
* - ['value', 'を'] → 'value を' (Japanese particle, normal spacing)
|
|
429
|
+
*/
|
|
430
|
+
declare function joinTokens(tokens: string[]): string;
|
|
431
|
+
/**
|
|
432
|
+
* Transform a parsed statement to target language
|
|
433
|
+
*/
|
|
434
|
+
declare function transformStatement(parsed: ParsedStatement, _sourceProfile: LanguageProfile, targetProfile: LanguageProfile): string;
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Shared Constants for i18n Package
|
|
438
|
+
*
|
|
439
|
+
* Centralizes keyword definitions to eliminate duplication across
|
|
440
|
+
* transformer.ts, create-provider.ts, and other modules.
|
|
441
|
+
*/
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* English commands - the canonical set that the runtime understands.
|
|
445
|
+
*/
|
|
446
|
+
declare const ENGLISH_COMMANDS: Set<string>;
|
|
447
|
+
/**
|
|
448
|
+
* English keywords that are not commands.
|
|
449
|
+
*/
|
|
450
|
+
declare const ENGLISH_KEYWORDS: Set<string>;
|
|
451
|
+
/**
|
|
452
|
+
* English keywords that should always be recognized, even in non-English locales.
|
|
453
|
+
* These are HTML/DOM standard terms that developers worldwide use.
|
|
454
|
+
*/
|
|
455
|
+
declare const UNIVERSAL_ENGLISH_KEYWORDS: Set<string>;
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* Creates a KeywordProvider from a dictionary.
|
|
459
|
+
*
|
|
460
|
+
* The provider creates reverse mappings (locale → English) for fast
|
|
461
|
+
* resolution during parsing.
|
|
462
|
+
*
|
|
463
|
+
* @example
|
|
464
|
+
* ```typescript
|
|
465
|
+
* import { es } from '../dictionaries/es';
|
|
466
|
+
* export const esKeywords = createKeywordProvider(es, 'es');
|
|
467
|
+
* ```
|
|
468
|
+
*/
|
|
469
|
+
declare function createKeywordProvider(dictionary: Dictionary, locale: string, options?: KeywordProviderOptions): KeywordProvider;
|
|
470
|
+
/**
|
|
471
|
+
* Creates a default English-only keyword provider.
|
|
472
|
+
* This is used when no locale is specified.
|
|
473
|
+
*/
|
|
474
|
+
declare function createEnglishProvider(): KeywordProvider;
|
|
475
|
+
|
|
476
|
+
declare const es: Dictionary;
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* Spanish keyword provider for the hyperscript parser.
|
|
480
|
+
*
|
|
481
|
+
* Enables parsing hyperscript written in Spanish:
|
|
482
|
+
* - `en clic alternar .active` → parses as `on click toggle .active`
|
|
483
|
+
* - `si verdadero entonces registrar "hola"` → parses as `if true then log "hello"`
|
|
484
|
+
*
|
|
485
|
+
* English keywords are also accepted (mixed mode), so:
|
|
486
|
+
* - `en click alternar .active` also works (Spanish `en` + English `click`)
|
|
487
|
+
*
|
|
488
|
+
* @example
|
|
489
|
+
* ```typescript
|
|
490
|
+
* import { esKeywords } from '@lokascript/i18n/parser/es';
|
|
491
|
+
* import { Parser } from '@lokascript/core';
|
|
492
|
+
*
|
|
493
|
+
* const parser = new Parser({ keywords: esKeywords });
|
|
494
|
+
* parser.parse('en clic alternar .active');
|
|
495
|
+
* ```
|
|
496
|
+
*/
|
|
497
|
+
declare const esKeywords: KeywordProvider;
|
|
498
|
+
|
|
499
|
+
declare const ja: Dictionary;
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Japanese keyword provider for the hyperscript parser.
|
|
503
|
+
*
|
|
504
|
+
* Enables parsing hyperscript written in Japanese:
|
|
505
|
+
* - `クリック で 切り替え .active` → parses as `on click toggle .active`
|
|
506
|
+
* - `もし 真 それから 記録 "こんにちは"` → parses as `if true then log "hello"`
|
|
507
|
+
*
|
|
508
|
+
* English keywords are also accepted (mixed mode), so:
|
|
509
|
+
* - `click で 切り替え .active` also works (English `click` + Japanese `で`, `切り替え`)
|
|
510
|
+
*
|
|
511
|
+
* Japanese is a useful test case because:
|
|
512
|
+
* - SOV word order (subject-object-verb) vs English SVO
|
|
513
|
+
* - No articles (a, an, the)
|
|
514
|
+
* - Unicode characters (tests tokenizer robustness)
|
|
515
|
+
*
|
|
516
|
+
* @example
|
|
517
|
+
* ```typescript
|
|
518
|
+
* import { jaKeywords } from '@lokascript/i18n/parser/ja';
|
|
519
|
+
* import { Parser } from '@lokascript/core';
|
|
520
|
+
*
|
|
521
|
+
* const parser = new Parser({ keywords: jaKeywords });
|
|
522
|
+
* parser.parse('クリック で 切り替え .active');
|
|
523
|
+
* ```
|
|
524
|
+
*/
|
|
525
|
+
declare const jaKeywords: KeywordProvider;
|
|
526
|
+
|
|
527
|
+
declare const fr: Dictionary;
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* French keyword provider for the hyperscript parser.
|
|
531
|
+
*
|
|
532
|
+
* Enables parsing hyperscript written in French:
|
|
533
|
+
* - `sur clic basculer .active` → parses as `on click toggle .active`
|
|
534
|
+
* - `si vrai alors enregistrer "bonjour"` → parses as `if true then log "hello"`
|
|
535
|
+
*
|
|
536
|
+
* English keywords are also accepted (mixed mode), so:
|
|
537
|
+
* - `sur click basculer .active` also works (French `sur` + English `click`)
|
|
538
|
+
*
|
|
539
|
+
* @example
|
|
540
|
+
* ```typescript
|
|
541
|
+
* import { frKeywords } from '@lokascript/i18n/parser/fr';
|
|
542
|
+
* import { Parser } from '@lokascript/core';
|
|
543
|
+
*
|
|
544
|
+
* const parser = new Parser({ keywords: frKeywords });
|
|
545
|
+
* parser.parse('sur clic basculer .active');
|
|
546
|
+
* ```
|
|
547
|
+
*/
|
|
548
|
+
declare const frKeywords: KeywordProvider;
|
|
549
|
+
|
|
550
|
+
declare const de: Dictionary;
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* German keyword provider for the hyperscript parser.
|
|
554
|
+
*
|
|
555
|
+
* Enables parsing hyperscript written in German:
|
|
556
|
+
* - `bei klick umschalten .active` → parses as `on click toggle .active`
|
|
557
|
+
* - `wenn wahr dann protokollieren "hallo"` → parses as `if true then log "hello"`
|
|
558
|
+
*
|
|
559
|
+
* English keywords are also accepted (mixed mode), so:
|
|
560
|
+
* - `bei click umschalten .active` also works (German `bei` + English `click`)
|
|
561
|
+
*
|
|
562
|
+
* German is a useful test case because:
|
|
563
|
+
* - Compound words (Zusammensetzungen) are common
|
|
564
|
+
* - Different word order in clauses (V2 in main, V-final in subordinate)
|
|
565
|
+
* - Case system (nominative, accusative, dative, genitive)
|
|
566
|
+
*
|
|
567
|
+
* @example
|
|
568
|
+
* ```typescript
|
|
569
|
+
* import { deKeywords } from '@lokascript/i18n/parser/de';
|
|
570
|
+
* import { Parser } from '@lokascript/core';
|
|
571
|
+
*
|
|
572
|
+
* const parser = new Parser({ keywords: deKeywords });
|
|
573
|
+
* parser.parse('bei klick umschalten .active');
|
|
574
|
+
* ```
|
|
575
|
+
*/
|
|
576
|
+
declare const deKeywords: KeywordProvider;
|
|
577
|
+
|
|
578
|
+
declare const ar: Dictionary;
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* Arabic keyword provider for the hyperscript parser.
|
|
582
|
+
*
|
|
583
|
+
* Enables parsing hyperscript written in Arabic:
|
|
584
|
+
* - `على نقر بدل .active` → parses as `on click toggle .active`
|
|
585
|
+
* - `إذا صحيح ثم سجل "مرحبا"` → parses as `if true then log "hello"`
|
|
586
|
+
*
|
|
587
|
+
* English keywords are also accepted (mixed mode), so:
|
|
588
|
+
* - `على click بدل .active` also works (Arabic `على` + English `click`)
|
|
589
|
+
*
|
|
590
|
+
* Arabic is a crucial test case because:
|
|
591
|
+
* - Right-to-left (RTL) script
|
|
592
|
+
* - Different character set (Unicode Arabic block)
|
|
593
|
+
* - Space-separated words with diacritics
|
|
594
|
+
* - Tests parser's Unicode handling robustly
|
|
595
|
+
*
|
|
596
|
+
* Note: The parser handles RTL text correctly because tokenization
|
|
597
|
+
* is based on whitespace/operator boundaries, not visual direction.
|
|
598
|
+
*
|
|
599
|
+
* @example
|
|
600
|
+
* ```typescript
|
|
601
|
+
* import { arKeywords } from '@lokascript/i18n/parser/ar';
|
|
602
|
+
* import { Parser } from '@lokascript/core';
|
|
603
|
+
*
|
|
604
|
+
* const parser = new Parser({ keywords: arKeywords });
|
|
605
|
+
* parser.parse('على نقر بدل .active');
|
|
606
|
+
* ```
|
|
607
|
+
*/
|
|
608
|
+
declare const arKeywords: KeywordProvider;
|
|
609
|
+
|
|
610
|
+
declare const ko: Dictionary;
|
|
611
|
+
|
|
612
|
+
/**
|
|
613
|
+
* Korean keyword provider for the hyperscript parser.
|
|
614
|
+
*
|
|
615
|
+
* Enables parsing hyperscript written in Korean:
|
|
616
|
+
* - `에 클릭 토글 .active` → parses as `on click toggle .active`
|
|
617
|
+
* - `만약 참 그러면 로그 "안녕하세요"` → parses as `if true then log "hello"`
|
|
618
|
+
*
|
|
619
|
+
* English keywords are also accepted (mixed mode), so:
|
|
620
|
+
* - `에 click 토글 .active` also works (Korean `에` + English `click`)
|
|
621
|
+
*
|
|
622
|
+
* Korean is a useful test case because:
|
|
623
|
+
* - SOV word order (Subject-Object-Verb)
|
|
624
|
+
* - Hangul script (syllabic blocks)
|
|
625
|
+
* - Agglutinative morphology with particles
|
|
626
|
+
* - Tests parser's Unicode handling with Korean characters
|
|
627
|
+
*
|
|
628
|
+
* @example
|
|
629
|
+
* ```typescript
|
|
630
|
+
* import { koKeywords } from '@lokascript/i18n/parser/ko';
|
|
631
|
+
* import { Parser } from '@lokascript/core';
|
|
632
|
+
*
|
|
633
|
+
* const parser = new Parser({ keywords: koKeywords });
|
|
634
|
+
* parser.parse('에 클릭 토글 .active');
|
|
635
|
+
* ```
|
|
636
|
+
*/
|
|
637
|
+
declare const koKeywords: KeywordProvider;
|
|
638
|
+
|
|
639
|
+
declare const zh: Dictionary;
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* Chinese (Simplified) keyword provider for the hyperscript parser.
|
|
643
|
+
*
|
|
644
|
+
* Enables parsing hyperscript written in Chinese:
|
|
645
|
+
* - `当 点击 切换 .active` → parses as `on click toggle .active`
|
|
646
|
+
* - `如果 真 那么 日志 "你好"` → parses as `if true then log "hello"`
|
|
647
|
+
*
|
|
648
|
+
* English keywords are also accepted (mixed mode), so:
|
|
649
|
+
* - `当 click 切换 .active` also works (Chinese `当` + English `click`)
|
|
650
|
+
*
|
|
651
|
+
* Chinese is a useful test case because:
|
|
652
|
+
* - SVO word order (similar to English)
|
|
653
|
+
* - Logographic script (Chinese characters)
|
|
654
|
+
* - Isolating morphology (minimal inflection)
|
|
655
|
+
* - Tests parser's Unicode handling with CJK characters
|
|
656
|
+
* - Large developer population
|
|
657
|
+
*
|
|
658
|
+
* @example
|
|
659
|
+
* ```typescript
|
|
660
|
+
* import { zhKeywords } from '@lokascript/i18n/parser/zh';
|
|
661
|
+
* import { Parser } from '@lokascript/core';
|
|
662
|
+
*
|
|
663
|
+
* const parser = new Parser({ keywords: zhKeywords });
|
|
664
|
+
* parser.parse('当 点击 切换 .active');
|
|
665
|
+
* ```
|
|
666
|
+
*/
|
|
667
|
+
declare const zhKeywords: KeywordProvider;
|
|
668
|
+
|
|
669
|
+
declare const tr: Dictionary;
|
|
670
|
+
|
|
671
|
+
/**
|
|
672
|
+
* Turkish keyword provider for the hyperscript parser.
|
|
673
|
+
*
|
|
674
|
+
* Enables parsing hyperscript written in Turkish:
|
|
675
|
+
* - `üzerinde tıklama değiştir .active` → parses as `on click toggle .active`
|
|
676
|
+
* - `eğer doğru ise kaydet "merhaba"` → parses as `if true then log "hello"`
|
|
677
|
+
*
|
|
678
|
+
* English keywords are also accepted (mixed mode), so:
|
|
679
|
+
* - `üzerinde click değiştir .active` also works (Turkish `üzerinde` + English `click`)
|
|
680
|
+
*
|
|
681
|
+
* Turkish is a useful test case because:
|
|
682
|
+
* - SOV word order (Subject-Object-Verb)
|
|
683
|
+
* - Agglutinative morphology with suffixes
|
|
684
|
+
* - Vowel harmony rules
|
|
685
|
+
* - Latin script with special characters (ı, ğ, ş, ç, ö, ü)
|
|
686
|
+
* - Tests parser's handling of extended Latin characters
|
|
687
|
+
*
|
|
688
|
+
* @example
|
|
689
|
+
* ```typescript
|
|
690
|
+
* import { trKeywords } from '@lokascript/i18n/parser/tr';
|
|
691
|
+
* import { Parser } from '@lokascript/core';
|
|
692
|
+
*
|
|
693
|
+
* const parser = new Parser({ keywords: trKeywords });
|
|
694
|
+
* parser.parse('üzerinde tıklama değiştir .active');
|
|
695
|
+
* ```
|
|
696
|
+
*/
|
|
697
|
+
declare const trKeywords: KeywordProvider;
|
|
698
|
+
|
|
699
|
+
declare const id: Dictionary;
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* Indonesian (Bahasa Indonesia) keyword provider for the hyperscript parser.
|
|
703
|
+
*
|
|
704
|
+
* Enables parsing hyperscript written in Indonesian:
|
|
705
|
+
* - `pada klik ganti .active` → parses as `on click toggle .active`
|
|
706
|
+
* - `jika benar lalu log "Halo"` → parses as `if true then log "Hello"`
|
|
707
|
+
*
|
|
708
|
+
* Indonesian is an SVO language with:
|
|
709
|
+
* - Agglutinative morphology (prefixes/suffixes)
|
|
710
|
+
* - No grammatical gender
|
|
711
|
+
* - Prepositions (like English)
|
|
712
|
+
* - Relatively simple syntax
|
|
713
|
+
*
|
|
714
|
+
* @example
|
|
715
|
+
* ```typescript
|
|
716
|
+
* import { idKeywords } from '@lokascript/i18n/parser/id';
|
|
717
|
+
* import { Parser } from '@lokascript/core';
|
|
718
|
+
*
|
|
719
|
+
* const parser = new Parser({ keywords: idKeywords });
|
|
720
|
+
* parser.parse('pada klik ganti .active');
|
|
721
|
+
* ```
|
|
722
|
+
*/
|
|
723
|
+
declare const idKeywords: KeywordProvider;
|
|
724
|
+
|
|
725
|
+
declare const qu: Dictionary;
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* Quechua (Runasimi) keyword provider for the hyperscript parser.
|
|
729
|
+
*
|
|
730
|
+
* Enables parsing hyperscript written in Quechua:
|
|
731
|
+
* - `ñitiy-pi yapay #count-ta` → parses as `on click increment #count`
|
|
732
|
+
*
|
|
733
|
+
* Quechua is an SOV language with:
|
|
734
|
+
* - Agglutinative/polysynthetic morphology
|
|
735
|
+
* - Extensive suffix system (case markers: -ta, -man, -pi, -manta, -wan)
|
|
736
|
+
* - Postpositions (unlike Spanish which uses prepositions)
|
|
737
|
+
* - Object-Verb word order
|
|
738
|
+
* - Evidentiality markers (not used in hyperscript)
|
|
739
|
+
*
|
|
740
|
+
* The grammar transformer handles suffix joining via hyphen notation
|
|
741
|
+
* (e.g., "#count-ta" attaches the accusative marker).
|
|
742
|
+
*
|
|
743
|
+
* @example
|
|
744
|
+
* ```typescript
|
|
745
|
+
* import { quKeywords } from '@lokascript/i18n/parser/qu';
|
|
746
|
+
* import { Parser } from '@lokascript/core';
|
|
747
|
+
*
|
|
748
|
+
* const parser = new Parser({ keywords: quKeywords });
|
|
749
|
+
* parser.parse('ñitiy-pi yapay #count-ta');
|
|
750
|
+
* ```
|
|
751
|
+
*/
|
|
752
|
+
declare const quKeywords: KeywordProvider;
|
|
753
|
+
|
|
754
|
+
declare const sw: Dictionary;
|
|
755
|
+
|
|
756
|
+
/**
|
|
757
|
+
* Swahili (Kiswahili) keyword provider for the hyperscript parser.
|
|
758
|
+
*
|
|
759
|
+
* Enables parsing hyperscript written in Swahili:
|
|
760
|
+
* - `kwenye bonyeza badilisha .active` → parses as `on click toggle .active`
|
|
761
|
+
* - `kama kweli basi andika "Habari"` → parses as `if true then log "Hello"`
|
|
762
|
+
*
|
|
763
|
+
* Swahili is an SVO Bantu language with:
|
|
764
|
+
* - Agglutinative verb morphology
|
|
765
|
+
* - Noun class system (simplified for hyperscript keywords)
|
|
766
|
+
* - Prepositions (unlike many other African languages)
|
|
767
|
+
* - Subject-verb agreement (not relevant for hyperscript)
|
|
768
|
+
*
|
|
769
|
+
* Swahili is widely spoken in East Africa and serves as a lingua franca
|
|
770
|
+
* for millions of speakers.
|
|
771
|
+
*
|
|
772
|
+
* @example
|
|
773
|
+
* ```typescript
|
|
774
|
+
* import { swKeywords } from '@lokascript/i18n/parser/sw';
|
|
775
|
+
* import { Parser } from '@lokascript/core';
|
|
776
|
+
*
|
|
777
|
+
* const parser = new Parser({ keywords: swKeywords });
|
|
778
|
+
* parser.parse('kwenye bonyeza badilisha .active');
|
|
779
|
+
* ```
|
|
780
|
+
*/
|
|
781
|
+
declare const swKeywords: KeywordProvider;
|
|
782
|
+
|
|
783
|
+
/**
|
|
784
|
+
* Portuguese (Português) dictionary for hyperscript keywords.
|
|
785
|
+
* Brazilian Portuguese variant.
|
|
786
|
+
*/
|
|
787
|
+
declare const pt: Dictionary;
|
|
788
|
+
|
|
789
|
+
/**
|
|
790
|
+
* Portuguese (Português) keyword provider for the hyperscript parser.
|
|
791
|
+
*
|
|
792
|
+
* Enables parsing hyperscript written in Portuguese:
|
|
793
|
+
* - `em clique alternar .active` → parses as `on click toggle .active`
|
|
794
|
+
* - `se verdadeiro então registrar "Olá"` → parses as `if true then log "Hello"`
|
|
795
|
+
*
|
|
796
|
+
* Portuguese is an SVO language with:
|
|
797
|
+
* - High mutual intelligibility with Spanish
|
|
798
|
+
* - Prepositions (like English and Spanish)
|
|
799
|
+
* - Gender agreement (simplified for hyperscript)
|
|
800
|
+
* - Fusional morphology
|
|
801
|
+
*
|
|
802
|
+
* Direct translation is supported between Portuguese and Spanish,
|
|
803
|
+
* avoiding the English pivot for more natural translations.
|
|
804
|
+
*
|
|
805
|
+
* @example
|
|
806
|
+
* ```typescript
|
|
807
|
+
* import { ptKeywords } from '@lokascript/i18n/parser/pt';
|
|
808
|
+
* import { Parser } from '@lokascript/core';
|
|
809
|
+
*
|
|
810
|
+
* const parser = new Parser({ keywords: ptKeywords });
|
|
811
|
+
* parser.parse('em clique alternar .active');
|
|
812
|
+
* ```
|
|
813
|
+
*/
|
|
814
|
+
declare const ptKeywords: KeywordProvider;
|
|
815
|
+
|
|
816
|
+
/**
|
|
817
|
+
* LocaleManager - Centralized locale configuration for hyperscript parsing.
|
|
818
|
+
*
|
|
819
|
+
* Provides utilities for:
|
|
820
|
+
* - Setting/getting the default locale
|
|
821
|
+
* - Creating locale-aware parsers
|
|
822
|
+
* - Runtime locale switching
|
|
823
|
+
*
|
|
824
|
+
* @example
|
|
825
|
+
* ```typescript
|
|
826
|
+
* import { LocaleManager } from '@lokascript/i18n/parser';
|
|
827
|
+
* import { esKeywords, frKeywords } from '@lokascript/i18n/parser';
|
|
828
|
+
*
|
|
829
|
+
* // Register available locales
|
|
830
|
+
* LocaleManager.register('es', esKeywords);
|
|
831
|
+
* LocaleManager.register('fr', frKeywords);
|
|
832
|
+
*
|
|
833
|
+
* // Set default locale
|
|
834
|
+
* LocaleManager.setDefault('es');
|
|
835
|
+
*
|
|
836
|
+
* // Get keyword provider for parsing
|
|
837
|
+
* const provider = LocaleManager.get(); // Returns esKeywords
|
|
838
|
+
* const frProvider = LocaleManager.get('fr'); // Returns frKeywords
|
|
839
|
+
*
|
|
840
|
+
* // Use with parser
|
|
841
|
+
* const parser = new Parser({ keywords: LocaleManager.get() });
|
|
842
|
+
* ```
|
|
843
|
+
*/
|
|
844
|
+
declare class LocaleManager {
|
|
845
|
+
private static providers;
|
|
846
|
+
private static defaultLocale;
|
|
847
|
+
private static englishProvider;
|
|
848
|
+
/**
|
|
849
|
+
* Register a locale provider.
|
|
850
|
+
*
|
|
851
|
+
* @param locale - The locale code (e.g., 'es', 'ja', 'fr')
|
|
852
|
+
* @param provider - The KeywordProvider for this locale
|
|
853
|
+
*/
|
|
854
|
+
static register(locale: string, provider: KeywordProvider): void;
|
|
855
|
+
/**
|
|
856
|
+
* Unregister a locale provider.
|
|
857
|
+
*
|
|
858
|
+
* @param locale - The locale code to remove
|
|
859
|
+
*/
|
|
860
|
+
static unregister(locale: string): void;
|
|
861
|
+
/**
|
|
862
|
+
* Set the default locale.
|
|
863
|
+
*
|
|
864
|
+
* @param locale - The locale code to use as default
|
|
865
|
+
* @throws Error if the locale is not registered
|
|
866
|
+
*/
|
|
867
|
+
static setDefault(locale: string): void;
|
|
868
|
+
/**
|
|
869
|
+
* Get the current default locale.
|
|
870
|
+
*
|
|
871
|
+
* @returns The default locale code
|
|
872
|
+
*/
|
|
873
|
+
static getDefault(): string;
|
|
874
|
+
/**
|
|
875
|
+
* Get a keyword provider for a locale.
|
|
876
|
+
*
|
|
877
|
+
* @param locale - The locale code (optional, defaults to the default locale)
|
|
878
|
+
* @returns The KeywordProvider for the locale
|
|
879
|
+
* @throws Error if the locale is not registered
|
|
880
|
+
*/
|
|
881
|
+
static get(locale?: string): KeywordProvider;
|
|
882
|
+
/**
|
|
883
|
+
* Check if a locale is registered.
|
|
884
|
+
*
|
|
885
|
+
* @param locale - The locale code to check
|
|
886
|
+
* @returns True if the locale is available
|
|
887
|
+
*/
|
|
888
|
+
static has(locale: string): boolean;
|
|
889
|
+
/**
|
|
890
|
+
* Get all available locale codes.
|
|
891
|
+
*
|
|
892
|
+
* @returns Array of locale codes
|
|
893
|
+
*/
|
|
894
|
+
static getAvailable(): string[];
|
|
895
|
+
/**
|
|
896
|
+
* Reset the LocaleManager to its initial state.
|
|
897
|
+
* Useful for testing.
|
|
898
|
+
*/
|
|
899
|
+
static reset(): void;
|
|
900
|
+
/**
|
|
901
|
+
* Register all built-in locales at once.
|
|
902
|
+
*
|
|
903
|
+
* @example
|
|
904
|
+
* ```typescript
|
|
905
|
+
* import { LocaleManager } from '@lokascript/i18n/parser';
|
|
906
|
+
* import { esKeywords, jaKeywords, frKeywords, deKeywords, arKeywords } from '@lokascript/i18n/parser';
|
|
907
|
+
*
|
|
908
|
+
* LocaleManager.registerAll({
|
|
909
|
+
* es: esKeywords,
|
|
910
|
+
* ja: jaKeywords,
|
|
911
|
+
* fr: frKeywords,
|
|
912
|
+
* de: deKeywords,
|
|
913
|
+
* ar: arKeywords,
|
|
914
|
+
* });
|
|
915
|
+
* ```
|
|
916
|
+
*/
|
|
917
|
+
static registerAll(providers: Record<string, KeywordProvider>): void;
|
|
918
|
+
}
|
|
919
|
+
/**
|
|
920
|
+
* Quick utility to detect the browser's preferred locale and return
|
|
921
|
+
* a matching provider, falling back to English.
|
|
922
|
+
*
|
|
923
|
+
* @returns The KeywordProvider for the browser's locale or English
|
|
924
|
+
*
|
|
925
|
+
* @example
|
|
926
|
+
* ```typescript
|
|
927
|
+
* import { detectBrowserLocale } from '@lokascript/i18n/parser';
|
|
928
|
+
* import { Parser } from '@lokascript/core';
|
|
929
|
+
*
|
|
930
|
+
* // Auto-detect and use browser locale
|
|
931
|
+
* const parser = new Parser({ keywords: detectBrowserLocale() });
|
|
932
|
+
* ```
|
|
933
|
+
*/
|
|
934
|
+
declare function detectBrowserLocale(): KeywordProvider;
|
|
935
|
+
|
|
936
|
+
/**
|
|
937
|
+
* Language Profiles Index
|
|
938
|
+
*
|
|
939
|
+
* Concrete implementations of LanguageProfile for supported languages.
|
|
940
|
+
* Each profile inherits from a language family default and adds
|
|
941
|
+
* language-specific markers and rules.
|
|
942
|
+
*/
|
|
943
|
+
|
|
944
|
+
declare const englishProfile: LanguageProfile;
|
|
945
|
+
declare const japaneseProfile: LanguageProfile;
|
|
946
|
+
declare const koreanProfile: LanguageProfile;
|
|
947
|
+
declare const chineseProfile: LanguageProfile;
|
|
948
|
+
declare const arabicProfile: LanguageProfile;
|
|
949
|
+
declare const turkishProfile: LanguageProfile;
|
|
950
|
+
declare const spanishProfile: LanguageProfile;
|
|
951
|
+
declare const germanProfile: LanguageProfile;
|
|
952
|
+
declare const frenchProfile: LanguageProfile;
|
|
953
|
+
declare const portugueseProfile: LanguageProfile;
|
|
954
|
+
declare const indonesianProfile: LanguageProfile;
|
|
955
|
+
declare const quechuaProfile: LanguageProfile;
|
|
956
|
+
declare const swahiliProfile: LanguageProfile;
|
|
957
|
+
declare const profiles: Record<string, LanguageProfile>;
|
|
958
|
+
declare function getProfile(locale: string): LanguageProfile | undefined;
|
|
959
|
+
declare function getSupportedLocales(): string[];
|
|
960
|
+
|
|
961
|
+
/**
|
|
962
|
+
* Grammar-Aware Transformer
|
|
963
|
+
*
|
|
964
|
+
* Transforms hyperscript statements between languages using the
|
|
965
|
+
* generalized grammar system. The key insight is that semantic
|
|
966
|
+
* roles are universal - only their surface realization differs.
|
|
967
|
+
*/
|
|
968
|
+
|
|
969
|
+
/**
|
|
970
|
+
* Parse a hyperscript statement into semantic roles
|
|
971
|
+
* This is the core analysis step that identifies WHAT each part means
|
|
972
|
+
*/
|
|
973
|
+
declare function parseStatement(input: string, sourceLocale?: string): ParsedStatement | null;
|
|
974
|
+
declare class GrammarTransformer {
|
|
975
|
+
private sourceProfile;
|
|
976
|
+
private targetProfile;
|
|
977
|
+
constructor(sourceLocale: string | undefined, targetLocale: string);
|
|
978
|
+
/**
|
|
979
|
+
* Transform a hyperscript statement from source to target language.
|
|
980
|
+
* Handles compound statements with "then" by splitting, transforming each part,
|
|
981
|
+
* and rejoining with the target language's "then" keyword.
|
|
982
|
+
*
|
|
983
|
+
* For multi-line input, preserves line structure (indentation, blank lines).
|
|
984
|
+
*/
|
|
985
|
+
transform(input: string): string;
|
|
986
|
+
/**
|
|
987
|
+
* Transform a single hyperscript statement (no compound "then" chains).
|
|
988
|
+
*/
|
|
989
|
+
private transformSingle;
|
|
990
|
+
/**
|
|
991
|
+
* Find the best matching rule for this statement
|
|
992
|
+
*/
|
|
993
|
+
private findRule;
|
|
994
|
+
/**
|
|
995
|
+
* Check if a parsed statement matches a rule
|
|
996
|
+
*/
|
|
997
|
+
private matchesRule;
|
|
998
|
+
}
|
|
999
|
+
/**
|
|
1000
|
+
* Transform hyperscript from English to target language
|
|
1001
|
+
*/
|
|
1002
|
+
declare function toLocale(input: string, targetLocale: string): string;
|
|
1003
|
+
/**
|
|
1004
|
+
* Transform hyperscript from source language to English
|
|
1005
|
+
*/
|
|
1006
|
+
declare function toEnglish(input: string, sourceLocale: string): string;
|
|
1007
|
+
/**
|
|
1008
|
+
* Transform between any two languages.
|
|
1009
|
+
*
|
|
1010
|
+
* Uses direct translation for supported language pairs (ja↔zh, es↔pt, ko↔ja),
|
|
1011
|
+
* falling back to English pivot for other pairs.
|
|
1012
|
+
*/
|
|
1013
|
+
declare function translate(input: string, sourceLocale: string, targetLocale: string): string;
|
|
1014
|
+
declare const examples: {
|
|
1015
|
+
english: {
|
|
1016
|
+
eventHandler: string;
|
|
1017
|
+
putInto: string;
|
|
1018
|
+
toggle: string;
|
|
1019
|
+
wait: string;
|
|
1020
|
+
};
|
|
1021
|
+
japanese: {
|
|
1022
|
+
eventHandler: string;
|
|
1023
|
+
putInto: string;
|
|
1024
|
+
toggle: string;
|
|
1025
|
+
wait: string;
|
|
1026
|
+
};
|
|
1027
|
+
chinese: {
|
|
1028
|
+
eventHandler: string;
|
|
1029
|
+
putInto: string;
|
|
1030
|
+
toggle: string;
|
|
1031
|
+
wait: string;
|
|
1032
|
+
};
|
|
1033
|
+
arabic: {
|
|
1034
|
+
eventHandler: string;
|
|
1035
|
+
putInto: string;
|
|
1036
|
+
toggle: string;
|
|
1037
|
+
wait: string;
|
|
1038
|
+
};
|
|
1039
|
+
};
|
|
1040
|
+
|
|
1041
|
+
export { englishProfile as $, ptKeywords as A, pt as B, detectBrowserLocale as C, type AdpositionType as D, ENGLISH_COMMANDS as E, type LanguageProfile as F, type GrammaticalMarker as G, type GrammarRule as H, type PatternTransform as I, type ParsedStatement as J, type KeywordProvider as K, LocaleManager as L, type MorphologyType as M, type ParsedElement as N, UNIVERSAL_PATTERNS as O, type PatternMatcher as P, LANGUAGE_FAMILY_DEFAULTS as Q, reorderRoles as R, type SemanticRole as S, insertMarkers as T, UNIVERSAL_ENGLISH_KEYWORDS as U, joinTokens as V, type WordOrder as W, transformStatement as X, profiles as Y, getProfile as Z, getSupportedLocales as _, type KeywordProviderOptions as a, japaneseProfile as a0, koreanProfile as a1, chineseProfile as a2, arabicProfile as a3, turkishProfile as a4, spanishProfile as a5, germanProfile as a6, frenchProfile as a7, portugueseProfile as a8, indonesianProfile as a9, quechuaProfile as aa, swahiliProfile as ab, GrammarTransformer as ac, parseStatement as ad, toLocale as ae, toEnglish as af, translate as ag, examples as ah, type I18nConfig as ai, type TranslationOptions as aj, type TranslationResult as ak, type Dictionary as al, type ValidationResult as am, type Token as an, type DictionaryCategory as ao, type ValidationError as ap, type ValidationWarning as aq, type LocaleMetadata as ar, type TranslationContext as as, type TokenType as at, DICTIONARY_CATEGORIES as au, isDictionaryCategory as av, getDictionaryCategory as aw, forEachCategory as ax, findInDictionary as ay, translateFromEnglish as az, createEnglishProvider as b, createKeywordProvider as c, ENGLISH_KEYWORDS as d, esKeywords as e, es as f, ja as g, frKeywords as h, fr as i, jaKeywords as j, deKeywords as k, de as l, arKeywords as m, ar as n, koKeywords as o, ko as p, zh as q, tr as r, idKeywords as s, trKeywords as t, id as u, quKeywords as v, qu as w, swKeywords as x, sw as y, zhKeywords as z };
|