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:

  1. Sets window.unolio = createClient({ apiKey, baseUrl })
  2. Optionally setLanguage from data-lang
  3. preload() then Unolio.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

AttributeWhereEffect
data-i18n="<key>"Any elementSets textContent from t(key) when translated value differs from missing
data-i18n-placeholder="<key>"Inputsplaceholder
data-i18n-title="<key>"Anytitle
data-i18n-aria-label="<key>"Anyaria-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

FileFormatTypical use
dist/unolio.esm.jsES moduleimport { createClient } from '…' via bundlers or a <script type="module"> tag
dist/unolio.cjs.jsCommonJSrequire('@unolio/sdk')

See also the repository README Quick Start – Option 1 (canonical examples may be updated independently).