@loklify/core
v0.1.4
Published
Loklify SDK · framework-agnostic translation client. Fetches i18n keys from your Loklify project at runtime.
Downloads
711
Maintainers
Readme
@loklify/core
Framework-agnostic translation client for Loklify, the i18n platform for small teams. Fetches translations from your Loklify project at runtime, with built-in in-memory cache.
Don't have an account yet? Create your project free at app.loklify.com.
Install
npm install @loklify/core
# or
pnpm add @loklify/core
# or
yarn add @loklify/coreUsage
import { LoklifyClient } from '@loklify/core'
const client = new LoklifyClient({
project: 'your-project-id',
})
const messages = await client.loadLocale('en')
// { 'home.title': 'Welcome', 'home.cta': 'Get started', ... }You'll find your project ID in the Loklify dashboard at app.loklify.com, under your project's settings.
API
new LoklifyClient(options)
| Option | Type | Required | Description |
|---|---|---|---|
| project | string | yes | Your Loklify project ID |
| token | string | no | Bearer token for private projects |
| apiBase | string | no | Override API URL (defaults to https://api.loklify.com) |
client.loadLocale(lang): Promise<Messages>
Fetches translations for the given language code. Subsequent calls for the same language hit the in-memory cache.
const fr = await client.loadLocale('fr')
const en = await client.loadLocale('en')client.setToken(token)
Updates the Bearer token for private projects. Useful when the user logs in after the client is constructed.
client.clearCache(lang?)
Clears the cache. Pass a language code to clear a single locale, or call without arguments to clear all.
client.clearCache('fr') // single locale
client.clearCache() // everythingTypes
import type { LoklifyOptions, Messages } from '@loklify/core'
type Messages = Record<string, string>Framework integrations
- Vue 3:
@loklify/vue· plugin withvue-i18nauto-injection - Nuxt 3/4:
@loklify/nuxt· zero-config module
Links
- Platform: loklify.com
- Dashboard: app.loklify.com
- Source: github.com/loklify/sdk
License
MIT
