Programmatic API
Every operation behind a command is exported from @the-i18n-kit/cli. A tool
that needs translation data can call the operation rather than spawning the CLI
and parsing its output — which is how the MCP server is built.
Using It
import { detectConfig, getTranslationStatus } from '@the-i18n-kit/cli'
const config = await detectConfig(process.cwd())
const status = await getTranslationStatus({ projectDir: process.cwd() })
console.log(`${config.locales.length} locales across ${config.layers.length} layers`)
Operations take a projectDir and return plain data. Nothing writes to stdout,
so the return value is the whole result — there is no output to parse and no
JSON contract to work around.
What Is Exported
The same set the MCP server consumes, grouped by what it does:
| Group | Operations |
|---|---|
| Detection | describeProject, detectConfig, listLocaleDirs, listNamespaces |
| Reading | getTranslations, getMissingTranslations, getTranslationStatus, findEmptyTranslations, searchTranslations |
| Writing | writeTranslations, removeTranslations, moveTranslationKey, renameTranslationKey |
| Translating | translateMissing, translateKey |
| Analysis | findOrphanKeys, removeOrphanKeys, scanCodeUsage, findDuplicateKeys, checkUndefinedKeys |
| Setup | scaffoldLocaleFiles |
| Locales | findLocaleImpl, resolveProtectedLocales |
Result types are exported alongside them, so a consumer types its own handling rather than restating the shape.
Reports Are the Caller's Business
An operation always returns its whole result. Writing that result to a file and
handing back { reportFile, summary } instead is what a surface does with it,
so outputFile and codequalityOutput are flags and tool parameters rather
than operation options, and reportOutput in the project config does not reach
a library caller.
The same diversion is exported, for a consumer that wants it:
import { descriptors, divertToReport, findOrphanKeys } from '@the-i18n-kit/cli'
const args = { projectDir: process.cwd(), outputFile: 'orphans.json' }
const result = await findOrphanKeys(args)
const orphans = descriptors.find(descriptor => descriptor.id === 'orphans')!
// { reportFile, summary }, with the full result written to orphans.json
const diverted = await divertToReport(result, orphans, args)
Limits
- The public surface is what
@the-i18n-kit/cliexports, and nothing deeper. The build emits content-hashed chunks, so a path intodistis not a stable import and will change on the next release. - Operations validate their own input and throw a
ToolErrorcarrying a code. They do not set an exit code — that is the command's job, not the operation's. - Translating needs a provider. Called without one,
translateMissingreturns every key as skipped with reasonno-providerrather than throwing; see the translate command.