diff --git a/scripts/build_zh_locale.py b/scripts/build_zh_locale.py index 1ed814f3..3520de26 100644 --- a/scripts/build_zh_locale.py +++ b/scripts/build_zh_locale.py @@ -28,6 +28,9 @@ LOCALE_CFG = "10002 936 zh\n" DEFAULT_NAMES = REPO / "data/zh_40250" FORMAT = re.compile(r"%(?:\([^)]*\))?[-+#0 ]*\d*(?:\.\d+)?[diouxXeEfFgGcrs%]") KEYED_FILES = ("locale_game.txt", "locale_interface.txt") +# Image folders whose labels are drawn text (the character window's tabs and stat labels). Each is taken +# from Longju as a whole: its .sub files carry their own coordinates into the folder's atlas. +IMAGE_DIRS = ("ui/windows",) def keyed_lines(path: Path, encoding: str): @@ -166,6 +169,15 @@ def build(en: Path, zh: Path, output: Path, client_base: Path, if (zh / filename).is_file(): shutil.copyfile(zh / filename, locale_dir / filename) + for folder in IMAGE_DIRS: + english_files = {path.name for path in (en / folder).iterdir()} + chinese_files = {path.name for path in (zh / folder).iterdir()} + if not english_files <= chinese_files: + raise ValueError(f"{folder}: Longju lacks {sorted(english_files - chinese_files)}") + for name in sorted(english_files): + shutil.copyfile(zh / folder / name, locale_dir / folder / name) + report["files"][folder] = {"replaced_images": len(english_files)} + if proto_tool is not None: if not proto_tool.is_file() or names_dir is None: raise ValueError("build locale_proto_patch and provide the Chinese name tables") diff --git a/scripts/test_build_zh_locale.py b/scripts/test_build_zh_locale.py index b187643f..faa1b233 100644 --- a/scripts/test_build_zh_locale.py +++ b/scripts/test_build_zh_locale.py @@ -26,6 +26,10 @@ class LocaleBuildTest(unittest.TestCase): (zh / "locale_interface.txt").write_bytes("ACCEPT\t确定\n".encode("gbk")) (en / "item_proto").write_bytes(b"40250-proto") (zh / "item_proto").write_bytes(b"old-proto") + for path, atlas in ((en, b"en-atlas"), (zh, b"zh-atlas")): + (path / "ui/windows").mkdir(parents=True) + (path / "ui/windows/windows.dds").write_bytes(atlas) + (zh / "ui/windows/zh_only.sub").write_bytes(b"sub") (client / "pack").mkdir() (client / "pack/Index").write_bytes(b"PACK\r\nlocale/de/\r\nlocale_de\r\nlocale/en/\r\nlocale_en\r\n") (client / "pack/locale_en.eix").write_bytes(b"en") @@ -41,6 +45,8 @@ class LocaleBuildTest(unittest.TestCase): self.assertIn("BAD\t%s at %d\tSA", merged) self.assertIn("ONLY_EN\tFallback", merged) self.assertEqual((staged / "item_proto").read_bytes(), b"40250-proto") + self.assertEqual((staged / "ui/windows/windows.dds").read_bytes(), b"zh-atlas") + self.assertFalse((staged / "ui/windows/zh_only.sub").exists()) self.assertEqual((output / "locale.cfg").read_text(), "10002 936 zh\n") self.assertEqual((output / "locale_zh.cfg").read_text(), "10002 936 zh\n") # A pack/ of its own: original packs linked, locale_zh packed from the staging dir and registered.