Getting started
Prerequisites
- Unolio project with an API reachable from your app (
baseUrl). - API key (
lk_…) from the project dashboard (Settings → API keys). - Node.js 18+ if you use the SDK outside the browser (
fetchis required).
Install
npm install @unolio/sdk
For React helpers:
npm install @unolio/sdk react
Minimal flow
- Create a client with
apiKeyandbaseUrl(in Node or SSR, setbaseUrlexplicitly; in the browser it defaults towindow.location.origin). - Set language with
setLanguage(lang)when the locale changes. - Preload with
await client.preload(lang)(orpreload()for the current language) before relying on translations for first paint. - Translate with
client.t('key')orclient.t('key', { name: 'value' })for{{name}}placeholders.
import { createClient } from '@unolio/sdk';
const client = createClient({
apiKey: process.env.UNOLIO_API_KEY!,
baseUrl: 'https://your-api.example.com',
defaultLanguage: 'en',
});
await client.preload('en', 'de');
console.log(client.t('home.title'));
client.setLanguage('de');
console.log(client.t('home.title'));
Environment variables
| Context | Typical pattern |
|---|---|
| Vite | VITE_UNOLIO_API_KEY, VITE_UNOLIO_API_URL / BASE_URL — import.meta.env.VITE_* |
| Next.js (client) | NEXT_PUBLIC_UNOLIO_API_KEY, NEXT_PUBLIC_UNOLIO_API_URL — process.env.NEXT_PUBLIC_* |
| Node / scripts | process.env.UNOLIO_API_KEY, pass baseUrl in code |
Never commit production keys; keep them in env files excluded by .gitignore.
React (one-minute version)
Wrap the tree with UnolioProvider and a createClient() instance. Use useUnolioClient() (or bind client.t) for strings, and <Trans> for mixed {{variables}} and <tag> markup. See Framework integration for a full provider + preload example.
Next steps
- API reference — every method and React export
- Script tag & DOM — no bundler / static HTML
- Framework integration — Next.js, Vue, Svelte, etc.