@nckdv/translation-sdk 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# `@nckdv/translation-sdk`
|
|
2
|
+
|
|
3
|
+
The API client for the nck-translation platform: fetch and cache a project's
|
|
4
|
+
catalogs, translate with them, and push updates back. Built on
|
|
5
|
+
`@nckdv/translation-core`.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @nckdv/translation-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { createClient } from "@nckdv/translation-sdk";
|
|
17
|
+
|
|
18
|
+
const client = createClient({
|
|
19
|
+
apiUrl: "https://translate.example.com",
|
|
20
|
+
apiKey: process.env.NCK_TRANSLATION_API_KEY, // server-side only
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// read
|
|
24
|
+
const t = await client.getTranslator("de");
|
|
25
|
+
t("home.title"); // "Willkommen bei Acme"
|
|
26
|
+
|
|
27
|
+
// push (needs a write-scoped key)
|
|
28
|
+
await client.push("en", { "home.title": "Welcome to Acme" });
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Notes
|
|
32
|
+
|
|
33
|
+
- **Server-side only.** The API key is a bearer credential for every catalog in
|
|
34
|
+
its project — never ship it to a browser.
|
|
35
|
+
- Catalogs are **cached in memory** (~5 min; `cacheMs`, `0` disables) and
|
|
36
|
+
**single-flighted**, so many concurrent reads of one language share one
|
|
37
|
+
request. A failure is never cached — the next read retries.
|
|
38
|
+
- `push()` merges a catalog into one language; a conflict throws a typed
|
|
39
|
+
`CatalogPushConflictError`. For the usual workflow, prefer
|
|
40
|
+
`@nckdv/translation-cli` (`sync` + `push`).
|
|
41
|
+
|
|
42
|
+
## API
|
|
43
|
+
|
|
44
|
+
`createClient(options)` returns: `getCatalog` · `getCatalogs` · `getTranslator`
|
|
45
|
+
· `prefetch` · `push` · `invalidate`.
|
|
46
|
+
|
|
47
|
+
## Family
|
|
48
|
+
|
|
49
|
+
- `@nckdv/translation-core` — the translate engine.
|
|
50
|
+
- `@nckdv/translation-cli` — `sync` / `push` from the command line.
|
|
51
|
+
- `@nckdv/translation-react` / `@nckdv/translation-nextjs` — React & Next.js
|
|
52
|
+
bindings.
|