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 (fetch is required).

Install

npm install @unolio/sdk

For React helpers:

npm install @unolio/sdk react

Minimal flow

  1. Create a client with apiKey and baseUrl (in Node or SSR, set baseUrl explicitly; in the browser it defaults to window.location.origin).
  2. Set language with setLanguage(lang) when the locale changes.
  3. Preload with await client.preload(lang) (or preload() for the current language) before relying on translations for first paint.
  4. Translate with client.t('key') or client.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

ContextTypical pattern
ViteVITE_UNOLIO_API_KEY, VITE_UNOLIO_API_URL / BASE_URLimport.meta.env.VITE_*
Next.js (client)NEXT_PUBLIC_UNOLIO_API_KEY, NEXT_PUBLIC_UNOLIO_API_URLprocess.env.NEXT_PUBLIC_*
Node / scriptsprocess.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