Mercurial > p > roundup > code
annotate roundup/scripts/roundup_gettext.py @ 8080:d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
Enhance roundup_gettext.py to extract strings from
detectors/extensions. If the polib module is available,
roundup-gettext will extract translatable strings from the tracker's
Python code. If polib is missing, it will print a warning.
Marcus did most of the work, I had to do a python 2-> conversion of
pygettext.py.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sat, 13 Jul 2024 18:27:11 -0400 |
| parents | 32a5a54536b5 |
| children | 2943140f5286 |
| rev | line source |
|---|---|
|
2803
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
1 #! /usr/bin/env python |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
2 # |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
3 # Copyright 2004 Richard Jones (richard@mechanicalcat.net) |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
4 |
|
8080
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
5 """Extract translatable strings from tracker templates and detectors/extensions""" |
|
2803
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
6 |
|
5376
64b05e24dbd8
Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4766
diff
changeset
|
7 from __future__ import print_function |
|
2803
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
8 import os |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
9 import sys |
|
8080
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
10 import tempfile |
|
4766
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
11 |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
12 # --- patch sys.path to make sure 'import roundup' finds correct version |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
13 import os.path as osp |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
14 |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
15 thisdir = osp.dirname(osp.abspath(__file__)) |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
16 rootdir = osp.dirname(osp.dirname(thisdir)) |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
17 if (osp.exists(thisdir + '/__init__.py') and |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
18 osp.exists(rootdir + '/roundup/__init__.py')): |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
19 # the script is located inside roundup source code |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
20 sys.path.insert(0, rootdir) |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
21 # --/ |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
22 |
|
86ef4ab17dc5
Run scripts (roundup_admin.py, ...) directly from checkout.
anatoly techtonik <techtonik@gmail.com>
parents:
4570
diff
changeset
|
23 |
|
2803
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
24 from roundup.i18n import _ |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
25 from roundup.cgi.TAL import talgettext |
|
8080
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
26 from roundup.pygettext import make_escapes, TokenEater, tokenize |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
27 |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
28 try: |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
29 import polib |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
30 except ImportError: |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
31 print(_("\nExtracting translatable strings from html templates.\n" |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
32 "Because the 'polib' module is missing, unable to extract\n" |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
33 "translations from detectors or extensions.\n" |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
34 "The 'polib' module can be installed with pip.\n")) |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
35 polib = None |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
36 |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
37 # from pygettext's main(): |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
38 class Options: |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
39 # constants |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
40 GNU = 1 |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
41 SOLARIS = 2 |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
42 # defaults |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
43 extractall = 0 # FIXME: currently this option has no effect at all. |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
44 escape = 0 |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
45 keywords = ["_", "gettext", "ngettext", "ugettext"] |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
46 outpath = '' |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
47 outfile = '' |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
48 writelocations = 1 |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
49 locationstyle = GNU |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
50 verbose = 0 |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
51 width = 10 |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
52 excludefilename = '' |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
53 docstrings = 0 |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
54 nodocstrings = {} |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
55 toexclude = [] # TODO we should exclude all strings already found in some template |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
56 |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
57 tokeneater_options = Options() |
|
2803
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
58 |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
59 # name of message template file. |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
60 # i don't think this will ever need to be changed, but still... |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
61 TEMPLATE_FILE = "messages.pot" |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
62 |
| 6044 | 63 |
|
2803
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
64 def run(): |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
65 # return unless command line arguments contain single directory path |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
66 if (len(sys.argv) != 2) or (sys.argv[1] in ("-h", "--help")): |
| 6044 | 67 print(_("Usage: %(program)s <tracker home>") % |
| 68 {"program": sys.argv[0]}) | |
|
2803
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
69 return |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
70 # collect file paths of html templates |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
71 home = os.path.abspath(sys.argv[1]) |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
72 htmldir = os.path.join(home, "html") |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
73 if os.path.isdir(htmldir): |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
74 # glob is not used because i want to match file names |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
75 # without case sensitivity, and that is easier done this way. |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
76 htmlfiles = [filename for filename in os.listdir(htmldir) |
| 6044 | 77 if os.path.isfile(os.path.join(htmldir, filename)) |
| 78 and filename.lower().endswith(".html")] | |
|
2803
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
79 else: |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
80 htmlfiles = [] |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
81 # return if no html files found |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
82 if not htmlfiles: |
|
5376
64b05e24dbd8
Python 3 preparation: convert print to a function.
Joseph Myers <jsm@polyomino.org.uk>
parents:
4766
diff
changeset
|
83 print(_("No tracker templates found in directory %s") % home) |
|
2803
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
84 return |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
85 # change to locale dir to have relative source references |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
86 locale = os.path.join(home, "locale") |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
87 if not os.path.isdir(locale): |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
88 os.mkdir(locale) |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
89 os.chdir(locale) |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
90 # tweak sys.argv as this is the only way to tell talgettext what to do |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
91 # Note: unix-style paths used instead of os.path.join deliberately |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
92 sys.argv[1:] = ["-o", TEMPLATE_FILE] \ |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
93 + ["../html/" + filename for filename in htmlfiles] |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
94 # run |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
95 talgettext.main() |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
96 |
|
8080
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
97 if not polib: |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
98 return |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
99 |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
100 # we have now everything from the templates in the TEMPLATE_FILE |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
101 # now we search in home/detectors and home/extensions *.py files for |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
102 # tokeneater_options.keywords |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
103 # this is partly assembled from pygettext's main() |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
104 make_escapes(not tokeneater_options.escape) |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
105 |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
106 pyfiles = [] |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
107 for source in ["detectors", "extensions"] : |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
108 for root, dirs, files in os.walk (os.path.join ("..", source)) : |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
109 pyfiles.extend ([os.path.join (root, f) for f in files if f.endswith (".py")]) |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
110 |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
111 eater = TokenEater (tokeneater_options) |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
112 |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
113 for filename in pyfiles : |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
114 eater.set_filename (filename) |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
115 with open (filename, "r") as f: |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
116 try: |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
117 for token in tokenize.generate_tokens(f.readline): |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
118 eater(*token) |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
119 except tokenize.TokenError as e: |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
120 print('%s: %s, line %d, column %d' % ( |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
121 e[0], filename, e[1][0], e[1][1]), file=sys.stderr) |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
122 |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
123 with tempfile.NamedTemporaryFile("w") as tf : |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
124 eater.write(tf) |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
125 tf.seek (0) |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
126 p1 = polib.pofile(TEMPLATE_FILE) |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
127 p2 = polib.pofile(tf.name) |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
128 |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
129 p2_msg_ids = set([e.msgid for e in p2]) |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
130 for e in p1 : |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
131 if e.msgid in p2_msg_ids : |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
132 p2_e = p2.find (e.msgid) |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
133 e.occurrences.extend (p2_e.occurrences) |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
134 p2_msg_ids.remove (e.msgid) |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
135 |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
136 for msgid in p2_msg_ids : |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
137 p1.append (p2.find (msgid)) |
|
d1c29284ccd9
feat: issue2551287 - roundup-gettext extracts strings from detectors/extensions
John Rouillard <rouilj@ieee.org>
parents:
6044
diff
changeset
|
138 p1.save () |
| 6044 | 139 |
|
2803
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
140 if __name__ == "__main__": |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
141 run() |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
142 |
|
a7b755646ffd
Extract translatable strings from tracker templates
Alexander Smishlajev <a1s@users.sourceforge.net>
parents:
diff
changeset
|
143 # vim: set et sts=4 sw=4 : |
