Skip to content

generate: --language option for the output language of the docs (#120) - #124

Merged
anhnh2002 merged 2 commits into
mainfrom
feat/output-language
Sep 30, 2026
Merged

anhnh2002 merged 2 commits into
mainfrom
feat/output-language

Conversation

@anhnh2002

Copy link
Copy Markdown
Collaborator

Closes #120.

Problem

--instructions "write in Japanese" added one trailing Additional instructions: line to English prompts. Some calls (the stale-link fix agent, for one) never saw it, so parts of the output stayed English. Asking the model to translate filenames broke the invariant that each module's .md filename equals its module-tree key. The result: Module docs not found warnings, missing-docs failures, and dead viewer links.

What this adds

  • codewiki generate --language ja (a code or a name: ja, Japanese, vi, zh, …), plus codewiki config agent --language as a saved default, and a language argument on the MCP generate_docs tool.
  • A dedicated <OUTPUT_LANGUAGE> directive, put first in the prompt addition. It asks for all prose, headings, tables and Mermaid labels in the target language. Code, identifiers and paths are kept as they are. Filenames, module names and link targets must never be translated.
  • The language travels inside agent_instructions, so every prompt that already received custom instructions gets it: module, leaf and sub-agent prompts, overviews, and the updater leaf agent. The stale-link fix agent now receives the instructions too.
  • metadata.json records generation_info.language. --update reuses it. It overrides the saved default and refuses an explicit --language that differs, pointing the user to a full regeneration instead.
  • GitHub Pages viewer: for translated docs, the nav, pager and overview labels use each page's first # heading, and <html lang> is set. Filenames stay ASCII. The viewer's own UI strings stay English for now.
  • Both instruction-merge paths now share AgentInstructions.merged_with. Side fix: to_backend_config no longer drops artifact_exclude.
  • English, or no --language, leaves prompts and output unchanged. The only default-path wording change: the repo-overview artifact addendum no longer forces an English section title.

Testing

  • New tests/test_language.py (23 tests) covers normalization, prompt directive placement, the config round-trip and both merge paths, metadata, update-language resolution, the stale-fix prompt, title extraction and viewer output.
  • Full suite: 237 passed, 2 skipped, 1 failed. The failure is test_clustering_skip.py::test_over_threshold_calls_llm_and_bad_response_falls_back, which also fails on main (its SimpleNamespace config has no max_tokens).
  • Smoke test on a small 4-file Python repo (claude-code provider, Haiku 4.5):
    • generate --language ja --github-pages: the overview prose and Mermaid labels are Japanese, metadata.json has "language": "Japanese", index.html has lang="ja" and the translated title, and there are no missing-docs warnings.
    • After a commit, generate --update with no --language: an incremental update, and the new apply_coupon section was written in Japanese.
    • generate --update --language vi: exits 2 with the mismatch message, before any LLM call.
    • The first smoke run exposed a problem. The initial directive wording let the model save the whole-repo page as shop.md instead of repo.md, so overview.md was missing. The directive now says to use exactly the filename named above, even when it differs from a package name. After that change, the rerun produced overview.md correctly.

Page prose, headings, tables and Mermaid labels follow the chosen language
while filenames, module-tree keys and link targets stay ASCII, so the
viewer, resume and --update keep working.

- New codewiki/src/language.py: normalize codes/names ("ja" -> Japanese),
  BCP-47 tag for <html lang>, and the OUTPUT_LANGUAGE prompt directive.
  English (or unset) leaves prompts unchanged.
- The language travels in agent_instructions, so every prompt that already
  gets get_prompt_addition() sees it, placed first. The stale-link fix agent
  now gets the instructions too.
- `generate --language`, `config agent --language`, MCP generate_docs
  `language`. Both instruction merge paths share AgentInstructions.merged_with
  (to_backend_config no longer drops artifact_exclude).
- metadata.json records generation_info.language; --update reuses it and
  refuses an explicit --language that differs.
- The GitHub Pages viewer shows each page's first H1 as its nav title for
  translated docs and sets <html lang>.
@anhnh2002
anhnh2002 merged commit 208473a into main Sep 30, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can language switching be supported?

1 participant