Locale updater script now updates PO files as well
This commit is contained in:
parent
07806f950d
commit
e26d40f23e
@ -24,8 +24,8 @@ You need:
|
|||||||
## Part 1: Pushing the translations from the game to Weblate:
|
## Part 1: Pushing the translations from the game to Weblate:
|
||||||
|
|
||||||
1. Clean up: Make sure the game repository is in a clean state (no non-committed changes)
|
1. Clean up: Make sure the game repository is in a clean state (no non-committed changes)
|
||||||
2. Update POT files: Run `update_locale_templates.py` in the root directory of this repositoryand commit the changes (if any)
|
2. Update POT files: Run `update_locale_files.py pot` in the root directory of this repository and commit the changes (if any)
|
||||||
3. Update PO files: TODO
|
3. Update PO files: Run `update_locale_files.py po` in the root directory of this repository and commit the changes (if any)
|
||||||
4. Push: Push the changes to the online repository of the game
|
4. Push: Push the changes to the online repository of the game
|
||||||
5. Update Weblate repository (optional): Weblate should soon automatically update its repository. But if you want to want the new strings to be available immediately, go to the project page, then “Manage > Repository Maintenance” and click “Update”
|
5. Update Weblate repository (optional): Weblate should soon automatically update its repository. But if you want to want the new strings to be available immediately, go to the project page, then “Manage > Repository Maintenance” and click “Update”
|
||||||
|
|
||||||
|
@ -3,11 +3,16 @@
|
|||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
##### ABOUT THIS SCRIPT ##################################################
|
##### ABOUT THIS SCRIPT ##################################################
|
||||||
# This script updates the translation template files (*.pot) of all mods
|
# This script updates the translation template files (*.pot) or
|
||||||
# by running the xgettext application.
|
# translation files (*.po) of all mods by using the gettext tools.
|
||||||
# It requires you have the 'gettext' software installed on your system.
|
# It requires you have the 'gettext' software installed on your system.
|
||||||
#
|
#
|
||||||
# Run this script, and the *.pot files will be updated.
|
# INVOCATION:
|
||||||
|
# ./update_locale_files.py [mode]
|
||||||
|
#
|
||||||
|
# where "mode" is either "pot" if you want to update the *.pot files
|
||||||
|
# or "po" if you want to update the *.po files. If "mode" is omitted,
|
||||||
|
# it defaults to "pot".
|
||||||
##########################################################################
|
##########################################################################
|
||||||
|
|
||||||
|
|
||||||
@ -19,11 +24,34 @@ PACKAGE_NAME = "Repixture"
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
# pattern for the 'name' in mod.conf
|
# pattern for the 'name' in mod.conf
|
||||||
pattern_name = re.compile(r'^name[ ]*=[ ]*([^ \n]*)')
|
pattern_name = re.compile(r'^name[ ]*=[ ]*([^ \n]*)')
|
||||||
# file name pattern for gettext translation template files (*.pot)
|
# file name pattern for gettext translation template files (*.pot)
|
||||||
pattern_pot = re.compile(r'(.*)\.pot$')
|
pattern_pot = re.compile(r'(.*)\.pot$')
|
||||||
|
# file name pattern for gettext translation files (*.po)
|
||||||
|
pattern_po = re.compile(r'(.*)\.po$')
|
||||||
|
|
||||||
|
def invoke_msgmerge(template_file, mod_folder, modname):
|
||||||
|
containing_path = os.path.dirname(template_file)
|
||||||
|
|
||||||
|
po_files = []
|
||||||
|
for root, dirs, files in os.walk(os.path.join(mod_folder)):
|
||||||
|
for f in files:
|
||||||
|
match = pattern_po.match(f)
|
||||||
|
if match:
|
||||||
|
po_files.append(f)
|
||||||
|
print(po_files)
|
||||||
|
if len(po_files) > 0:
|
||||||
|
for po_file in po_files:
|
||||||
|
po_file = os.path.join("locale", po_file)
|
||||||
|
po_file = os.path.join(mod_folder, po_file)
|
||||||
|
command = "msgmerge --backup=none -U '"+po_file+"' '"+template_file+"'"
|
||||||
|
return_value = os.system(command)
|
||||||
|
if return_value != 0:
|
||||||
|
print("ERROR: msgmerge invocation returned with "+str(return_value))
|
||||||
|
exit(1)
|
||||||
|
|
||||||
def invoke_xgettext(template_file, mod_folder, modname):
|
def invoke_xgettext(template_file, mod_folder, modname):
|
||||||
containing_path = os.path.dirname(template_file)
|
containing_path = os.path.dirname(template_file)
|
||||||
@ -43,14 +71,20 @@ def invoke_xgettext(template_file, mod_folder, modname):
|
|||||||
print("ERROR: xgettext invocation returned with "+str(return_value))
|
print("ERROR: xgettext invocation returned with "+str(return_value))
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
def update_locale_template(folder, modname):
|
def update_locale_template(folder, modname, mode):
|
||||||
for root, dirs, files in os.walk(os.path.join(folder, 'locale')):
|
for root, dirs, files in os.walk(os.path.join(folder, 'locale')):
|
||||||
for name in files:
|
for name in files:
|
||||||
code_match = pattern_pot.match(name)
|
code_match = pattern_pot.match(name)
|
||||||
if code_match == None:
|
if code_match == None:
|
||||||
continue
|
continue
|
||||||
fname = os.path.join(root, name)
|
fname = os.path.join(root, name)
|
||||||
|
if mode == "pot":
|
||||||
invoke_xgettext(fname, folder, modname)
|
invoke_xgettext(fname, folder, modname)
|
||||||
|
elif mode == "po":
|
||||||
|
invoke_msgmerge(fname, folder, modname)
|
||||||
|
else:
|
||||||
|
print("ERROR: invalid locale template mode!")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
def get_modname(folder):
|
def get_modname(folder):
|
||||||
try:
|
try:
|
||||||
@ -67,21 +101,30 @@ def get_modname(folder):
|
|||||||
return None
|
return None
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def update_mod(folder):
|
def update_mod(folder, mode):
|
||||||
modname = get_modname(folder)
|
modname = get_modname(folder)
|
||||||
if modname != None:
|
if modname != None:
|
||||||
print("Updating '"+modname+"' ...")
|
print("Updating '"+modname+"' ...")
|
||||||
update_locale_template(folder, modname)
|
update_locale_template(folder, modname, mode)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
mode = ""
|
||||||
|
if len(sys.argv) >= 2:
|
||||||
|
mode = sys.argv[1]
|
||||||
|
if mode == "":
|
||||||
|
mode = "pot"
|
||||||
|
if mode != "po" and mode != "pot":
|
||||||
|
print("ERROR: invalid mode specified. Provide either 'po', 'pot' or nothing as command line argument")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
for modfolder in [f.path for f in os.scandir("./mods") if f.is_dir() and not f.name.startswith('.')]:
|
for modfolder in [f.path for f in os.scandir("./mods") if f.is_dir() and not f.name.startswith('.')]:
|
||||||
is_modpack = os.path.exists(os.path.join(modfolder, "modpack.txt")) or os.path.exists(os.path.join(modfolder, "modpack.conf"))
|
is_modpack = os.path.exists(os.path.join(modfolder, "modpack.txt")) or os.path.exists(os.path.join(modfolder, "modpack.conf"))
|
||||||
if is_modpack:
|
if is_modpack:
|
||||||
subfolders = [f.path for f in os.scandir(modfolder) if f.is_dir() and not f.name.startswith('.')]
|
subfolders = [f.path for f in os.scandir(modfolder) if f.is_dir() and not f.name.startswith('.')]
|
||||||
for subfolder in subfolders:
|
for subfolder in subfolders:
|
||||||
update_mod(subfolder)
|
update_mod(subfolder, mode)
|
||||||
else:
|
else:
|
||||||
update_mod(modfolder)
|
update_mod(modfolder, mode)
|
||||||
print("All done.")
|
print("All done.")
|
||||||
|
|
||||||
main()
|
main()
|
Loading…
x
Reference in New Issue
Block a user