forked from Mirrorlandia_minetest/minetest
Fix translation updater script: Handle nested modpacks, support games (#14340)
This commit is contained in:
parent
83f779c52d
commit
4859cf44ce
@ -166,16 +166,9 @@ def get_modname(folder):
|
|||||||
if match:
|
if match:
|
||||||
return match.group(1)
|
return match.group(1)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
if not os.path.isfile(os.path.join(folder, "modpack.txt")):
|
|
||||||
folder_name = os.path.basename(folder)
|
folder_name = os.path.basename(folder)
|
||||||
# Special case when run in Minetest's builtin directory
|
# Special case when run in Minetest's builtin directory
|
||||||
if folder_name == "builtin":
|
return "__builtin" if folder_name == "builtin" else folder_name
|
||||||
return "__builtin"
|
|
||||||
else:
|
|
||||||
return folder_name
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
return None
|
|
||||||
|
|
||||||
# If there are already .tr files in /locale, returns a list of their names
|
# If there are already .tr files in /locale, returns a list of their names
|
||||||
def get_existing_tr_files(folder):
|
def get_existing_tr_files(folder):
|
||||||
@ -463,8 +456,11 @@ def update_tr_file(dNew, mod_name, tr_file):
|
|||||||
|
|
||||||
# Updates translation files for the mod in the given folder
|
# Updates translation files for the mod in the given folder
|
||||||
def update_mod(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)
|
modname = get_modname(folder)
|
||||||
if modname is not None:
|
|
||||||
print(f"Updating translations for {modname}")
|
print(f"Updating translations for {modname}")
|
||||||
data = generate_template(folder, modname)
|
data = generate_template(folder, modname)
|
||||||
if data == None:
|
if data == None:
|
||||||
@ -472,18 +468,20 @@ def update_mod(folder):
|
|||||||
else:
|
else:
|
||||||
for tr_file in get_existing_tr_files(folder):
|
for tr_file in get_existing_tr_files(folder):
|
||||||
update_tr_file(data, modname, os.path.join(folder, "locale/", tr_file))
|
update_tr_file(data, modname, os.path.join(folder, "locale/", tr_file))
|
||||||
else:
|
|
||||||
print(f"Unable to determine the mod name in folder {folder}. Missing 'name' field in mod.conf.", file=_stderr)
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
# Determines if the folder being pointed to is a mod or a mod pack
|
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 game, mod or a mod pack
|
||||||
# and then runs update_mod accordingly
|
# and then runs update_mod accordingly
|
||||||
def update_folder(folder):
|
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_game(folder):
|
||||||
if is_modpack:
|
run_all_subfolders(os.path.join(folder, "mods"))
|
||||||
subfolders = [f.path for f in os.scandir(folder) if f.is_dir() and not f.name.startswith('.')]
|
elif is_modpack(folder):
|
||||||
for subfolder in subfolders:
|
run_all_subfolders(folder)
|
||||||
update_mod(subfolder)
|
|
||||||
else:
|
else:
|
||||||
update_mod(folder)
|
update_mod(folder)
|
||||||
print("Done.")
|
print("Done.")
|
||||||
|
Loading…
Reference in New Issue
Block a user