@nckdv/translation-sdk
v0.2.1
Published
Client SDK for the nck-translation API: catalog fetching, caching and single-flight.
Downloads
504
Maintainers
Readme
@nckdv/translation-sdk
The API client for the nck-translation platform: fetch and cache a project's
catalogs, translate with them, and push updates back. Built on
@nckdv/translation-core.
Install
npm install @nckdv/translation-sdkUsage
import { createClient } from "@nckdv/translation-sdk";
const client = createClient({
apiUrl: "https://translate.example.com",
apiKey: process.env.NCK_TRANSLATION_API_KEY, // server-side only
});
// read
const t = await client.getTranslator("de");
t("home.title"); // "Willkommen bei Acme"
// push (needs a write-scoped key)
await client.push("en", { "home.title": "Welcome to Acme" });Notes
- Server-side only. The API key is a bearer credential for every catalog in its project — never ship it to a browser.
- Catalogs are cached in memory (~5 min;
cacheMs,0disables) and single-flighted, so many concurrent reads of one language share one request. A failure is never cached — the next read retries. push()merges a catalog into one language; a conflict throws a typedCatalogPushConflictError. For the usual workflow, prefer@nckdv/translation-cli(sync+push).
API
createClient(options) returns: getCatalog · getCatalogs · getTranslator
· prefetch · push · invalidate.
Family
@nckdv/translation-core— the translate engine.@nckdv/translation-cli—sync/pushfrom the command line.@nckdv/translation-react/@nckdv/translation-nextjs— React & Next.js bindings.
