fix: complete Chinese building names and dragon soul interface labels
This commit is contained in:
@@ -125,7 +125,7 @@ def wrap_description(text: str) -> str:
|
||||
return " |".join(lines)
|
||||
|
||||
|
||||
def translate_itemdesc(path: Path, table: Path):
|
||||
def translate_itemdesc(path: Path, table: Path, names: dict = None):
|
||||
"""itemdesc.txt with its description and summary columns replaced from the English→Chinese table (UTF-8,
|
||||
English<TAB>Chinese) and wrapped; untranslated cells keep the English text."""
|
||||
chinese = {}
|
||||
@@ -137,6 +137,9 @@ def translate_itemdesc(path: Path, table: Path):
|
||||
for line in path.read_bytes().decode("cp1252").split("\n"):
|
||||
parts = line.split("\t")
|
||||
if parts[0].strip().isdigit():
|
||||
vnum = parts[0].strip()
|
||||
if names and vnum in names and names[vnum]:
|
||||
parts[1] = names[vnum]
|
||||
left = False
|
||||
for column in ITEMDESC_COLUMNS:
|
||||
text = parts[column].strip() if column < len(parts) else ""
|
||||
@@ -154,6 +157,26 @@ def translate_itemdesc(path: Path, table: Path):
|
||||
return {"translated_cells": translated, "english_rows": english_rows}
|
||||
|
||||
|
||||
def translate_guildbuildinglist(path: Path, table: Path):
|
||||
"""Replace column 3 (name) in guildbuildinglist.txt using a VNUM<TAB>NAME table (UTF-8)."""
|
||||
names = {}
|
||||
for line in table.read_text(encoding="utf-8").splitlines():
|
||||
if line and not line.startswith("#"):
|
||||
vnum, name = line.split("\t", 1)
|
||||
names[vnum.strip()] = name.strip()
|
||||
lines = path.read_bytes().decode("cp1252").splitlines()
|
||||
out = []
|
||||
translated = 0
|
||||
for line in lines:
|
||||
parts = line.split("\t")
|
||||
if parts and parts[0] in names:
|
||||
parts[3] = names[parts[0]]
|
||||
translated += 1
|
||||
out.append("\t".join(parts))
|
||||
path.write_bytes(("\n".join(out) + "\n").encode("gbk"))
|
||||
return {"translated_rows": translated}
|
||||
|
||||
|
||||
def overlay_rows(path: Path, overlay: Path, wrap_columns=()):
|
||||
"""Replace the rows of a vnum-keyed file by the overlay's (UTF-8, whole rows, no header); other rows keep
|
||||
their bytes (the English files are cp1252). wrap_columns (0-based) are wrapped like translated text."""
|
||||
@@ -320,7 +343,16 @@ def build(en: Path, zh: Path, output: Path, client_base: Path,
|
||||
|
||||
table = names_dir / "itemdesc_translate_zh.tsv" if names_dir else None
|
||||
if table and table.is_file():
|
||||
report["files"]["itemdesc.txt translation"] = translate_itemdesc(locale_dir / "itemdesc.txt", table)
|
||||
item_names_map = name_rows(names_dir / "item_names_zh.txt") if names_dir else {}
|
||||
if names_dir:
|
||||
item_names_map.update(name_rows(names_dir / "item_names_zh_overlay.txt"))
|
||||
report["files"]["itemdesc.txt translation"] = translate_itemdesc(
|
||||
locale_dir / "itemdesc.txt", table, item_names_map)
|
||||
|
||||
building_table = names_dir / "guildbuildinglist_zh.tsv" if names_dir else None
|
||||
if building_table and building_table.is_file() and (locale_dir / "guildbuildinglist.txt").is_file():
|
||||
report["files"]["guildbuildinglist.txt"] = translate_guildbuildinglist(
|
||||
locale_dir / "guildbuildinglist.txt", building_table)
|
||||
|
||||
for filename in ROW_FILES:
|
||||
overlay = names_dir / (Path(filename).stem + "_zh_overlay.txt") if names_dir else None
|
||||
|
||||
Reference in New Issue
Block a user