Using Chinese Source Text as i18n Keys: A CLI Workflow That Lets LLMs Handle the Translation Grind
For teams that own their translations and want LLM help without a separate translation platform, this removes the key-to-source mapping overhead and builds review and validation into the CLI. It is a concrete alternative to semantic keys when source-text stability is acceptable and the team can tolerate the trade-off of changing a key every time the copy changes.
Most i18n setups use semantic keys like `features.localeFiles.title`, which separate code from copy and add a mapping layer. When the source language is Chinese and developers maintain translations themselves, a different pattern works better: pass the Chinese source string directly to `t()`. This makes code read as the copy, gives an LLM translator natural context, and lets the same Chinese phrase map to multiple translations via a `__TRANS_ID` suffix.
The `@10coding/i18n-trans` CLI automates the maintenance workflow around this idea. It statically scans `t()` calls with Babel, compares source and target locale JSONs for missing or extra keys, and can auto-fix with `--add` and `--remove` flags. The `trans` command sends untranslated units in batches of 20 to any OpenAI-compatible endpoint, validates the response for exact key matches and placeholder preservation, and marks AI output with a `⟦REVIEW⟧` prefix for human sign-off.
Using source text as keys couples key stability to copy stability; every copy change becomes a key change that orphans existing translations, so teams with frequently rewritten UI text would see constant churn.
The approach deliberately skips a runtime package and only defines a contract, which sidesteps framework version fragmentation but shifts the burden of correct interpolation handling to the consuming app.
Batching LLM calls at 20 units with context and validation treats machine translation as an asynchronous review pipeline rather than a one-shot replacement, matching how cautious teams actually need to deploy AI output.
The `__TRANS_ID` mechanism solves the one-word-many-translations problem without inventing artificial semantic keys, but it relies on the developer manually specifying the variant argument at each call site.