Script tag & DOM integration
Use the UMD/IIFE build when you prefer a <script> tag without a bundler, or host unolio.umd.js beside your HTML.
Served file
Hosts typically expose the file as:
/sdk/unolio.umd.js or CDN URL — src must point at your API origin (the same origin that exposes /api/v1), unless CORS allows cross-origin embedding.
Example:
<script
src="https://your-api-domain.com/sdk/unolio.umd.js"
data-project-id="YOUR_PROJECT_ID"
data-api-key="lk_your_api_key_here"
data-base-url="https://your-api-domain.com"
data-lang="en"
></script>
Auto-init (footer in dist/unolio.umd.js)
The bundled footer selects the last script[data-project-id] element. Together with data-api-key, it:
- Sets
window.unolio = createClient({ apiKey, baseUrl }) - Optionally
setLanguagefromdata-lang preload()thenUnolio.translateDOM(window.unolio)
Both data-project-id and data-api-key must be present for this path to run. data-base-url is optional (empty string omitted from options). If you omit data-project-id, instantiate manually:
window.unolio = Unolio.createClient({
apiKey: 'lk_...',
baseUrl: 'https://your-api-domain.com',
});
window.unolio.setLanguage('en');
await window.unolio.preload().then(() => Unolio.translateDOM(window.unolio));
(Use type="module" + async/inline await patterns as appropriate.)
DOM attributes
| Attribute | Where | Effect |
|---|---|---|
data-i18n="<key>" | Any element | Sets textContent from t(key) when translated value differs from missing |
data-i18n-placeholder="<key>" | Inputs | placeholder |
data-i18n-title="<key>" | Any | title |
data-i18n-aria-label="<key>" | Any | aria-label |
Fallback copy in markup is only replaced when t(key) returns something other than the raw key (same as translateDOM logic).
Language switching
Expose switchLanguage from the Unolio global when using UMD:
<select onchange="Unolio.switchLanguage(window.unolio, this.value)">
<option value="en">English</option>
<option value="de">Deutsch</option>
</select>
Alternatively call await client.preload(lang) and Unolio.translateDOM(client) yourself.
Other bundles
| File | Format | Typical use |
|---|---|---|
dist/unolio.esm.js | ES module | import { createClient } from '…' via bundlers or a <script type="module"> tag |
dist/unolio.cjs.js | CommonJS | require('@unolio/sdk') |
See also the repository README Quick Start – Option 1 (canonical examples may be updated independently).