Skip to content

Commit

Permalink
Fix translation updater script: Handle nested modpacks, support games (
Browse files Browse the repository at this point in the history
  • Loading branch information
appgurueu committed Feb 5, 2024
1 parent 83f779c commit 4859cf4
Showing 1 changed file with 24 additions and 26 deletions.
50 changes: 24 additions & 26 deletions util/mod_translation_updater.py
Expand Up @@ -166,16 +166,9 @@ def get_modname(folder):
if match:
return match.group(1)
except FileNotFoundError:
if not os.path.isfile(os.path.join(folder, "modpack.txt")):
folder_name = os.path.basename(folder)
# Special case when run in Minetest's builtin directory
if folder_name == "builtin":
return "__builtin"
else:
return folder_name
else:
return None
return None
folder_name = os.path.basename(folder)
# Special case when run in Minetest's builtin directory
return "__builtin" if folder_name == "builtin" else folder_name

# If there are already .tr files in /locale, returns a list of their names
def get_existing_tr_files(folder):
Expand Down Expand Up @@ -463,27 +456,32 @@ def update_tr_file(dNew, mod_name, tr_file):

# Updates translation files for the mod in the given folder
def update_mod(folder):
if not os.path.exists(os.path.join(folder, "init.lua")):
print(f"Mod folder {folder} is missing init.lua, aborting.")
exit(1)
assert not is_modpack(folder)
modname = get_modname(folder)
if modname is not None:
print(f"Updating translations for {modname}")
data = generate_template(folder, modname)
if data == None:
print(f"No translatable strings found in {modname}")
else:
for tr_file in get_existing_tr_files(folder):
update_tr_file(data, modname, os.path.join(folder, "locale/", tr_file))
print(f"Updating translations for {modname}")
data = generate_template(folder, modname)
if data == None:
print(f"No translatable strings found in {modname}")
else:
print(f"Unable to determine the mod name in folder {folder}. Missing 'name' field in mod.conf.", file=_stderr)
exit(1)
for tr_file in get_existing_tr_files(folder):
update_tr_file(data, modname, os.path.join(folder, "locale/", tr_file))

def is_modpack(folder):
return os.path.exists(os.path.join(folder, "modpack.txt")) or os.path.exists(os.path.join(folder, "modpack.conf"))

def is_game(folder):
return os.path.exists(os.path.join(folder, "game.conf")) and os.path.exists(os.path.join(folder, "mods"))

# Determines if the folder being pointed to is a mod or a mod pack
# Determines if the folder being pointed to is a game, mod or a mod pack
# and then runs update_mod accordingly
def update_folder(folder):
is_modpack = os.path.exists(os.path.join(folder, "modpack.txt")) or os.path.exists(os.path.join(folder, "modpack.conf"))
if is_modpack:
subfolders = [f.path for f in os.scandir(folder) if f.is_dir() and not f.name.startswith('.')]
for subfolder in subfolders:
update_mod(subfolder)
if is_game(folder):
run_all_subfolders(os.path.join(folder, "mods"))
elif is_modpack(folder):
run_all_subfolders(folder)
else:
update_mod(folder)
print("Done.")
Expand Down

0 comments on commit 4859cf4

Please sign in to comment.