Mercurial > p > roundup > code
comparison roundup/scripts/roundup_gettext.py @ 8089:f2b049b49fca
fix: replace hardcoded 'html' as template directory
Template directory is now determined by loading the config file from
the tracker home and using the template setting.
Also fixed error message when polib import fails to indicate
extraction is only from thml templates.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Tue, 16 Jul 2024 01:28:15 -0400 |
| parents | 1045425c23b2 |
| children | 586f76eb33e8 |
comparison
equal
deleted
inserted
replaced
| 8088:1045425c23b2 | 8089:f2b049b49fca |
|---|---|
| 20 # the script is located inside roundup source code | 20 # the script is located inside roundup source code |
| 21 sys.path.insert(0, rootdir) | 21 sys.path.insert(0, rootdir) |
| 22 # --/ | 22 # --/ |
| 23 | 23 |
| 24 | 24 |
| 25 from roundup import configuration | |
| 25 from roundup.cgi.TAL import talgettext | 26 from roundup.cgi.TAL import talgettext |
| 26 from roundup.i18n import _ | 27 from roundup.i18n import _ |
| 27 from roundup.pygettext import TokenEater, make_escapes, tokenize | 28 from roundup.pygettext import TokenEater, make_escapes, tokenize |
| 28 | 29 |
| 29 try: | 30 try: |
| 30 import polib | 31 import polib |
| 31 except ImportError: | 32 except ImportError: |
| 32 print(_("\nExtracting translatable strings from html templates.\n" | 33 print(_("\nExtracting translatable strings only from html templates.\n" |
| 33 "Because the 'polib' module is missing, unable to extract\n" | 34 "Because the 'polib' module is missing, unable to extract\n" |
| 34 "translations from detectors or extensions.\n" | 35 "translations from detectors or extensions.\n" |
| 35 "The 'polib' module can be installed with pip.\n")) | 36 "The 'polib' module can be installed with pip.\n")) |
| 36 polib = None | 37 polib = None |
| 37 | 38 |
| 62 # name of message template file. | 63 # name of message template file. |
| 63 # i don't think this will ever need to be changed, but still... | 64 # i don't think this will ever need to be changed, but still... |
| 64 TEMPLATE_FILE = "messages.pot" | 65 TEMPLATE_FILE = "messages.pot" |
| 65 | 66 |
| 66 | 67 |
| 67 # FIXME: html directory can be specified in config.ini. Should be | |
| 68 # a parameter, or config.ini should be loaded. | |
| 69 def run(): | 68 def run(): |
| 70 # return unless command line arguments contain single directory path | 69 # return unless command line arguments contain single directory path |
| 71 if (len(sys.argv) != 2) or (sys.argv[1] in ("-h", "--help")): | 70 if (len(sys.argv) != 2) or (sys.argv[1] in ("-h", "--help")): |
| 72 print(_("Usage: %(program)s <tracker home>") % | 71 print(_("Usage: %(program)s <tracker home>") % |
| 73 {"program": sys.argv[0]}) | 72 {"program": sys.argv[0]}) |
| 74 return | 73 return |
| 75 # collect file paths of html templates | 74 |
| 76 home = os.path.abspath(sys.argv[1]) | 75 home = os.path.abspath(sys.argv[1]) |
| 77 htmldir = os.path.join(home, "html") | 76 # collect file paths of html templates from config |
| 77 config = configuration.CoreConfig(home) | |
| 78 htmldir = config["TEMPLATES"] | |
| 78 if os.path.isdir(htmldir): | 79 if os.path.isdir(htmldir): |
| 79 # glob is not used because i want to match file names | 80 # glob is not used because i want to match file names |
| 80 # without case sensitivity, and that is easier done this way. | 81 # without case sensitivity, and that is easier done this way. |
| 81 htmlfiles = [e.name for e in os.scandir(htmldir) | 82 htmlfiles = [e.name for e in os.scandir(htmldir) |
| 82 if e.is_file() | 83 if e.is_file() |
| 83 and e.name.lower().endswith(".html")] | 84 and e.name.lower().endswith(".html")] |
| 84 else: | 85 else: |
| 85 htmlfiles = [] | 86 htmlfiles = [] |
| 86 # return if no html files found | 87 # return if no html files found |
| 87 if not htmlfiles: | 88 if not htmlfiles: |
| 88 print(_("No tracker templates found in directory %s") % home) | 89 print(_("No tracker templates found in directory %s") % htmldir) |
| 89 return | 90 return |
| 90 # change to locale dir to have relative source references | 91 # change to locale dir to have relative source references |
| 91 locale = os.path.join(home, "locale") | 92 locale = os.path.join(home, "locale") |
| 92 if not os.path.isdir(locale): | 93 if not os.path.isdir(locale): |
| 93 os.mkdir(locale) | 94 os.mkdir(locale) |
| 94 os.chdir(locale) | 95 os.chdir(locale) |
| 96 | |
| 97 # compute relative path to template directory from locale directory | |
| 98 relpath = os.path.relpath(htmldir) | |
| 99 | |
| 95 # tweak sys.argv as this is the only way to tell talgettext what to do | 100 # tweak sys.argv as this is the only way to tell talgettext what to do |
| 96 # Note: unix-style paths used instead of os.path.join deliberately | 101 # Note: unix-style paths used instead of os.path.join deliberately |
| 97 sys.argv[1:] = ["-o", TEMPLATE_FILE] \ | 102 sys.argv[1:] = ["-o", TEMPLATE_FILE] \ |
| 98 + ["../html/" + filename for filename in htmlfiles] | 103 + [relpath + "/" + filename for filename in htmlfiles] |
| 99 # run | 104 # run |
| 100 talgettext.main() | 105 talgettext.main() |
| 101 | 106 |
| 102 if not polib: | 107 if not polib: |
| 103 return | 108 return |
