Repository navigation
feat(kiritan): localize the CLI itself into English/Japanese - #42
Merged
Merged
Conversation
…glish/Japanese
Switches the CLI from citty to yargs, since citty has no hook for
translating its own --help output or argument-parsing errors (they're
hardcoded English strings inside the library itself) while yargs ships
full bundled translations for that boilerplate via .locale("ja").
Adds a --lang <en|ja> flag (falling back to KIRITAN_LANG, then the
usual POSIX locale env vars, then "en") that picks the CLI's own
display language, independently of --locale (which picks which
document locale a run acts on). Every command/option description and
the CLI's own plain-text output lines now go through
packages/kiritan/src/cli/messages.i18n.ts via @kiritan/runtime's
createT; --json output is untouched, staying machine-readable
regardless of --lang. A CheckIssue.detail or a thrown Error.message
from a pipeline function stays in English always, the same way a
library's own exceptions would.
messages.i18n.ts is registered as a colocated runtime.sources resource
in this repo's own .kiritanconfig, so kiritan check/typegen catch a
missing en/ja pair here the same way they would for any other
project's own resources.
yargs is kept external in tsdown.config.ts rather than bundled, since
its .locale() support reads locale JSON files at runtime from a path
relative to its own installed package directory — bundling it away
would silently break that lookup.
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
All alerts resolved. Learn more about Socket for GitHub. This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored. |
Verified against the actual CLI code first: @types/yargs (still only
published for the v17 API) type-checks cleanly against yargs 18's
runtime API surface for everything this CLI uses, and .locale("ja")
behaves identically. Considered sade as an alternative first, but its
own "Usage"/"Options"/"Missing required argument"-equivalent strings
are hardcoded English literals with no locale hook at all, so it
couldn't have replaced yargs here in the first place.
yargs 18 dropped CJS entirely (ESM-only), unlike 17's dual-format
export map — updated the tsdown.config.ts comment explaining why
`yargs` is kept external accordingly (an externalized require("yargs")
in the unused dist/cli.cjs stub would throw if anyone ran it, but
nothing does; the real dist/cli.mjs bin entry only ever imports it).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
^17.7.3, matching@types/yargs) — citty has no hook for translating its own--helpoutput or argument-parsing errors ("Missing required argument", "Unknown argument", etc.), which are hardcoded English strings inside the library itself. yargs ships full bundled translations for that boilerplate (.locale("ja")), which is what actually made this possible.--lang <en|ja>flag to every command, picking the CLI's own display language — independent of--locale, which picks which document locale abuild/check/translate/extractrun acts on. Falls back toKIRITAN_LANG, then the usual POSIX locale env vars (LC_ALL/LC_MESSAGES/LANG), thenen. An explicit but unsupported value (e.g.--lang fr) is reported as a normal invalid-choice error via yargs's own validation, rather than silently falling back.packages/kiritan/src/cli/messages.i18n.tsvia@kiritan/runtime'screateT— dogfooding kiritan's own runtime i18n for the CLI's own strings, per the user's request.check --jsonis untouched and stays machine-readable regardless of--lang(editor tooling parses it).CheckIssue.detailor a thrownError.messagefrom a pipeline function (packages/kiritan/src/pipeline/*.ts) — these are library-level strings shared by the CLI and the programmatic API, and stay in English the same way any Node library's own exceptions would.messages.i18n.tsis registered as acolocated-strategyruntime.sourcesresource in this repo's own.kiritanconfig, sokiritan check/kiritan typegencatch a missing en/ja pair here the same way they would for any other project's own resources — verified by temporarily deleting onejavalue and confirmingkiritan checkactually flagged it.yargsis kept external intsdown.config.ts(not bundled) — its.locale()support reads locale JSON files at runtime from a path resolved relative to its own installed package directory, which bundling would silently break.Test plan
npm run ci(prettier + eslint)npm run typechecknpm run test(11 new tests:resolveCliLanguage's precedence rules, and CLI-level tests spawning the real yargs parser via.parseAsync()forinit/build/checkin both languages, plus a--jsonoutput check)npm run docs:build/npm run docs:checkfix-unnatural-line-breakslint on every edited/new file--help/subcommand--helpin both languages, an unknown command, no command at all, and a bad--langvalue (all correctly localized via yargs's own bundled Japanese strings); raninit/build/check --jsonend-to-end in a scratch project confirming translated output and unaffected JSON