zh locale: translate all 40250 itemdesc descriptions, wrapped for the tooltip

itemdesc_translate_zh.tsv maps the English description/summary text to Chinese (1,788 entries,
every itemdesc row covered). build_zh_locale.py replaces the cells and wraps Chinese into
26-byte lines joined by ' |', which 40250's Western SplitDescription turns into forced line
breaks; the 50307 overlay row is wrapped the same way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-09-30 11:17:21 +09:00
co-authored by Claude Opus 5.5
parent 3fcb27dd4d
commit b7c215ee42
4 changed files with 1941 additions and 4 deletions
+48
View File
@@ -13,6 +13,29 @@ MODULE = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(MODULE)
def split_description(desc, limit):
"""uitooltip.SplitDescription (40250 root), which runs on the encoded bytes under Python 2."""
line_tokens, line_len, lines = [], 0, []
for token in desc.split():
if b"|" in token:
sep_pos = token.find(b"|")
line_tokens.append(token[:sep_pos])
lines.append(b" ".join(line_tokens))
line_len = len(token) - (sep_pos + 1)
line_tokens = [token[sep_pos + 1:]]
else:
line_len += len(token)
if len(line_tokens) + line_len > limit:
lines.append(b" ".join(line_tokens))
line_len = len(token)
line_tokens = [token]
else:
line_tokens.append(token)
if line_tokens:
lines.append(b" ".join(line_tokens))
return lines
class LocaleBuildTest(unittest.TestCase):
def test_preserves_40250_keys_formats_and_proto(self):
with tempfile.TemporaryDirectory() as directory:
@@ -95,6 +118,31 @@ class LocaleBuildTest(unittest.TestCase):
with self.assertRaises(ValueError):
MODULE.overlay_rows(root / "itemdesc.txt", root / "overlay.txt")
def test_itemdesc_translation_wraps_for_split_description(self):
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
(root / "itemdesc.txt").write_bytes(
b"27001\tRed Potion (S)\tRestores HP.\t\r\n"
b"27002\tRed Potion (M)\tRestores 1,000 HP. Item is tradeable.\tPotion production\r\n"
b"99\tNew\tCaf\xe9.\t\r\n")
(root / "table.tsv").write_text(
"# English\t中文\nRestores HP.\t恢复生命值。\n"
"Restores 1,000 HP. Item is tradeable.\t立即恢复1,000点生命值,此物品可交易,冷却时间结束后可再次使用。\n"
"Potion production\t药水制作\n")
result = MODULE.translate_itemdesc(root / "itemdesc.txt", root / "table.tsv")
rows = (root / "itemdesc.txt").read_bytes().decode("gbk").split("\r\n")
self.assertEqual(rows[0], "27001\tRed Potion (S)\t恢复生命值。\t")
wrapped = rows[1].split("\t")[2]
self.assertEqual(wrapped, "立即恢复1,000点生命值, |此物品可交易, |冷却时间结束后可再次使用。")
self.assertEqual(rows[1].split("\t")[3], "药水制作")
self.assertEqual(rows[2], "99\tNew\tCafé.\t")
self.assertEqual(result, {"translated_cells": 3, "english_rows": ["99"]})
# uitooltip.SplitDescription (40250, Western path, 35 columns) on the GBK bytes gives these lines.
lines = split_description(wrapped.encode("gbk"), 35)
self.assertEqual([line.strip().decode("gbk") for line in lines],
["立即恢复1,000点生命值,", "此物品可交易,", "冷却时间结束后可再次使用。"])
self.assertEqual(MODULE.wrap_description("Plain English text"), "Plain English text")
def test_skilldesc_keeps_format_arguments(self):
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)