Skip to content

Commit

Permalink
now the temporary output file is inthe target language
Browse files Browse the repository at this point in the history
  • Loading branch information
Anis committed Nov 29, 2024
1 parent c527564 commit d78cbd4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
1 change: 0 additions & 1 deletion compare_tools/compare_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def compare_configs(cfg_previous: str, cfg_new: str):
elif type(cfg_new) is Mod:
cfg_new = cfg_new.download_locale_en(store=False)
cfg_new = parse_config(cfg_new, is_file=False)
print(cfg_new)

# Find sections or keys that have changed, were added, or removed

Expand Down
20 changes: 13 additions & 7 deletions compare_tools/format_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
}


def format_output(config_json, mod):
def format_output(config_json, mod, language):
config_out = ConfigParser()
config_ret = ConfigParser()
config_lang = ConfigParser()
config_lang.read(mod.path / f"locale/{language}/locale.cfg")

added_sections = config_json["added_sections"]
removed_sections = config_json["removed_sections"]
Expand All @@ -24,7 +26,7 @@ def format_output(config_json, mod):
path = "output/" + mod.name + "/locale.cfg"
if not os.path.exists("output/" + mod.name):
os.makedirs("output/" + mod.name)

with open(path, "w+") as f:
# added_sections
for sections in "added_sections", "removed_sections":
Expand All @@ -35,8 +37,11 @@ def format_output(config_json, mod):
config_ret.add_section(section_name)

for key, value in section.items():
config_out.set(section_name, key, value)
config_ret.set(section_name, key, value)
config_out.set(section_name, key,
config_lang[section_name][kk])
config_ret.set(section_name, key,
config_lang[section_name][kk])

config_out.write(f)
config_out = ConfigParser()
f.write("#######################################\n")
Expand All @@ -59,8 +64,10 @@ def format_output(config_json, mod):
if sub_key == "modified_keys":
# it is written as "from", "to" keys
vv = vv["to"]
config_out.set(section_name, kk, vv)
config_ret.set(section_name, kk, vv)
config_out.set(section_name, kk,
config_lang[section_name][kk])
config_ret.set(section_name, kk,
config_lang[section_name][kk])

config_out.write(f)
config_out = ConfigParser()
Expand All @@ -76,7 +83,6 @@ def format_output(config_json, mod):
mod = Mod(args.mod_url)
path_previous = mod.path_en / "locale.cfg"
path_new = mod.path / "locale/fr/locale.cfg"
# path_new = mod.download_locale_en()

diff = compare_configs(path_previous, path_new)
format_output(diff, mod)
9 changes: 5 additions & 4 deletions compare_tools/init_mod_translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@

from Mod import Mod


def init_mod(mod_repo_url, overwrite=False):
mod = Mod(mod_repo_url)
if os.path.exists(mod.path) and not overwrite:
raise FileExistsError("Mod folder already exists in repository. Use --f to overwrite.")
raise FileExistsError(
"Mod folder already exists in repository. Use --f to overwrite.")

os.makedirs(mod.path_en, exist_ok=overwrite)
mod.download_locale_en()

print(f"Locale File downloaded for {mod.name} by {mod.owner}. Ready to translate!")

print(
f"Locale File downloaded for {mod.name} by {mod.owner}. Ready to translate!")
return mod


Expand Down
3 changes: 1 addition & 2 deletions mod_translate_track.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ def main(url: str, language: str):
mod = Mod.Mod(url)
diff = compare_configs.compare_configs(
mod.path_en/"locale.cfg", mod)
# TODO: I am using local EN vs Language. I need to use remote EN vs locale EN AND output it in LANGUAGE
format_output.format_output(diff, mod)
format_output.format_output(diff, mod, language)


if __name__ == "__main__":
Expand Down

0 comments on commit d78cbd4

Please sign in to comment.