Skip to content

Commit b4629eb

Browse files
committed
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.
1 parent 8e479de commit b4629eb

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

roundup/scripts/roundup_gettext.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@
2222
# --/
2323

2424

25+
from roundup import configuration
2526
from roundup.cgi.TAL import talgettext
2627
from roundup.i18n import _
2728
from roundup.pygettext import TokenEater, make_escapes, tokenize
2829

2930
try:
3031
import polib
3132
except ImportError:
32-
print(_("\nExtracting translatable strings from html templates.\n"
33+
print(_("\nExtracting translatable strings only from html templates.\n"
3334
"Because the 'polib' module is missing, unable to extract\n"
3435
"translations from detectors or extensions.\n"
3536
"The 'polib' module can be installed with pip.\n"))
@@ -64,17 +65,17 @@ class Options:
6465
TEMPLATE_FILE = "messages.pot"
6566

6667

67-
# FIXME: html directory can be specified in config.ini. Should be
68-
# a parameter, or config.ini should be loaded.
6968
def run():
7069
# return unless command line arguments contain single directory path
7170
if (len(sys.argv) != 2) or (sys.argv[1] in ("-h", "--help")):
7271
print(_("Usage: %(program)s <tracker home>") %
7372
{"program": sys.argv[0]})
7473
return
75-
# collect file paths of html templates
74+
7675
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"]
7879
if os.path.isdir(htmldir):
7980
# glob is not used because i want to match file names
8081
# without case sensitivity, and that is easier done this way.
@@ -85,17 +86,21 @@ def run():
8586
htmlfiles = []
8687
# return if no html files found
8788
if not htmlfiles:
88-
print(_("No tracker templates found in directory %s") % home)
89+
print(_("No tracker templates found in directory %s") % htmldir)
8990
return
9091
# change to locale dir to have relative source references
9192
locale = os.path.join(home, "locale")
9293
if not os.path.isdir(locale):
9394
os.mkdir(locale)
9495
os.chdir(locale)
96+
97+
# compute relative path to template directory from locale directory
98+
relpath = os.path.relpath(htmldir)
99+
95100
# tweak sys.argv as this is the only way to tell talgettext what to do
96101
# Note: unix-style paths used instead of os.path.join deliberately
97102
sys.argv[1:] = ["-o", TEMPLATE_FILE] \
98-
+ ["../html/" + filename for filename in htmlfiles]
103+
+ [relpath + "/" + filename for filename in htmlfiles]
99104
# run
100105
talgettext.main()
101106

0 commit comments

Comments
 (0)