@lokascript/i18n 2.11.1 → 3.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/CHANGELOG.md +13 -0
- package/dist/browser.cjs +5 -1690
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +2 -2
- package/dist/browser.d.ts +2 -2
- package/dist/browser.js +6 -1685
- package/dist/browser.js.map +1 -1
- package/dist/dictionaries/index.cjs +5 -1
- package/dist/dictionaries/index.cjs.map +1 -1
- package/dist/dictionaries/index.js +5 -1
- package/dist/dictionaries/index.js.map +1 -1
- package/dist/{transformer-CsOeqayN.d.cts → index-BykxjYST.d.cts} +1 -232
- package/dist/{transformer-DWCTG1DQ.d.ts → index-DuIef8O7.d.ts} +1 -232
- package/dist/index.cjs +16 -1878
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +35 -35
- package/dist/index.d.ts +35 -35
- package/dist/index.js +17 -1873
- package/dist/index.js.map +1 -1
- package/dist/lokascript-i18n.min.js +1 -1
- package/dist/lokascript-i18n.min.js.map +1 -1
- package/dist/lokascript-i18n.mjs +49 -2680
- package/dist/lokascript-i18n.mjs.map +1 -1
- package/dist/plugins/vite.cjs +5 -1
- package/dist/plugins/vite.cjs.map +1 -1
- package/dist/plugins/vite.js +5 -1
- package/dist/plugins/vite.js.map +1 -1
- package/dist/plugins/webpack.cjs +5 -1
- package/dist/plugins/webpack.cjs.map +1 -1
- package/dist/plugins/webpack.js +5 -1
- package/dist/plugins/webpack.js.map +1 -1
- package/package.json +4 -4
- package/src/browser.ts +0 -7
- package/src/compatibility/browser-tests/grammar-demo.spec.ts +22 -8
- package/src/constants.ts +1 -0
- package/src/dictionaries/bn.ts +5 -1
- package/src/grammar/index.ts +15 -9
- package/src/grammar/profiles.test.ts +440 -0
- package/src/index.ts +0 -7
- package/src/lexicon-parity.test.ts +77 -0
- package/src/grammar/grammar.test.ts +0 -2751
- package/src/grammar/transformer.ts +0 -2737
|
@@ -877,235 +877,4 @@ declare const profiles: Record<string, LanguageProfile>;
|
|
|
877
877
|
declare function getProfile(locale: string): LanguageProfile | undefined;
|
|
878
878
|
declare function getSupportedLocales(): string[];
|
|
879
879
|
|
|
880
|
-
|
|
881
|
-
* Grammar-Aware Transformer
|
|
882
|
-
*
|
|
883
|
-
* Transforms hyperscript statements between languages using the
|
|
884
|
-
* generalized grammar system. The key insight is that semantic
|
|
885
|
-
* roles are universal - only their surface realization differs.
|
|
886
|
-
*/
|
|
887
|
-
|
|
888
|
-
/**
|
|
889
|
-
* Parse a hyperscript statement into semantic roles
|
|
890
|
-
* This is the core analysis step that identifies WHAT each part means
|
|
891
|
-
*/
|
|
892
|
-
declare function parseStatement(input: string, sourceLocale?: string): ParsedStatement | null;
|
|
893
|
-
declare class GrammarTransformer {
|
|
894
|
-
private sourceProfile;
|
|
895
|
-
private targetProfile;
|
|
896
|
-
constructor(sourceLocale: string | undefined, targetLocale: string);
|
|
897
|
-
/**
|
|
898
|
-
* Transform a hyperscript statement from source to target language.
|
|
899
|
-
* Handles compound statements with "then" by splitting, transforming each part,
|
|
900
|
-
* and rejoining with the target language's "then" keyword.
|
|
901
|
-
*
|
|
902
|
-
* For multi-line input, preserves line structure (indentation, blank lines).
|
|
903
|
-
*/
|
|
904
|
-
transform(input: string): string;
|
|
905
|
-
private transformInternal;
|
|
906
|
-
/**
|
|
907
|
-
* Transform a single hyperscript statement (no compound "then" chains).
|
|
908
|
-
*/
|
|
909
|
-
private transformSingle;
|
|
910
|
-
/**
|
|
911
|
-
* Clause carrying a masked `using view transition` tail: strip the opaque
|
|
912
|
-
* token, transform the clause alone, and re-append the token at the very end.
|
|
913
|
-
*
|
|
914
|
-
* The tail is a clause-final modifier in every word order the corpus emits:
|
|
915
|
-
* the semantic side matches it as the literal `using view` marker plus a value
|
|
916
|
-
* word, and the SOV/VSO event-handler patterns admit it as an optional
|
|
917
|
-
* TRAILING group (after the with-marked operand). So the target position is
|
|
918
|
-
* "end of the transformed clause" for all 24 languages — no per-profile
|
|
919
|
-
* placement decision, which is what makes this a passthrough rather than a
|
|
920
|
-
* role.
|
|
921
|
-
*
|
|
922
|
-
* Returns null when the clause carries no masked tail, or when the token is
|
|
923
|
-
* not clause-final (nothing to reposition — leaving it in place still restores
|
|
924
|
-
* verbatim English).
|
|
925
|
-
*/
|
|
926
|
-
private transformWithViewTransitionTail;
|
|
927
|
-
/**
|
|
928
|
-
* `<command …> end` fragments: transform the command without its stranded
|
|
929
|
-
* terminator, then re-append the translated terminator as a standalone
|
|
930
|
-
* trailing token. Fragments that open a block of their own (`if … end`,
|
|
931
|
-
* `repeat … end`, `js … end`) bail — their terminator belongs to them and
|
|
932
|
-
* their dedicated paths handle it.
|
|
933
|
-
*/
|
|
934
|
-
private transformWithTrailingEnd;
|
|
935
|
-
/**
|
|
936
|
-
* Detect and transform an inline JS block (`[on <event>] js <raw js> end`).
|
|
937
|
-
*
|
|
938
|
-
* The `js ... end` body is raw JavaScript: it must not be tokenized,
|
|
939
|
-
* translated, or word-order reordered. We mask the whole block with a single
|
|
940
|
-
* opaque placeholder, run the surrounding statement (the event-handler head,
|
|
941
|
-
* if any) through the normal reorder pipeline so the placeholder lands in the
|
|
942
|
-
* correct action position, then substitute the translated `js`/`end` keywords
|
|
943
|
-
* around the verbatim body.
|
|
944
|
-
*
|
|
945
|
-
* Returns `null` (fall through to the normal path) when there is no js block,
|
|
946
|
-
* no matching `end`, or trailing content after `end` (kept tight on purpose).
|
|
947
|
-
*/
|
|
948
|
-
private tryTransformJsBlock;
|
|
949
|
-
/**
|
|
950
|
-
* Transform an event handler whose body is a block command
|
|
951
|
-
* (`on <event> [from <src>] {if|repeat|unless|while|for} … end`).
|
|
952
|
-
*
|
|
953
|
-
* `parseEventHandler` would treat the block keyword as the action and sweep the
|
|
954
|
-
* condition/body into role values, then reorder them — shredding the block
|
|
955
|
-
* (`if event.shiftKey call submitAndContinue() end` → scattered tokens). Instead
|
|
956
|
-
* we mask the whole block as an opaque action placeholder, reorder the event
|
|
957
|
-
* head normally, transform the block as a self-contained unit, and restitch.
|
|
958
|
-
*
|
|
959
|
-
* Returns `null` (fall through) when the input isn't an event handler, has no
|
|
960
|
-
* block-keyword body, or has no closing `end`.
|
|
961
|
-
*/
|
|
962
|
-
private tryTransformEventWithBlockBody;
|
|
963
|
-
/**
|
|
964
|
-
* Transform an event handler whose body is an inline `unless` guard with NO
|
|
965
|
-
* `end` (`on <event> unless <cond> <body>` — the `unless-condition` shape).
|
|
966
|
-
*
|
|
967
|
-
* Object-marking SVO targets (he, zh). `parseEventHandler` reads `unless` as the
|
|
968
|
-
* action and sweeps the whole `<cond> <body>` tail into a single `patient` blob;
|
|
969
|
-
* the target then prefixes that blob with its object marker — Hebrew's accusative
|
|
970
|
-
* את (`… אלא את I match .disabled מתג .selected`) or Chinese's BA particle 把
|
|
971
|
-
* (`… 除非 把 I match .disabled 切换 .selected`) — and the inner toggle loses its
|
|
972
|
-
* own marker. The semantic parser can't recover the guard from that: the marker
|
|
973
|
-
* ahead of the condition blocks the `unless` pattern AND the now-markerless body
|
|
974
|
-
* command fails its object-marked toggle pattern, so the body collapses (`unless`
|
|
975
|
-
* dropped). Marker-less languages (de/it/ar/pl) tolerate the same role-blob and
|
|
976
|
-
* stay faithful, so this is an object-marker artifact, not a general parse gap.
|
|
977
|
-
*
|
|
978
|
-
* The standalone `unless <cond> <body>` path already produces the correct shape
|
|
979
|
-
* (`extractBlockStructure` → `transformBlock`: condition kept marker-free, body
|
|
980
|
-
* command keeps its marker — he `אלא I match .disabled מתג את .selected`, zh
|
|
981
|
-
* `除非 I match .disabled 切换 把 .selected`). So we split the event head off,
|
|
982
|
-
* transform the guard through that path, and emit the event clause first (he and
|
|
983
|
-
* zh are both SVO — event leads). Returns `null` (fall through) when the input
|
|
984
|
-
* isn't an object-marking event handler with an un-terminated inline `unless`
|
|
985
|
-
* guard.
|
|
986
|
-
*/
|
|
987
|
-
private tryTransformEventWithUnlessGuard;
|
|
988
|
-
/**
|
|
989
|
-
* Transform an event handler whose body leads with a command-modifier
|
|
990
|
-
* (`on <event> [from <src>] {async|once|debounced [at N]|throttled [at N]} <body>`).
|
|
991
|
-
*
|
|
992
|
-
* `parseEventHandler` reads the first token after the event as the **action**, so
|
|
993
|
-
* a leading modifier is mistaken for the verb and the real verb (`fetch`/`add`) is
|
|
994
|
-
* swept into the patient. For SOV targets the reorder then surfaces that verb
|
|
995
|
-
* **first** (`取得 /api/data を クリック …`), and the semantic parser matches the
|
|
996
|
-
* leading `<verb> <patient>` with the low-priority `*-generated-verb-first`
|
|
997
|
-
* command pattern — returning a bare command and discarding the event + the rest
|
|
998
|
-
* of the body (degenerate parse).
|
|
999
|
-
*
|
|
1000
|
-
* Instead, lift the modifier out, transform the modifier-free handler through the
|
|
1001
|
-
* normal path (which keeps the body in canonical patient-first SOV order so the
|
|
1002
|
-
* event sits mid-stream and the existing SOV event-extraction recovers it), then
|
|
1003
|
-
* re-emit the modifier as a **leading English literal**. The semantic parser
|
|
1004
|
-
* strips a leading `once`/`debounced`/`throttled` (`extractStandaloneModifiers`)
|
|
1005
|
-
* and an `async` anywhere (`stripAsyncModifier`) before parsing, so the modifier
|
|
1006
|
-
* is consumed as handler metadata rather than shadowing the body.
|
|
1007
|
-
*
|
|
1008
|
-
* Returns `null` (fall through) when the input isn't an event handler or the body
|
|
1009
|
-
* doesn't lead with a modifier — leaving simple/Mode-B handlers byte-identical.
|
|
1010
|
-
*/
|
|
1011
|
-
private tryTransformEventWithModifierBody;
|
|
1012
|
-
/**
|
|
1013
|
-
* Transform a `set <stuff> on <scope>` clause (S1 tabs-aria). The trailing
|
|
1014
|
-
* `on <scope>` is the element(s) the attribute is set on — kept attached by
|
|
1015
|
-
* splitOnCommandBoundaries. The semantic parser captures it as a `scope` role
|
|
1016
|
-
* via the passthrough literal `on` (setSchema's scope markerOverride is `on`
|
|
1017
|
-
* in every language), so `on` is emitted verbatim and only the scope *value*
|
|
1018
|
-
* is translated (selectors pass through; `me`/`it`/`you` translate to the
|
|
1019
|
-
* native reference, which the parser also accepts).
|
|
1020
|
-
*
|
|
1021
|
-
* Positioning matches where the set patterns expect the scope: at the clause
|
|
1022
|
-
* end for verb-first orders (SVO/VSO), and immediately before the clause-final
|
|
1023
|
-
* verb for SOV (the generated SOV pattern is `{dest} {patient} on {scope}
|
|
1024
|
-
* {verb}`). Returns null (fall through) when there is no trailing `on <scope>`.
|
|
1025
|
-
*
|
|
1026
|
-
* Source is English in the sync-translations pipeline, so the `set` verb and
|
|
1027
|
-
* `on` marker are matched as English literals.
|
|
1028
|
-
*/
|
|
1029
|
-
private transformSetWithScope;
|
|
1030
|
-
/**
|
|
1031
|
-
* Transform a self-contained block command (`{head} {clause?} {body} {end}`),
|
|
1032
|
-
* where head ∈ {if, repeat, unless, …}. The clause (condition / `until event …`)
|
|
1033
|
-
* runs up to the first command verb and is translated word-by-word; the body is
|
|
1034
|
-
* recursively transformed (so its inner commands reorder for the target); the
|
|
1035
|
-
* head/tail keywords are translated. The block is never word-order reordered as
|
|
1036
|
-
* a whole — delimiters stay at the edges regardless of target word order.
|
|
1037
|
-
*/
|
|
1038
|
-
private transformBlockBody;
|
|
1039
|
-
/**
|
|
1040
|
-
* Transform an `if`/`unless` block body, splitting it at a top-level `else` into
|
|
1041
|
-
* a then-branch and an else-branch so each is reordered as a self-contained unit
|
|
1042
|
-
* and the `else` keyword itself is translated. Without this, the body is reordered
|
|
1043
|
-
* as one stream: `else` rides along glued to the preceding clause (and, when that
|
|
1044
|
-
* clause begins with a selector, is marked a selector and left *untranslated*),
|
|
1045
|
-
* and a spurious `then` is inserted around it — both of which break the target
|
|
1046
|
-
* text and the downstream parse. The split is depth-aware so an `else` belonging
|
|
1047
|
-
* to a nested block is not mistaken for this block's separator. Bodies without an
|
|
1048
|
-
* `else` transform exactly as before.
|
|
1049
|
-
*/
|
|
1050
|
-
private transformConditionalBody;
|
|
1051
|
-
/**
|
|
1052
|
-
* Translate a reactive block by translating the head/tail/connector
|
|
1053
|
-
* via the dictionary, recursively transforming the body through the
|
|
1054
|
-
* regular pipeline, and rejoining in source-language position order.
|
|
1055
|
-
* Block-syntactic tokens are never reordered: they're delimiters, not
|
|
1056
|
-
* arguments, and authors expect them at start/end positions
|
|
1057
|
-
* regardless of target word order.
|
|
1058
|
-
*/
|
|
1059
|
-
private transformBlock;
|
|
1060
|
-
/**
|
|
1061
|
-
* Find the best matching rule for this statement
|
|
1062
|
-
*/
|
|
1063
|
-
private findRule;
|
|
1064
|
-
/**
|
|
1065
|
-
* Check if a parsed statement matches a rule
|
|
1066
|
-
*/
|
|
1067
|
-
private matchesRule;
|
|
1068
|
-
}
|
|
1069
|
-
/**
|
|
1070
|
-
* Transform hyperscript from English to target language
|
|
1071
|
-
*/
|
|
1072
|
-
declare function toLocale(input: string, targetLocale: string): string;
|
|
1073
|
-
/**
|
|
1074
|
-
* Transform hyperscript from source language to English
|
|
1075
|
-
*/
|
|
1076
|
-
declare function toEnglish(input: string, sourceLocale: string): string;
|
|
1077
|
-
/**
|
|
1078
|
-
* Transform between any two languages.
|
|
1079
|
-
*
|
|
1080
|
-
* Uses direct translation for supported language pairs (ja↔zh, es↔pt, ko↔ja),
|
|
1081
|
-
* falling back to English pivot for other pairs.
|
|
1082
|
-
*/
|
|
1083
|
-
declare function translate(input: string, sourceLocale: string, targetLocale: string): string;
|
|
1084
|
-
declare const examples: {
|
|
1085
|
-
english: {
|
|
1086
|
-
eventHandler: string;
|
|
1087
|
-
putInto: string;
|
|
1088
|
-
toggle: string;
|
|
1089
|
-
wait: string;
|
|
1090
|
-
};
|
|
1091
|
-
japanese: {
|
|
1092
|
-
eventHandler: string;
|
|
1093
|
-
putInto: string;
|
|
1094
|
-
toggle: string;
|
|
1095
|
-
wait: string;
|
|
1096
|
-
};
|
|
1097
|
-
chinese: {
|
|
1098
|
-
eventHandler: string;
|
|
1099
|
-
putInto: string;
|
|
1100
|
-
toggle: string;
|
|
1101
|
-
wait: string;
|
|
1102
|
-
};
|
|
1103
|
-
arabic: {
|
|
1104
|
-
eventHandler: string;
|
|
1105
|
-
putInto: string;
|
|
1106
|
-
toggle: string;
|
|
1107
|
-
wait: string;
|
|
1108
|
-
};
|
|
1109
|
-
};
|
|
1110
|
-
|
|
1111
|
-
export { joinTokens as $, type AdpositionType as A, frenchProfile as B, germanProfile as C, getProfile as D, ENGLISH_COMMANDS as E, getSupportedLocales as F, type GrammarRule as G, examples as H, hebrewProfile as I, hindiDictionary as J, type KeywordProvider as K, LANGUAGE_FAMILY_DEFAULTS as L, type MorphologyType as M, hiKeywords as N, id as O, type ParsedElement as P, idKeywords as Q, indonesianProfile as R, type SemanticRole as S, insertMarkers as T, UNIVERSAL_ENGLISH_KEYWORDS as U, it as V, type WordOrder as W, itKeywords as X, ja as Y, jaKeywords as Z, japaneseProfile as _, ENGLISH_KEYWORDS as a, ko as a0, koKeywords as a1, koreanProfile as a2, malayProfile as a3, ms as a4, msKeywords as a5, parseStatement as a6, pl as a7, plKeywords as a8, portugueseProfile as a9, vi as aA, viKeywords as aB, zh as aC, zhKeywords as aD, profiles as aa, pt as ab, ptKeywords as ac, qu as ad, quKeywords as ae, quechuaProfile as af, reorderRoles as ag, russianDictionary as ah, ruKeywords as ai, spanishProfile as aj, sw as ak, swKeywords as al, swahiliProfile as am, th as an, thKeywords as ao, tl as ap, tlKeywords as aq, toEnglish as ar, toLocale as as, tr as at, trKeywords as au, transformStatement as av, translate as aw, turkishProfile as ax, ukrainianDictionary as ay, ukKeywords as az, GrammarTransformer as b, type GrammaticalMarker as c, type KeywordProviderOptions as d, type LanguageProfile as e, LocaleManager as f, type ParsedStatement as g, type PatternMatcher as h, type PatternTransform as i, UNIVERSAL_PATTERNS as j, ar as k, arKeywords as l, arabicProfile as m, bn as n, bnKeywords as o, chineseProfile as p, createEnglishProvider as q, createKeywordProvider as r, de as s, deKeywords as t, detectBrowserLocale as u, englishProfile as v, es as w, esKeywords as x, fr as y, frKeywords as z };
|
|
880
|
+
export { koKeywords as $, type AdpositionType as A, germanProfile as B, getProfile as C, getSupportedLocales as D, ENGLISH_COMMANDS as E, hebrewProfile as F, type GrammarRule as G, hindiDictionary as H, hiKeywords as I, id as J, type KeywordProvider as K, LANGUAGE_FAMILY_DEFAULTS as L, type MorphologyType as M, idKeywords as N, indonesianProfile as O, type ParsedElement as P, insertMarkers as Q, it as R, type SemanticRole as S, itKeywords as T, UNIVERSAL_ENGLISH_KEYWORDS as U, ja as V, type WordOrder as W, jaKeywords as X, japaneseProfile as Y, joinTokens as Z, ko as _, ENGLISH_KEYWORDS as a, koreanProfile as a0, malayProfile as a1, ms as a2, msKeywords as a3, pl as a4, plKeywords as a5, portugueseProfile as a6, profiles as a7, pt as a8, ptKeywords as a9, qu as aa, quKeywords as ab, quechuaProfile as ac, reorderRoles as ad, russianDictionary as ae, ruKeywords as af, spanishProfile as ag, sw as ah, swKeywords as ai, swahiliProfile as aj, th as ak, thKeywords as al, tl as am, tlKeywords as an, tr as ao, trKeywords as ap, transformStatement as aq, turkishProfile as ar, ukrainianDictionary as as, ukKeywords as at, vi as au, viKeywords as av, zh as aw, zhKeywords as ax, type GrammaticalMarker as b, type KeywordProviderOptions as c, type LanguageProfile as d, LocaleManager as e, type ParsedStatement as f, type PatternMatcher as g, type PatternTransform as h, UNIVERSAL_PATTERNS as i, ar as j, arKeywords as k, arabicProfile as l, bn as m, bnKeywords as n, chineseProfile as o, createEnglishProvider as p, createKeywordProvider as q, de as r, deKeywords as s, detectBrowserLocale as t, englishProfile as u, es as v, esKeywords as w, fr as x, frKeywords as y, frenchProfile as z };
|
|
@@ -877,235 +877,4 @@ declare const profiles: Record<string, LanguageProfile>;
|
|
|
877
877
|
declare function getProfile(locale: string): LanguageProfile | undefined;
|
|
878
878
|
declare function getSupportedLocales(): string[];
|
|
879
879
|
|
|
880
|
-
|
|
881
|
-
* Grammar-Aware Transformer
|
|
882
|
-
*
|
|
883
|
-
* Transforms hyperscript statements between languages using the
|
|
884
|
-
* generalized grammar system. The key insight is that semantic
|
|
885
|
-
* roles are universal - only their surface realization differs.
|
|
886
|
-
*/
|
|
887
|
-
|
|
888
|
-
/**
|
|
889
|
-
* Parse a hyperscript statement into semantic roles
|
|
890
|
-
* This is the core analysis step that identifies WHAT each part means
|
|
891
|
-
*/
|
|
892
|
-
declare function parseStatement(input: string, sourceLocale?: string): ParsedStatement | null;
|
|
893
|
-
declare class GrammarTransformer {
|
|
894
|
-
private sourceProfile;
|
|
895
|
-
private targetProfile;
|
|
896
|
-
constructor(sourceLocale: string | undefined, targetLocale: string);
|
|
897
|
-
/**
|
|
898
|
-
* Transform a hyperscript statement from source to target language.
|
|
899
|
-
* Handles compound statements with "then" by splitting, transforming each part,
|
|
900
|
-
* and rejoining with the target language's "then" keyword.
|
|
901
|
-
*
|
|
902
|
-
* For multi-line input, preserves line structure (indentation, blank lines).
|
|
903
|
-
*/
|
|
904
|
-
transform(input: string): string;
|
|
905
|
-
private transformInternal;
|
|
906
|
-
/**
|
|
907
|
-
* Transform a single hyperscript statement (no compound "then" chains).
|
|
908
|
-
*/
|
|
909
|
-
private transformSingle;
|
|
910
|
-
/**
|
|
911
|
-
* Clause carrying a masked `using view transition` tail: strip the opaque
|
|
912
|
-
* token, transform the clause alone, and re-append the token at the very end.
|
|
913
|
-
*
|
|
914
|
-
* The tail is a clause-final modifier in every word order the corpus emits:
|
|
915
|
-
* the semantic side matches it as the literal `using view` marker plus a value
|
|
916
|
-
* word, and the SOV/VSO event-handler patterns admit it as an optional
|
|
917
|
-
* TRAILING group (after the with-marked operand). So the target position is
|
|
918
|
-
* "end of the transformed clause" for all 24 languages — no per-profile
|
|
919
|
-
* placement decision, which is what makes this a passthrough rather than a
|
|
920
|
-
* role.
|
|
921
|
-
*
|
|
922
|
-
* Returns null when the clause carries no masked tail, or when the token is
|
|
923
|
-
* not clause-final (nothing to reposition — leaving it in place still restores
|
|
924
|
-
* verbatim English).
|
|
925
|
-
*/
|
|
926
|
-
private transformWithViewTransitionTail;
|
|
927
|
-
/**
|
|
928
|
-
* `<command …> end` fragments: transform the command without its stranded
|
|
929
|
-
* terminator, then re-append the translated terminator as a standalone
|
|
930
|
-
* trailing token. Fragments that open a block of their own (`if … end`,
|
|
931
|
-
* `repeat … end`, `js … end`) bail — their terminator belongs to them and
|
|
932
|
-
* their dedicated paths handle it.
|
|
933
|
-
*/
|
|
934
|
-
private transformWithTrailingEnd;
|
|
935
|
-
/**
|
|
936
|
-
* Detect and transform an inline JS block (`[on <event>] js <raw js> end`).
|
|
937
|
-
*
|
|
938
|
-
* The `js ... end` body is raw JavaScript: it must not be tokenized,
|
|
939
|
-
* translated, or word-order reordered. We mask the whole block with a single
|
|
940
|
-
* opaque placeholder, run the surrounding statement (the event-handler head,
|
|
941
|
-
* if any) through the normal reorder pipeline so the placeholder lands in the
|
|
942
|
-
* correct action position, then substitute the translated `js`/`end` keywords
|
|
943
|
-
* around the verbatim body.
|
|
944
|
-
*
|
|
945
|
-
* Returns `null` (fall through to the normal path) when there is no js block,
|
|
946
|
-
* no matching `end`, or trailing content after `end` (kept tight on purpose).
|
|
947
|
-
*/
|
|
948
|
-
private tryTransformJsBlock;
|
|
949
|
-
/**
|
|
950
|
-
* Transform an event handler whose body is a block command
|
|
951
|
-
* (`on <event> [from <src>] {if|repeat|unless|while|for} … end`).
|
|
952
|
-
*
|
|
953
|
-
* `parseEventHandler` would treat the block keyword as the action and sweep the
|
|
954
|
-
* condition/body into role values, then reorder them — shredding the block
|
|
955
|
-
* (`if event.shiftKey call submitAndContinue() end` → scattered tokens). Instead
|
|
956
|
-
* we mask the whole block as an opaque action placeholder, reorder the event
|
|
957
|
-
* head normally, transform the block as a self-contained unit, and restitch.
|
|
958
|
-
*
|
|
959
|
-
* Returns `null` (fall through) when the input isn't an event handler, has no
|
|
960
|
-
* block-keyword body, or has no closing `end`.
|
|
961
|
-
*/
|
|
962
|
-
private tryTransformEventWithBlockBody;
|
|
963
|
-
/**
|
|
964
|
-
* Transform an event handler whose body is an inline `unless` guard with NO
|
|
965
|
-
* `end` (`on <event> unless <cond> <body>` — the `unless-condition` shape).
|
|
966
|
-
*
|
|
967
|
-
* Object-marking SVO targets (he, zh). `parseEventHandler` reads `unless` as the
|
|
968
|
-
* action and sweeps the whole `<cond> <body>` tail into a single `patient` blob;
|
|
969
|
-
* the target then prefixes that blob with its object marker — Hebrew's accusative
|
|
970
|
-
* את (`… אלא את I match .disabled מתג .selected`) or Chinese's BA particle 把
|
|
971
|
-
* (`… 除非 把 I match .disabled 切换 .selected`) — and the inner toggle loses its
|
|
972
|
-
* own marker. The semantic parser can't recover the guard from that: the marker
|
|
973
|
-
* ahead of the condition blocks the `unless` pattern AND the now-markerless body
|
|
974
|
-
* command fails its object-marked toggle pattern, so the body collapses (`unless`
|
|
975
|
-
* dropped). Marker-less languages (de/it/ar/pl) tolerate the same role-blob and
|
|
976
|
-
* stay faithful, so this is an object-marker artifact, not a general parse gap.
|
|
977
|
-
*
|
|
978
|
-
* The standalone `unless <cond> <body>` path already produces the correct shape
|
|
979
|
-
* (`extractBlockStructure` → `transformBlock`: condition kept marker-free, body
|
|
980
|
-
* command keeps its marker — he `אלא I match .disabled מתג את .selected`, zh
|
|
981
|
-
* `除非 I match .disabled 切换 把 .selected`). So we split the event head off,
|
|
982
|
-
* transform the guard through that path, and emit the event clause first (he and
|
|
983
|
-
* zh are both SVO — event leads). Returns `null` (fall through) when the input
|
|
984
|
-
* isn't an object-marking event handler with an un-terminated inline `unless`
|
|
985
|
-
* guard.
|
|
986
|
-
*/
|
|
987
|
-
private tryTransformEventWithUnlessGuard;
|
|
988
|
-
/**
|
|
989
|
-
* Transform an event handler whose body leads with a command-modifier
|
|
990
|
-
* (`on <event> [from <src>] {async|once|debounced [at N]|throttled [at N]} <body>`).
|
|
991
|
-
*
|
|
992
|
-
* `parseEventHandler` reads the first token after the event as the **action**, so
|
|
993
|
-
* a leading modifier is mistaken for the verb and the real verb (`fetch`/`add`) is
|
|
994
|
-
* swept into the patient. For SOV targets the reorder then surfaces that verb
|
|
995
|
-
* **first** (`取得 /api/data を クリック …`), and the semantic parser matches the
|
|
996
|
-
* leading `<verb> <patient>` with the low-priority `*-generated-verb-first`
|
|
997
|
-
* command pattern — returning a bare command and discarding the event + the rest
|
|
998
|
-
* of the body (degenerate parse).
|
|
999
|
-
*
|
|
1000
|
-
* Instead, lift the modifier out, transform the modifier-free handler through the
|
|
1001
|
-
* normal path (which keeps the body in canonical patient-first SOV order so the
|
|
1002
|
-
* event sits mid-stream and the existing SOV event-extraction recovers it), then
|
|
1003
|
-
* re-emit the modifier as a **leading English literal**. The semantic parser
|
|
1004
|
-
* strips a leading `once`/`debounced`/`throttled` (`extractStandaloneModifiers`)
|
|
1005
|
-
* and an `async` anywhere (`stripAsyncModifier`) before parsing, so the modifier
|
|
1006
|
-
* is consumed as handler metadata rather than shadowing the body.
|
|
1007
|
-
*
|
|
1008
|
-
* Returns `null` (fall through) when the input isn't an event handler or the body
|
|
1009
|
-
* doesn't lead with a modifier — leaving simple/Mode-B handlers byte-identical.
|
|
1010
|
-
*/
|
|
1011
|
-
private tryTransformEventWithModifierBody;
|
|
1012
|
-
/**
|
|
1013
|
-
* Transform a `set <stuff> on <scope>` clause (S1 tabs-aria). The trailing
|
|
1014
|
-
* `on <scope>` is the element(s) the attribute is set on — kept attached by
|
|
1015
|
-
* splitOnCommandBoundaries. The semantic parser captures it as a `scope` role
|
|
1016
|
-
* via the passthrough literal `on` (setSchema's scope markerOverride is `on`
|
|
1017
|
-
* in every language), so `on` is emitted verbatim and only the scope *value*
|
|
1018
|
-
* is translated (selectors pass through; `me`/`it`/`you` translate to the
|
|
1019
|
-
* native reference, which the parser also accepts).
|
|
1020
|
-
*
|
|
1021
|
-
* Positioning matches where the set patterns expect the scope: at the clause
|
|
1022
|
-
* end for verb-first orders (SVO/VSO), and immediately before the clause-final
|
|
1023
|
-
* verb for SOV (the generated SOV pattern is `{dest} {patient} on {scope}
|
|
1024
|
-
* {verb}`). Returns null (fall through) when there is no trailing `on <scope>`.
|
|
1025
|
-
*
|
|
1026
|
-
* Source is English in the sync-translations pipeline, so the `set` verb and
|
|
1027
|
-
* `on` marker are matched as English literals.
|
|
1028
|
-
*/
|
|
1029
|
-
private transformSetWithScope;
|
|
1030
|
-
/**
|
|
1031
|
-
* Transform a self-contained block command (`{head} {clause?} {body} {end}`),
|
|
1032
|
-
* where head ∈ {if, repeat, unless, …}. The clause (condition / `until event …`)
|
|
1033
|
-
* runs up to the first command verb and is translated word-by-word; the body is
|
|
1034
|
-
* recursively transformed (so its inner commands reorder for the target); the
|
|
1035
|
-
* head/tail keywords are translated. The block is never word-order reordered as
|
|
1036
|
-
* a whole — delimiters stay at the edges regardless of target word order.
|
|
1037
|
-
*/
|
|
1038
|
-
private transformBlockBody;
|
|
1039
|
-
/**
|
|
1040
|
-
* Transform an `if`/`unless` block body, splitting it at a top-level `else` into
|
|
1041
|
-
* a then-branch and an else-branch so each is reordered as a self-contained unit
|
|
1042
|
-
* and the `else` keyword itself is translated. Without this, the body is reordered
|
|
1043
|
-
* as one stream: `else` rides along glued to the preceding clause (and, when that
|
|
1044
|
-
* clause begins with a selector, is marked a selector and left *untranslated*),
|
|
1045
|
-
* and a spurious `then` is inserted around it — both of which break the target
|
|
1046
|
-
* text and the downstream parse. The split is depth-aware so an `else` belonging
|
|
1047
|
-
* to a nested block is not mistaken for this block's separator. Bodies without an
|
|
1048
|
-
* `else` transform exactly as before.
|
|
1049
|
-
*/
|
|
1050
|
-
private transformConditionalBody;
|
|
1051
|
-
/**
|
|
1052
|
-
* Translate a reactive block by translating the head/tail/connector
|
|
1053
|
-
* via the dictionary, recursively transforming the body through the
|
|
1054
|
-
* regular pipeline, and rejoining in source-language position order.
|
|
1055
|
-
* Block-syntactic tokens are never reordered: they're delimiters, not
|
|
1056
|
-
* arguments, and authors expect them at start/end positions
|
|
1057
|
-
* regardless of target word order.
|
|
1058
|
-
*/
|
|
1059
|
-
private transformBlock;
|
|
1060
|
-
/**
|
|
1061
|
-
* Find the best matching rule for this statement
|
|
1062
|
-
*/
|
|
1063
|
-
private findRule;
|
|
1064
|
-
/**
|
|
1065
|
-
* Check if a parsed statement matches a rule
|
|
1066
|
-
*/
|
|
1067
|
-
private matchesRule;
|
|
1068
|
-
}
|
|
1069
|
-
/**
|
|
1070
|
-
* Transform hyperscript from English to target language
|
|
1071
|
-
*/
|
|
1072
|
-
declare function toLocale(input: string, targetLocale: string): string;
|
|
1073
|
-
/**
|
|
1074
|
-
* Transform hyperscript from source language to English
|
|
1075
|
-
*/
|
|
1076
|
-
declare function toEnglish(input: string, sourceLocale: string): string;
|
|
1077
|
-
/**
|
|
1078
|
-
* Transform between any two languages.
|
|
1079
|
-
*
|
|
1080
|
-
* Uses direct translation for supported language pairs (ja↔zh, es↔pt, ko↔ja),
|
|
1081
|
-
* falling back to English pivot for other pairs.
|
|
1082
|
-
*/
|
|
1083
|
-
declare function translate(input: string, sourceLocale: string, targetLocale: string): string;
|
|
1084
|
-
declare const examples: {
|
|
1085
|
-
english: {
|
|
1086
|
-
eventHandler: string;
|
|
1087
|
-
putInto: string;
|
|
1088
|
-
toggle: string;
|
|
1089
|
-
wait: string;
|
|
1090
|
-
};
|
|
1091
|
-
japanese: {
|
|
1092
|
-
eventHandler: string;
|
|
1093
|
-
putInto: string;
|
|
1094
|
-
toggle: string;
|
|
1095
|
-
wait: string;
|
|
1096
|
-
};
|
|
1097
|
-
chinese: {
|
|
1098
|
-
eventHandler: string;
|
|
1099
|
-
putInto: string;
|
|
1100
|
-
toggle: string;
|
|
1101
|
-
wait: string;
|
|
1102
|
-
};
|
|
1103
|
-
arabic: {
|
|
1104
|
-
eventHandler: string;
|
|
1105
|
-
putInto: string;
|
|
1106
|
-
toggle: string;
|
|
1107
|
-
wait: string;
|
|
1108
|
-
};
|
|
1109
|
-
};
|
|
1110
|
-
|
|
1111
|
-
export { joinTokens as $, type AdpositionType as A, frenchProfile as B, germanProfile as C, getProfile as D, ENGLISH_COMMANDS as E, getSupportedLocales as F, type GrammarRule as G, examples as H, hebrewProfile as I, hindiDictionary as J, type KeywordProvider as K, LANGUAGE_FAMILY_DEFAULTS as L, type MorphologyType as M, hiKeywords as N, id as O, type ParsedElement as P, idKeywords as Q, indonesianProfile as R, type SemanticRole as S, insertMarkers as T, UNIVERSAL_ENGLISH_KEYWORDS as U, it as V, type WordOrder as W, itKeywords as X, ja as Y, jaKeywords as Z, japaneseProfile as _, ENGLISH_KEYWORDS as a, ko as a0, koKeywords as a1, koreanProfile as a2, malayProfile as a3, ms as a4, msKeywords as a5, parseStatement as a6, pl as a7, plKeywords as a8, portugueseProfile as a9, vi as aA, viKeywords as aB, zh as aC, zhKeywords as aD, profiles as aa, pt as ab, ptKeywords as ac, qu as ad, quKeywords as ae, quechuaProfile as af, reorderRoles as ag, russianDictionary as ah, ruKeywords as ai, spanishProfile as aj, sw as ak, swKeywords as al, swahiliProfile as am, th as an, thKeywords as ao, tl as ap, tlKeywords as aq, toEnglish as ar, toLocale as as, tr as at, trKeywords as au, transformStatement as av, translate as aw, turkishProfile as ax, ukrainianDictionary as ay, ukKeywords as az, GrammarTransformer as b, type GrammaticalMarker as c, type KeywordProviderOptions as d, type LanguageProfile as e, LocaleManager as f, type ParsedStatement as g, type PatternMatcher as h, type PatternTransform as i, UNIVERSAL_PATTERNS as j, ar as k, arKeywords as l, arabicProfile as m, bn as n, bnKeywords as o, chineseProfile as p, createEnglishProvider as q, createKeywordProvider as r, de as s, deKeywords as t, detectBrowserLocale as u, englishProfile as v, es as w, esKeywords as x, fr as y, frKeywords as z };
|
|
880
|
+
export { koKeywords as $, type AdpositionType as A, germanProfile as B, getProfile as C, getSupportedLocales as D, ENGLISH_COMMANDS as E, hebrewProfile as F, type GrammarRule as G, hindiDictionary as H, hiKeywords as I, id as J, type KeywordProvider as K, LANGUAGE_FAMILY_DEFAULTS as L, type MorphologyType as M, idKeywords as N, indonesianProfile as O, type ParsedElement as P, insertMarkers as Q, it as R, type SemanticRole as S, itKeywords as T, UNIVERSAL_ENGLISH_KEYWORDS as U, ja as V, type WordOrder as W, jaKeywords as X, japaneseProfile as Y, joinTokens as Z, ko as _, ENGLISH_KEYWORDS as a, koreanProfile as a0, malayProfile as a1, ms as a2, msKeywords as a3, pl as a4, plKeywords as a5, portugueseProfile as a6, profiles as a7, pt as a8, ptKeywords as a9, qu as aa, quKeywords as ab, quechuaProfile as ac, reorderRoles as ad, russianDictionary as ae, ruKeywords as af, spanishProfile as ag, sw as ah, swKeywords as ai, swahiliProfile as aj, th as ak, thKeywords as al, tl as am, tlKeywords as an, tr as ao, trKeywords as ap, transformStatement as aq, turkishProfile as ar, ukrainianDictionary as as, ukKeywords as at, vi as au, viKeywords as av, zh as aw, zhKeywords as ax, type GrammaticalMarker as b, type KeywordProviderOptions as c, type LanguageProfile as d, LocaleManager as e, type ParsedStatement as f, type PatternMatcher as g, type PatternTransform as h, UNIVERSAL_PATTERNS as i, ar as j, arKeywords as k, arabicProfile as l, bn as m, bnKeywords as n, chineseProfile as o, createEnglishProvider as p, createKeywordProvider as q, de as r, deKeywords as s, detectBrowserLocale as t, englishProfile as u, es as v, esKeywords as w, fr as x, frKeywords as y, frenchProfile as z };
|