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 JSON contract to work around.

What Is Exported

The same set the MCP server consumes, grouped by what it does:

GroupOperations
DetectiondescribeProject, detectConfig, listLocaleDirs, listNamespaces
ReadinggetTranslations, getMissingTranslations, getTranslationStatus, findEmptyTranslations, searchTranslations
WritingwriteTranslations, removeTranslations, moveTranslationKey, renameTranslationKey
TranslatingtranslateMissing, translateKey
AnalysisfindOrphanKeys, removeOrphanKeys, scanCodeUsage, findDuplicateKeys, checkUndefinedKeys
SetupscaffoldLocaleFiles
LocalesfindLocaleImpl, 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.

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:

scripts/report.ts
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/cli exports, and nothing deeper. The build emits content-hashed chunks, so a path into dist is not a stable import and will change on the next release.
  • Operations validate their own input and throw a ToolError carrying 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, translateMissing returns every key as skipped with reason no-provider rather than throwing; see the translate command.
Copyright © 2026