Cookbook
Multilingual recipes and translation examples for LokaScript.
For general hyperscript recipes (toggle, show/hide, forms, fetch),
see the hyperfixi cookbook.
Translating Code Between Languages
Use @lokascript/i18n to translate hyperscript code programmatically:
import { translate } from '@lokascript/i18n';
// English → Japanese (SOV word order)
translate('on click toggle .active on me', 'en', 'ja');
// → 'クリック で 私 の .active を 切り替え'
// English → Spanish (SVO word order)
translate('on click toggle .active on me', 'en', 'es');
// → 'al hacer clic alternar .active en mi'
// Japanese → English
translate('クリック で 私 の .active を 切り替え', 'ja', 'en');
// → 'on click toggle .active on me'
Multilingual Toggle
The same toggle pattern in multiple languages:
English (SVO)
on click toggle .active on me
Japanese (SOV)
クリック で 私 の .active を 切り替え
Spanish (SVO)
al hacer clic alternar .active en mi
Arabic (VSO)
عند النقر بدّل .active على نفسي
Adapter Plugin: Adding a Language
With the @lokascript/hyperscript-adapter, add multilingual
support to existing _hyperscript projects using data-lang:
<!-- Load _hyperscript + Spanish adapter -->
<script src="https://unpkg.com/hyperscript.org"></script>
<script src="https://unpkg.com/@lokascript/hyperscript-adapter@2.6.0/dist/hyperscript-i18n-es.global.js"></script>
<!-- Write hyperscript in Spanish -->
<button _="on click alternar .active" data-lang="es">
Alternar activo
</button>
<!-- English still works unchanged -->
<button _="on click toggle .active on me">
Toggle Active
</button>
Language Detection
Detect the language of hyperscript code automatically:
import { detect } from '@lokascript/semantic';
detect('クリック で 私 の .active を 切り替え');
// { language: 'ja', confidence: 0.95 }
detect('on click toggle .active on me');
// { language: 'en', confidence: 0.99 }
More Resources
- Patterns - Browse 164 patterns in 24 languages
- Multilingual API - Full API reference
- Adapter Plugin - Add multilingual support to _hyperscript
- hyperfixi Cookbook - General hyperscript recipes