Reference
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
scripts/coverage.ts
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
stdout guard to work around.
What Is Exported
The same set the MCP server consumes, grouped by what it does:
| Group | Operations |
|---|---|
| Detection | detectConfig, listLocaleDirs, listNamespaces |
| Reading | getTranslations, getMissingTranslations, getTranslationStatus, findEmptyTranslations, searchTranslations |
| Writing | writeTranslations, addTranslations, updateTranslations, removeTranslations, 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.
The command for each of these is documented in the CLI reference,
including its flags. An operation and its command take the same options under
the same names, because the command is a thin wrapper around the operation.
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.