From 1fa722ae1763421c87c74b140bfe2dc3e48cea67 Mon Sep 17 00:00:00 2001 From: Yifan Liu Date: Sat, 11 Feb 2023 22:28:54 -0600 Subject: [PATCH] chore: update overseas clients tools add a new tool to help locate untranslated texts in json minor updates to the old ones rename files so that they are more intuitive --- tools/OverseasClients/.gitignore | 2 + .../FindMissingJsonTranslate.py | 90 +++++++++++++++++++ .../FindMissingTemplates.py} | 39 ++++---- .../SortJsonByZHServerOrder.py} | 0 .../ignore_list_of_templates.txt} | 0 .../test.json | 0 tools/global_servers/.gitignore | 1 - 7 files changed, 115 insertions(+), 17 deletions(-) create mode 100644 tools/OverseasClients/.gitignore create mode 100644 tools/OverseasClients/FindMissingJsonTranslate.py rename tools/{global_servers/diff_resource.py => OverseasClients/FindMissingTemplates.py} (76%) rename tools/{global_servers/match_json.py => OverseasClients/SortJsonByZHServerOrder.py} (100%) rename tools/{global_servers/ignore_list.txt => OverseasClients/ignore_list_of_templates.txt} (100%) rename tools/{global_servers => OverseasClients}/test.json (100%) delete mode 100644 tools/global_servers/.gitignore diff --git a/tools/OverseasClients/.gitignore b/tools/OverseasClients/.gitignore new file mode 100644 index 0000000000..c96976224f --- /dev/null +++ b/tools/OverseasClients/.gitignore @@ -0,0 +1,2 @@ +diff_image/ +missing* \ No newline at end of file diff --git a/tools/OverseasClients/FindMissingJsonTranslate.py b/tools/OverseasClients/FindMissingJsonTranslate.py new file mode 100644 index 0000000000..62b7381357 --- /dev/null +++ b/tools/OverseasClients/FindMissingJsonTranslate.py @@ -0,0 +1,90 @@ +import json +import os +import sys +import re + +# NOTE +# You may customize here +regex_ignore_list = [ + "Mizuki", + "SSS", + "Reclamation", + "Rogue" +] + +server_list = [ + "YoStarJP", + "YoStarEN", + "YoStarKR", + "txwy" +] + +# Get the server name from argument +try: + # server_name = "YoStarJP" + server_name = sys.argv[1] + if server_name not in server_list: + raise +except Exception: + server_name = None + while (not server_name): + print("Enter one and only one server name:", + ", ".join(server_list)) + t = input() + server_name = t if t in server_list else None + +output_file = "missing_translate-" + server_name + ".txt" + +cur_dir = os.path.dirname(os.path.abspath(__file__)) +proj_dir = os.path.join(cur_dir, "../../") +output_file = os.path.join(cur_dir, output_file) + +# File name of the json +# NOTE: You may change this to e.g. recruitment.json +# This is hardcoded because tasks.json is the most likely modified one +json_name = "tasks.json" + +zh_json_file = os.path.join(proj_dir, "resource/", json_name) +gl_json_file = os.path.join(proj_dir, "resource/global/", + server_name, "resource/", json_name) + +# For test purpose +# gl_json_file = os.path.join(cur_dir, "test.json") + +with open(zh_json_file, 'r', encoding='utf-8') as zh_fh: + zh_json: dict = json.load(zh_fh) + +with open(gl_json_file, 'r', encoding='utf-8') as gl_fh: + gl_json: dict = json.load(gl_fh) + +# def getBaseTask(task: dict) -> dict: +# try: +# base_task = zh_json[task["base_task"]] +# return getBaseTask(base_task) +# except: +# return task + +res_keys = [] +for key, value in zh_json.items(): + value: dict + # check if it has a "text" and if the text is empty + if value.get("text"): + # and then check if gl_json has a corresponding one + try: + _ = gl_json[key]["text"][0] + except: + if any(map(lambda x: re.search(x, key), regex_ignore_list)): + continue + # NOTE + # It is likely that Ascii texts do not need a translation but there is no guarantee. + # You may want to comment this out in some cases. + # if getBaseTask(value).get("isAscii", False) is True: + if all(map(str.isascii, value["text"])): + continue + + res_keys.append(key + ': ' + ', '.join(value["text"])) + + print(key, value["text"]) + +with open(output_file, 'w', encoding='utf-8') as f: + f.write('\n'.join(res_keys)) diff --git a/tools/global_servers/diff_resource.py b/tools/OverseasClients/FindMissingTemplates.py similarity index 76% rename from tools/global_servers/diff_resource.py rename to tools/OverseasClients/FindMissingTemplates.py index db7973bf92..35042eb30a 100644 --- a/tools/global_servers/diff_resource.py +++ b/tools/OverseasClients/FindMissingTemplates.py @@ -16,18 +16,29 @@ # 1. Install Python # 2. Run "$python diff_resource.py xxx" in the terminal where xxx is the desired # server name i.e. YoStarJP/YoStarEN/YoStarKR/txwy -# 3. Results can be found in the diff_image folder +# 3. Results can be found in the missing_templates folder # import os import sys import shutil +import re +# NOTE # Put the file names of text-less images (so that global servers use the same # image as the ZH (ZH_CN) server does) in this file. # Note you have to manually update the content of this file. -ignore_list_file_name = "ignore_list.txt" +ignore_list_file_name = "ignore_list_of_templates.txt" + +# NOTE +# You may customize here +regex_ignore_list = [ + "Mizuki", + "SSS", + "Reclamation", + "Rogue" +] server_list = [ "YoStarJP", @@ -67,27 +78,23 @@ with open(os.path.join(cur_dir, ignore_list_file_name)) as f: ignore_files = [line.rstrip('\n') for line in f] # ZH server pics not found in global server nor ignored will be filtered here -diff_files = [i for i in zh_files if - - # NOTE: You May Customize Here - # not i.startswith("Mizuki@Roguelike") and - "Rogue" not in i and - - i not in gl_files and - i not in ignore_files +diff_files = [f for f in zh_files if + not any(map(lambda x: re.search(x, f), regex_ignore_list)) and + f not in gl_files and + f not in ignore_files ] -# These pictures will be copied to the diff_image folder for reference. +# These pictures will be copied to the missing_templates folder for reference. # Contributors of global servers may screenshot the corresponding files. # Note this folder is in .gitignore so it will not be uploaded. -out_dir = os.path.join(cur_dir, "diff_image/", server_name) +out_dir = os.path.join(cur_dir, "missing_templates/", server_name) if os.path.exists(out_dir): shutil.rmtree(out_dir) os.makedirs(out_dir) -for i in diff_files: - # print(i) - shutil.copyfile(os.path.join(zh_dir, i), os.path.join(out_dir, i)) +for f in diff_files: + # print(f) + shutil.copyfile(os.path.join(zh_dir, f), os.path.join(out_dir, f)) print("Pictures not included in", server_name, - "server resources is copied to diff_image/" + server_name) + "server resources is copied to missing_templates/" + server_name) diff --git a/tools/global_servers/match_json.py b/tools/OverseasClients/SortJsonByZHServerOrder.py similarity index 100% rename from tools/global_servers/match_json.py rename to tools/OverseasClients/SortJsonByZHServerOrder.py diff --git a/tools/global_servers/ignore_list.txt b/tools/OverseasClients/ignore_list_of_templates.txt similarity index 100% rename from tools/global_servers/ignore_list.txt rename to tools/OverseasClients/ignore_list_of_templates.txt diff --git a/tools/global_servers/test.json b/tools/OverseasClients/test.json similarity index 100% rename from tools/global_servers/test.json rename to tools/OverseasClients/test.json diff --git a/tools/global_servers/.gitignore b/tools/global_servers/.gitignore deleted file mode 100644 index 048ad76eaf..0000000000 --- a/tools/global_servers/.gitignore +++ /dev/null @@ -1 +0,0 @@ -diff_image/ \ No newline at end of file