@verbatra/sdk 0.1.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 +30 -2
- package/dist/index.cjs +669 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +102 -1
- package/dist/index.d.ts +102 -1
- package/dist/index.js +665 -31
- package/dist/index.js.map +1 -1
- package/package.json +8 -5
package/README.md
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/mariokreitz/verbatra/main/.github/assets/verbatra-mark.png" alt="verbatra logo, a glowing V mark on a dark square" width="96" height="96" />
|
|
3
|
+
</p>
|
|
4
|
+
|
|
1
5
|
<h1 align="center">@verbatra/sdk</h1>
|
|
2
6
|
|
|
3
7
|
<p align="center">
|
|
@@ -5,12 +9,14 @@
|
|
|
5
9
|
</p>
|
|
6
10
|
|
|
7
11
|
<p align="center">
|
|
12
|
+
<a href="https://www.npmjs.com/package/@verbatra/sdk"><img src="https://img.shields.io/npm/v/@verbatra/sdk?label=%40verbatra%2Fsdk" alt="@verbatra/sdk npm version" /></a>
|
|
13
|
+
<a href="https://codecov.io/gh/mariokreitz/verbatra"><img src="https://codecov.io/gh/mariokreitz/verbatra/graph/badge.svg" alt="Coverage" /></a>
|
|
8
14
|
<a href="https://github.com/mariokreitz/verbatra/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="License: MIT" /></a>
|
|
9
15
|
</p>
|
|
10
16
|
|
|
11
17
|
## Description
|
|
12
18
|
|
|
13
|
-
`@verbatra/sdk` is the engine behind verbatra: load and validate a config, run the one-shot translate flow over every target locale,
|
|
19
|
+
`@verbatra/sdk` is the engine behind verbatra: load and validate a config, run the one-shot translate flow over every target locale, watch the source and re-translate on each change, or export and import an Excel workbook for manual translation. The [`@verbatra/cli`](https://github.com/mariokreitz/verbatra/tree/main/packages/cli) command is a thin wrapper over this package.
|
|
14
20
|
|
|
15
21
|
## Requirements
|
|
16
22
|
|
|
@@ -64,7 +70,7 @@ export default defineConfig({
|
|
|
64
70
|
});
|
|
65
71
|
```
|
|
66
72
|
|
|
67
|
-
`files.pattern` must contain the `{locale}` token, and `targetLocales` must not include `sourceLocale`; both are enforced when the config is validated. The supported `format` values are `i18next-json`, `vue-i18n-json`, `next-intl-json`, and `ngx-translate-json`. OpenAI and Gemini take `{ model, maxOutputTokens }`; DeepL takes `{}` (with an optional `glossaryId`). API keys are never part of the config. Each provider reads its own environment variable (`ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, `GEMINI_API_KEY`, `DEEPL_API_KEY`).
|
|
73
|
+
`files.pattern` must contain the `{locale}` token, and `targetLocales` must not include `sourceLocale`; both are enforced when the config is validated. The supported `format` values are `i18next-json`, `vue-i18n-json`, `next-intl-json`, and `ngx-translate-json`. The optional `glossary` (a term map) and `tone` (`"formal"`, `"informal"`, or `"neutral"`) refine the output. OpenAI and Gemini take `{ model, maxOutputTokens }`; DeepL takes `{}` (with an optional `glossaryId`). API keys are never part of the config. Each provider reads its own environment variable (`ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, `GEMINI_API_KEY`, `DEEPL_API_KEY`).
|
|
68
74
|
|
|
69
75
|
## API reference
|
|
70
76
|
|
|
@@ -101,6 +107,28 @@ const controller = await watch({
|
|
|
101
107
|
process.on("SIGINT", () => void controller.stop());
|
|
102
108
|
```
|
|
103
109
|
|
|
110
|
+
### `exportWorkbook(input): Promise<ExportWorkbookResult>`
|
|
111
|
+
|
|
112
|
+
Exports the strings that need translating into a styled Excel workbook for a human translator. `input` is `{ config, cwd?, out?, locales?, includeUnchanged? }`. By default it writes the missing and changed strings for every target locale to `verbatra-translations.xlsx`; `out` overrides the path, `locales` narrows which target locales are exported, and `includeUnchanged: true` also exports already up-to-date strings. Resolves to an `ExportWorkbookResult` with the written `path` and a per-locale row count.
|
|
113
|
+
|
|
114
|
+
### `importWorkbook(input): Promise<RunSummary>`
|
|
115
|
+
|
|
116
|
+
Imports a filled workbook back into the locale files, running the same placeholder and ICU checks as `translate`. `input` is `{ config, workbook, cwd?, dryRun? }`. With `dryRun: true` it validates and reports without writing locale files or updating the lock. Resolves to a `RunSummary`, the same shape `translate` returns.
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
import { exportWorkbook, importWorkbook, loadConfig } from "@verbatra/sdk";
|
|
120
|
+
|
|
121
|
+
const config = await loadConfig();
|
|
122
|
+
|
|
123
|
+
// Export the strings that need translating to an Excel workbook.
|
|
124
|
+
const { path } = await exportWorkbook({ config });
|
|
125
|
+
|
|
126
|
+
// ...a human fills the Translation column, then import the file back.
|
|
127
|
+
const summary = await importWorkbook({ config, workbook: path });
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
See [Manual translation](https://verbatra.kreitz-webdev.de/docs/manual-translation) for the full round-trip and the workbook layout.
|
|
131
|
+
|
|
104
132
|
## Errors and results
|
|
105
133
|
|
|
106
134
|
The SDK throws a single structured error type, `SdkError`, for whole-run failures such as a missing or invalid config or an unreadable source file. It carries a stable `code` and never contains an API key. Per-locale failures do not throw: they are recorded on the `RunSummary` so one failing locale never aborts the others.
|