Traditional Chinese API docs render argument descriptions in simplified Chinese

#234 · closed · 2 comments

View on GitHub ↗

tallneil

## What happens Every generated `*-README-zhHant.md` uses the simplified `@zh` text for argument descriptions, while the table header and the Returns section are correctly traditional. `packages/website-astro/api/useCounter-README-zhHant.md`: ``` #### Returns `readonly [...]`: 包含以下元素的元組: <- traditional, correct - 計數器的當前值。 #### Arguments |參數名|描述|類型|預設值| <- traditional header, correct |---|---|---|---| |initialValue|初始值,可以为数字或者一个初始化的函数|...| <- simplified, wrong |max|最大值。不提供则无上限|...| |min|最小值。不提供则无下限|...| ``` `packages/core/src/useCounter/interface.ts` defines `@zh-Hant` for every parameter, and the parser extracts it correctly — dumping `generate()` output shows both tags present with the right values: ```json { "name": "zh", "value": "初始值,可以为数字或者一个初始化的函数" }, { "name": "zh-Hant", "value": "初始值,可以為數字或者一個初始化的函數" } ``` So the translation exists and is reaching the renderer. It is discarded at the last step. ## Cause `packages/ts-document/src/generateMarkdown.ts:57`: ```ts // Field like tag.version const execResult = /tag\.(\w+)/.exec(field) if (execResult) { field = execResult[1] const obj = schema.tags?.find(tag => tag.name === field) ``` The `zh-Hant` table schema in `default.ts:75` sets the description column to `tag.zh-Hant`, but `\w` does not match `-`. The regex matches `tag.zh` and captures `zh`, dropping `-Hant`, so the lookup finds the simplified tag. This also explains why only the table is affected. The Returns text and the type description are read straight from `tagMap` (`generateMarkdown.ts:96` and `:108`) and never pass through this regex; only table *columns* do. ## Fix Allow hyphens in the captured tag name: ```diff -const execResult = /tag\.(\w+)/.exec(field) +const execResult = /tag\.([\w-]+)/.exec(field) ``` ## Verified Applied the one-character-class change, rebuilt `ts-document`, re-ran `pnpm --filter @reactuses/core gend`: - 90 `*-README-zhHant.md` files change, and their argument descriptions become traditional (`初始值,可以為數字或者一個初始化的函數`, `最大值。不提供則無上限`) - **0** English and **0** zhHans files change - 90 rather than the full hook count because hooks that take no arguments render no table ## Environment - `@reactuses/ts-document` 0.8.0 - reproduced on `main` at 48561e0 - note: `gend` currently needs `packages/ts-document` built by hand first — see #233

Comments

childrentime

Confirmed — your analysis is exactly right. Applied the regex change locally, rebuilt `ts-document` and re-ran `gend`: 89 `*-zhHant.md` files change, 0 English and 0 zhHans, and all 800 changed lines are table rows (description column only). Would you like to open a PR?

tallneil

PR is open: #237 One correction to the fix in this issue. The regex change alone regresses: 146 of the 447 documented parameters carry `@zh` with no `@zh-Hant`, and an exact-match lookup returns `-` for all of them, blanking 148 argument rows. The 90-file count in this issue includes those. The PR pairs the regex change with a base-language fallback — prefer the exact tag, fall back to the tag without the subtag — which is the rule `generate.ts:118` already applies to hook-level tags. Result: 85 files, 252 rows corrected, 0 blanked, 0 English or zhHans files touched.