# dm/i18n: the Chinese-English string table and the literal gate
中文: [README.zh-CN.md](README.zh-CN.md)
All UI text we added on top of the original game exists in Chinese and English and is registered in one table here; a scanning script makes sure no text bypasses that table. The game's own text is not handled here; it follows the game's own string tables.
## The three files
| File | What it is |
|---|---|
| `ui_text.tsv` | The string table, the single source of the UI text we added. Four tab-separated columns: `键` (key), `中文` (Chinese), `English`, `用在哪` (where used) |
| `scan_literals.py` | The literal gate: scans the sources for string literals containing Chinese and reports any that reach the screen without going through the table |
| `literal_whitelist.tsv` | The gate's whitelist: Chinese literals that really never reach the screen are registered here. Three columns: `文件` (file), `匹配` (match), `理由` (reason) |
The table is read by `dm/ios/tools/dm_i18n.py`, which does two things with it:
- **Text drawn inside the game**: when the overlay is built, every row is appended to the game's string table, with Chinese in the Simplified and Traditional Chinese columns and English in all other languages. Layouts write `@key`, and the host fetches by key with `dm_str`. Switching language is done by the game itself.
- **Text drawn outside the game** (system alerts, the resource download page and so on): it generates `dm/host/dm_i18n_tab.h`, which is compiled in and read by key with `dm_ui`.
The lookup interface is in `dm/host/dm_i18n.h`.
## Adding a UI string
1. Add a row to `ui_text.tsv` and fill in all four columns. The rules for the first three are enforced by `dm_i18n.py`, which stops with an error when one is broken:
- The key starts with `dm` followed by letters and digits only, no underscore (`@key` in a layout breaks at an underscore). Keys must be unique and must not clash with a key of the original game.
- Neither the Chinese nor the English may be empty. The English may not contain Chinese characters.
- Placeholders (`%d`, `%s` and so on) must match between the two columns in number, order and type.
- For a line break, write the two characters `\n`.
- Some keys (the Rift panel, Rift messages and others) have a length limit on the English; exceeding it reports what the limit is. The limits are `EN_LIMITS` in `dm_i18n.py`. Character count is only an approximation, so new English wording still needs a look at a screenshot to see that it stays inside its box.
- The "where used" column is not checked by any script. Existing rows say which screen the text appears on, which file uses it, and what each placeholder stands for; do the same.
2. Regenerate the header and commit it together with the table:
3. Use the key in code, never a literal: write `@key` in layout scripts (`dm/ios/tools/touch_layout.py` and others); in the host use `dm_str(main_base, "key")` for text inside the game and `dm_ui("key")` for text outside it.
4. Run the two checks below.
## The two checks
```
python3 dm/ios/tools/dm_i18n.py --check
python3 dm/i18n/scan_literals.py
```
Both only read source files and need no game files; `make -C dm/host/tests run` runs them too.
The first checks every row of the table against the rules above, and that the checked-in `dm/host/dm_i18n_tab.h` was generated from the current table. On success it prints `dm_i18n OK <count> 条`; when the header is stale it prints the command to regenerate it.
The second is the literal gate.
## How the literal gate decides
`scan_literals.py` scans string literals containing Chinese in these files:
- `*.c` and `*.m` under `dm/host/`, and `*.m` and `*.c` under `dm/ios/Sources/`;
- the layout and asset generation scripts whose output is written into the game, listed in `PY_FILES` in the script. A new script of that kind must be added to the list, or the gate will not see it.
These do not count: comments, Python docstrings, and literals whose innermost call is a logging or error function (`LOG`, `fprintf`, `NSLog`, `print` and so on; the list is `SINK` in the script).
Every remaining literal must have a row in `literal_whitelist.tsv`, or the gate is red. The match column takes four forms:
| Form | Meaning |
|---|---|
| A piece of text | The literal contains this text |
| `=` followed by the whole literal | The literal is exactly this |
| `@` followed by a function name | The literal's innermost call is this function |
| `*` | The whole file |
The reason column says why this Chinese never reaches the screen (for example, it only goes to logs). A whitelist row that no longer matches any literal is red as well and has to be removed.
Results:
- Pass: `I18N OK:中文字面量 N 条全在白名单(M 行),其余走中英表`, exit code 0.
- Fail: lines starting with `I18N 红`, listing file, line number and literal one by one, exit code 1.
- `python3 dm/i18n/scan_literals.py --list` lists every literal it found with its innermost call, for use when writing whitelist rows.
When the gate is red, first ask whether the player can see this text. If so, put it in the string table and use the key in code; add a whitelist row only when it really never reaches the screen. The gate only recognizes literals containing Chinese, so it cannot catch hard-coded English; that belongs in the table all the same.
Gate check: Chinese literals visible to the player must go through the Chinese-English string table (dm/i18n/ui_text.tsv) and may not bypass it (criterion 3 of the English version).
Scans host / iOS front-end sources and the layout / asset generation scripts whose output is written into the game, extracts string literals containing Chinese, and drops: comments, docstrings, and those whose innermost call is a logging / error function.
Every remaining one must have a row in the whitelist dm/i18n/literal_whitelist.tsv (file / match / reason; match = a fragment of the literal, or = followed by the whole literal, or @function name = the innermost call is that function, or * = the whole file), otherwise it is reported as a failure; surplus rows in the whitelist are reported as failures as well (to keep it from going stale).
Usage: python3 dm/i18n/scan_literals.py (run in the unit tests, see dm/host/tests/Makefile)"""
"""去注释,字面量原位保留;返回 [(起点, 字面量文本)] 与去注释后的全文(注释换成等长空格,下标不变)。 | Strip comments while keeping literals in place; returns [(start, literal text)] and the full text with comments removed (comments are replaced by spaces of equal length, so indices do not change)."""
"""pos 处字面量所在的最内层调用名(往前找未配对的左括号,取它前面的标识符);不在调用里返回 ''。 | Name of the innermost call containing the literal at pos (search backward for the unmatched left parenthesis and take the identifier before it); returns '' when not inside a call."""
dmDlIncomplete %s里的资源还不完整:%s Resources in %s are incomplete: %s 资源下载页:拷了一半
dmDlNoData 没找到游戏资源。「D2R Mobile」里现在有:%s%s。把整个资源文件夹拷进来 No game resources found. "D2R Mobile" now contains: %s%s. Copy in the whole resource folder 资源下载页
dmDlTidyFail 整理游戏资源没成(%s) Could not organize the game resources (%s) 资源下载页(main.m):档案散着放时挪进 data 没成
dmDlUnknown 原因不明 unknown reason 资源下载页(main.m)
dmDlPackBad 系统下载的资源包不完整:%s The downloaded resource pack is incomplete: %s 资源下载页(main.m)
dmDlNone 还没有放游戏资源 No game resources yet 资源下载页(main.m)
dmDlNameSep 、 , 资源下载页:文件夹名分隔符
dmDlEtc 等 etc. 资源下载页:列不完
dmDlRetry 重试 Retry 资源下载页按钮
dmDlNoAssets 还没有游戏资源\n请先从内测页的「下载资源包」把「D2R Mobile Resources」文件夹下到手机,\n再在「文件」里把它整个拷到「我的 iPhone → D2R Mobile」(别改名、别多套一层),拷完后点重试 No game resources yet\nDownload the "D2R Mobile Resources" folder from "Download resource pack" on the beta page,\nthen in Files copy the whole folder to "On My iPhone → D2R Mobile" (do not rename or nest it), then tap Retry 资源下载页:兜底指引
dmDlConnecting 正在连接资源服务器… Connecting to the resource server… 资源下载页
dmDlDownloading 正在下载游戏资源… Downloading game resources… 资源下载页
dmDlSpaceMsg 还差 %.2f GB。\n游戏资源还要下载 %.2f GB(另留 0.2 GB 余量),%@ 现在可用 %.2f GB。\n请在「设置 → 通用 → %@ 储存空间」清理后点重试。 %.2f GB more space needed.\nGame resources still need %.2f GB (plus 0.2 GB headroom); this %@ has %.2f GB free.\nFree up space in Settings → General → %@ Storage, then tap Retry. 资源下载页:空间不够(系统提示框正文)
dmDlNotStarted %@游戏资源下载没开始:%@\n%@\n也可以从内测页手动下载资源包,放进「我的 iPhone → D2R Mobile」 %@The resource download could not start: %@\n%@\nYou can also download the resource pack from the beta page and put it in "On My iPhone → D2R Mobile" 资源下载页:取不到下载地址 / 清单时停在这一页(前缀、原因、下一步)
dmDlNetDown 手机现在连不上网络(第一次打开时系统会问是否允许联网,没允许的话到「设置 → D2R Mobile」里打开) this device is offline (on first launch the system asks whether to allow network access; if you declined, turn it on in Settings → D2R Mobile) 资源下载页:下载没开始的原因
dmDlNoServer 连不上资源服务器 cannot reach the resource server 资源下载页:下载没开始的原因(asset_dl.m)
dmDlNoBase 包里没有配置下载地址 this build has no download address configured 资源下载页:下载没开始的原因(asset_dl.m)
dmDlNextAuto 网络通了会自动继续,也可以点重试;已经下好的部分不会重下 It resumes automatically once you are back online, or tap Retry. Anything already downloaded is kept. 资源下载页:下一步
dmDlNextRetry 点重试再试一次;已经下好的部分不会重下 Tap Retry to try again. Anything already downloaded is kept. 资源下载页:下一步
dmDlStopped 游戏资源下载停了:%@\n已下 %.2f / %.2f GB,点重试接着下(不会重头) The resource download stopped: %@\nDownloaded %.2f / %.2f GB. Tap Retry to resume (it will not start over) 资源下载页:中途停了
dmDlCopyIn 还没有游戏资源\n把游戏资源文件夹拷进「我的 iPhone → D2R Mobile」(在「文件」App 里)\n文件夹叫什么、套了几层都认;拷完后点重试 No game resources yet\nCopy the game resource folder into "On My iPhone → D2R Mobile" in the Files app\nAny folder name or nesting works; then tap Retry 资源下载页:这个包没配下载地址时(照公开仓库自己出的包)
dmDlCopyInShort 把缺的文件拷进同一个文件夹后点重试 Copy the missing files into the same folder, then tap Retry 资源下载页:没配下载地址、资源不完整时接在清单后面
dmOldNoSupportPkg 本包不带老机型支持(缺 romfs_overlay_astc/pack.json) This build has no support for older devices (romfs_overlay_astc/pack.json is missing) 老机型补充包:没用上的原因(main.m)
dmOldPackSize 「%s」里的补充包大小不对(%.2f / %.2f GB),像是没拷完 The pack in "%s" has the wrong size (%.2f / %.2f GB); the copy looks incomplete 老机型补充包:没用上的原因
dmOldPackBad 「%s」里的补充包内容不对(和这个版本不配套,或拷坏了),请重新下载 The pack in "%s" does not match this version or is corrupted; please download it again 老机型补充包:没用上的原因
dmOldPackNone 没找到老机型补充包 Supplementary pack for older devices not found 老机型补充包:没用上的原因
dmOldUnsupTitle 暂不支持本机型 Device Not Supported 老机型弹框标题(本包不带老机型支持时)
dmOldUnsupMsg 本机型(iPhone 14 及更早,A16 及以前芯片)暂不支持:显卡不支持游戏素材格式。iPhone 15 Pro 及以后可以玩。 This device (iPhone 14 or earlier, A16 chip or older) is not supported yet: its GPU cannot read the game's texture format. iPhone 15 Pro and later can run the game. 老机型弹框正文
dmOldNeedMsg 本机型需要老机型补充包(约 %.1f GB)。\n在「文件」里把「Legacy Device Pack」文件夹整个拷到「我的 iPhone → D2R Mobile」,再打开D2R Mobile。%@ This device needs the supplementary pack for older devices (about %.1f GB).\nIn the Files app, copy the whole "Legacy Device Pack" folder into "On My iPhone → D2R Mobile", then open D2R Mobile again.%@ 老机型弹框正文(%@ = 没用上的原因,可空)
dmOldWhySuffix \n(%s) \n(%s) 老机型弹框正文末尾的原因
dmOldDl 直接下载 Download 老机型弹框按钮
dmOldCopied 已经拷好了 Already Copied 老机型弹框按钮
dmOldQuit 退出 Quit 老机型弹框按钮
dmOldConnecting 正在连接下载服务器… Connecting to the download server… 老机型补充包下载页
dmRiftSayErr 秘境出错了,这次没开 The Rift could not be opened 秘境系统提示(dm_rift.c);英文:拟
dmRiftSayStart 第 %d 层开始,限时 15 分钟 Level %d: 15 minute time limit 秘境系统提示(dm_rift.c);英文:Greater Rift level / time limit 取自暗黑 3 官方 2.1.0 补丁说明(news.blizzard.com/en-us/article/14569138)「complete the current Greater Rift level within the designated time limit」
dmRiftSayGift 赠彩虹刻面一颗,已掉在脚下 A Rainbow Facet has dropped 秘境系统提示(dm_rift.c);「彩虹刻面」是旧译名(原版现行「彩虹魔石」);英文物品名 = 原版键 Rainbow Facet 的 enUS;英文:物品名 = 暗黑 2 原版 item-names[Rainbow Facet]
dmRiftSayTimeout 时间到:本层未过关,守护者仍会掉落 Time's up: level not cleared 秘境系统提示(dm_rift.c);超时打倒守护者不算过关;英文:not cleared,不用 Failed(没死也没失败,只是不计)
dmSkillCapLocked 打通任意一层秘境后解锁技能等级上限 Clear any Rift level to unlock the skill level cap 技能树里对已到 20 级的技能再加点、而这个角色还没打通过秘境时的系统提示(dm_actions.c);英文:Rift / level 同秘境其它提示
dmRiftPtsHeld 未分配的点数太多,剩余奖励在用掉后补发 Spend your points to get the rest 秘境系统提示(dm_rift.c 通关点数):未用点数顶到上限,剩下的等用掉后补发;英文按原意写
dmRiftMsSub90 补齐没有的那种 One you are missing 大秘境面板首通奖励列表(touch_layout.py RF_MS)
dmRiftMsTier90 90 层 90 首通奖励列表的层号(布局里是静态字,一行一条);英文:英文只写层号(栏宽放不下 Level N;标题栏已说明是 First Clear)
dmRiftMsItem100 六颗高级符文 6 High Runes 大秘境面板首通奖励列表(touch_layout.py RF_MS)
dmRiftMsSub100 28–33 号符文各一颗 Lo to Zod, one each 大秘境面板首通奖励列表(touch_layout.py RF_MS);符文名 = 原版 item-runes[r28]–[r33]:Lo / Sur / Ber / Jah / Cham / Zod Rune
dmRiftMsTier100 100 层 100 首通奖励列表的层号(布局里是静态字,一行一条);英文:英文只写层号(栏宽放不下 Level N;标题栏已说明是 First Clear)
dmRiftStr 怪物强度 Monster Power 大秘境面板(touch_layout.py _rift_panel);英文:Monster Power 是暗黑 3 1.0.5 的正式系统名(官方博客 us.diablo3.com/en/blog/7540457:「Monster Power, a new system designed to give players more control over how challenging enemies are」,并自比暗黑 2 的 Players X)
Can't render this file because it contains an unexpected character in line 19 and column 70.
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.