@lokascript/hyperscript-adapter 2.10.0 → 2.11.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 +16 -11
- package/dist/hyperscript-i18n-ar.global.js +5 -6
- package/dist/hyperscript-i18n-bn.global.js +5 -6
- package/dist/hyperscript-i18n-de.global.js +5 -6
- package/dist/hyperscript-i18n-east-asian.global.js +5 -6
- package/dist/hyperscript-i18n-en.global.js +7 -8
- package/dist/hyperscript-i18n-es.global.js +5 -6
- package/dist/hyperscript-i18n-fr.global.js +5 -6
- package/dist/hyperscript-i18n-he.global.js +5 -6
- package/dist/hyperscript-i18n-hi.global.js +5 -6
- package/dist/hyperscript-i18n-id.global.js +5 -6
- package/dist/hyperscript-i18n-it.global.js +5 -6
- package/dist/hyperscript-i18n-ja.global.js +5 -6
- package/dist/hyperscript-i18n-ko.global.js +5 -6
- package/dist/hyperscript-i18n-lite.global.js +2 -2
- package/dist/hyperscript-i18n-ms.global.js +5 -6
- package/dist/hyperscript-i18n-pl.global.js +5 -6
- package/dist/hyperscript-i18n-pt.global.js +5 -6
- package/dist/hyperscript-i18n-qu.global.js +5 -6
- package/dist/hyperscript-i18n-ru.global.js +5 -6
- package/dist/hyperscript-i18n-slavic.global.js +5 -6
- package/dist/hyperscript-i18n-south-asian.global.js +5 -6
- package/dist/hyperscript-i18n-southeast-asian.global.js +5 -6
- package/dist/hyperscript-i18n-sw.global.js +5 -6
- package/dist/hyperscript-i18n-th.global.js +5 -6
- package/dist/hyperscript-i18n-tl.global.js +5 -6
- package/dist/hyperscript-i18n-tr.global.js +5 -6
- package/dist/hyperscript-i18n-uk.global.js +5 -6
- package/dist/hyperscript-i18n-vi.global.js +5 -6
- package/dist/hyperscript-i18n-western.global.js +5 -6
- package/dist/hyperscript-i18n-zh.global.js +5 -6
- package/dist/hyperscript-i18n.global.js +27 -28
- package/dist/hyperscript-i18n.global.js.map +1 -1
- package/dist/index.cjs +107 -86
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +75 -12
- package/dist/index.d.ts +75 -12
- package/dist/index.js +107 -93
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/attribute-translator.ts +12 -7
- package/src/browser-lite.ts +18 -3
- package/src/host-validate.ts +63 -0
- package/src/hyperscript-renderer.ts +64 -5
- package/src/index.ts +6 -1
- package/src/language-resolver.ts +15 -3
- package/src/plugin.ts +57 -7
- package/src/preprocessor-core.ts +217 -0
- package/src/preprocessor.ts +14 -215
- package/src/slim-plugin.ts +18 -3
- package/src/slim-preprocessor.ts +16 -154
package/README.md
CHANGED
|
@@ -112,21 +112,26 @@ The plugin resolves language in this order:
|
|
|
112
112
|
|
|
113
113
|
1. `data-lang` attribute on the element
|
|
114
114
|
2. `data-hyperscript-lang` on the element or closest ancestor
|
|
115
|
-
3.
|
|
116
|
-
|
|
115
|
+
3. `lang` attribute on the element or closest ancestor (the standard HTML
|
|
116
|
+
cascade — a `<section lang="es">` localizes everything inside it, and a
|
|
117
|
+
nested `lang="en"` opts back out)
|
|
118
|
+
4. `<html lang="...">` on the document (reached via step 3 for attached
|
|
119
|
+
elements; still applies to detached fragments)
|
|
120
|
+
5. `defaultLanguage` option (if configured)
|
|
117
121
|
|
|
118
122
|
English (`en`) and unresolved languages pass through without translation.
|
|
119
123
|
|
|
120
124
|
## Options
|
|
121
125
|
|
|
122
|
-
| Option | Type | Default | Description
|
|
123
|
-
| --------------------- | ---------------------------------- | ------------- |
|
|
124
|
-
| `defaultLanguage` | `string` | — | Default language for all elements
|
|
125
|
-
| `languageAttribute` | `string` | `"data-lang"` | Custom attribute name for per-element language
|
|
126
|
-
| `confidenceThreshold` | `number \| Record<string, number>` | `0.5` | Min confidence (0–1). Per-language map supported (see below).
|
|
127
|
-
| `strategy` | `'semantic' \| 'i18n' \| 'auto'` | `'semantic'` | Translation strategy
|
|
128
|
-
| `debug` | `boolean` | `false` | Log translations to console
|
|
129
|
-
| `i18nToEnglish` | `function` | — | Optional `@lokascript/i18n` `toEnglish` function for fallback
|
|
126
|
+
| Option | Type | Default | Description |
|
|
127
|
+
| --------------------- | ---------------------------------- | ------------- | ------------------------------------------------------------------------------------------------------------------ |
|
|
128
|
+
| `defaultLanguage` | `string` | — | Default language for all elements |
|
|
129
|
+
| `languageAttribute` | `string` | `"data-lang"` | Custom attribute name for per-element language |
|
|
130
|
+
| `confidenceThreshold` | `number \| Record<string, number>` | `0.5` | Min confidence (0–1). Per-language map supported (see below). |
|
|
131
|
+
| `strategy` | `'semantic' \| 'i18n' \| 'auto'` | `'semantic'` | Translation strategy |
|
|
132
|
+
| `debug` | `boolean` | `false` | Log translations to console |
|
|
133
|
+
| `i18nToEnglish` | `function` | — | Optional `@lokascript/i18n` `toEnglish` function for fallback |
|
|
134
|
+
| `validateWithHost` | `boolean` | `true` | Check rendered English on the host parser; on rejection keep the original text (no-op on builds without `parse()`) |
|
|
130
135
|
|
|
131
136
|
### Per-language confidence thresholds
|
|
132
137
|
|
|
@@ -147,7 +152,7 @@ _hyperscript.use(
|
|
|
147
152
|
|
|
148
153
|
## How It Works
|
|
149
154
|
|
|
150
|
-
The plugin
|
|
155
|
+
The plugin registers an `addBeforeProcessHook` callback — \_hyperscript's supported public extension point, which fires before the runtime reads `_="..."` attributes (or `<script type="text/hyperscript">` bodies). Non-English input is rewritten to English in place via the `@lokascript/semantic` parser before the runtime's own scan reaches it, and the rendered English is checked on the host's own parser before it is committed (see `validateWithHost`). No \_hyperscript internals are patched. Requires a \_hyperscript build that exposes `addBeforeProcessHook` (0.9.9x era).
|
|
151
156
|
|
|
152
157
|
## Limitations
|
|
153
158
|
|