@verbatra/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.
Files changed (2) hide show
  1. package/README.md +24 -2
  2. package/package.json +5 -5
package/README.md CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
  ## Description
18
18
 
19
- `@verbatra/sdk` is the engine behind verbatra: load and validate a config, run the one-shot translate flow over every target locale, or watch the source and re-translate on each change. The [`@verbatra/cli`](https://github.com/mariokreitz/verbatra/tree/main/packages/cli) command is a thin wrapper over this package.
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.
20
20
 
21
21
  ## Requirements
22
22
 
@@ -70,7 +70,7 @@ export default defineConfig({
70
70
  });
71
71
  ```
72
72
 
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`. 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`).
74
74
 
75
75
  ## API reference
76
76
 
@@ -107,6 +107,28 @@ const controller = await watch({
107
107
  process.on("SIGINT", () => void controller.stop());
108
108
  ```
109
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
+
110
132
  ## Errors and results
111
133
 
112
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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verbatra/sdk",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "description": "Programmatic API to automate i18n translation and keep your locale files in sync across languages with AI and machine-translation providers.",
6
6
  "keywords": [
@@ -31,7 +31,7 @@
31
31
  "url": "git+https://github.com/mariokreitz/verbatra.git",
32
32
  "directory": "packages/sdk"
33
33
  },
34
- "homepage": "https://github.com/mariokreitz/verbatra/tree/main/packages/sdk",
34
+ "homepage": "https://verbatra.kreitz-webdev.de",
35
35
  "bugs": {
36
36
  "url": "https://github.com/mariokreitz/verbatra/issues"
37
37
  },
@@ -71,15 +71,15 @@
71
71
  "zod": "4.4.3"
72
72
  },
73
73
  "devDependencies": {
74
- "@types/node": "22.19.21",
74
+ "@types/node": "26.0.0",
75
75
  "@vitest/coverage-v8": "4.1.8",
76
76
  "tsup": "8.5.1",
77
77
  "typescript": "6.0.3",
78
78
  "vitest": "4.1.8",
79
- "@verbatra/ai-providers": "0.1.0",
80
- "@verbatra/core": "0.1.0",
81
79
  "@verbatra/exchange": "0.2.0",
82
80
  "@verbatra/format-adapters": "0.2.0",
81
+ "@verbatra/ai-providers": "0.1.0",
82
+ "@verbatra/core": "0.1.0",
83
83
  "@verbatra/config": "0.0.0"
84
84
  },
85
85
  "scripts": {