added basic nametranslations for global languages

This commit is contained in:
argoneus 2020-02-16 03:05:24 +01:00 committed by Gitea
parent 057273552b
commit 9b998704e2

View file

@ -10,13 +10,24 @@ from multiprocessing import Pool
def update_names(dir_in, old_path, languages, is_global):
names = extract_names(dir_in)
names = extract_names(dir_in, is_global)
global_languages = {"enm": 1, "zh": 2, "ko": 3}
if is_global:
languages = global_languages.keys()
# we have to update japanese like the rest because CustomData exists
# and POKELABO deleted the wedding gear event stuff from the game files
for l in languages:
if l == "jpn":
out_dict = dict(zip(names, names))
elif l in global_languages.keys():
out_dict = {}
for name in names:
spl = name.split("\t")
idx = global_languages[l]
val = spl[idx] if spl[idx] != "None" else ""
out_dict[spl[0]] = val
else:
out_dict = dict.fromkeys(names, "")
@ -34,13 +45,13 @@ def update_names(dir_in, old_path, languages, is_global):
)
def extract_names(dir_in):
def extract_names(dir_in, is_global):
char_tsv_path = os.path.join(dir_in, "Diva", "Settings", "Character.tsv")
if not os.path.isfile(char_tsv_path):
raise FileNotFoundError("Character.tsv not found")
names, sets = read_char_tsv(char_tsv_path)
names, sets = read_char_tsv(char_tsv_path, is_global)
files = [
f
@ -50,6 +61,8 @@ def extract_names(dir_in):
if len(files) == 0:
raise FileNotFoundError("No valid files found in directory: " + dir_in)
# TODO unsupported on global for now
if not is_global:
# tfw gil
# it's still faster on my machine so i'm keeping it
read_partial = partial(read_mission, char_names=names, char_sets=sets)
@ -61,7 +74,7 @@ def extract_names(dir_in):
return names
def read_char_tsv(char_tsv_path):
def read_char_tsv(char_tsv_path, is_global):
char_names = set()
char_sets = set()
@ -77,6 +90,11 @@ def read_char_tsv(char_tsv_path):
and row["CharacterName"].strip()
and row["NameText"].strip()
):
if is_global:
char_names.add(
f"{row['NameText']}\t{row['CharaEnglish']}\t{row['CharaChinese']}\t{row['CharaKorean']}"
)
else:
char_names.add(row["NameText"])
char_sets.add(row["CharacterName"])