Debian Codegraph @

po/update_po.py

raw symbols SCIP
1 #! /usr/bin/env python3
2 #
3 # update_po - a gramps tool to update translations
4 #
5 # Copyright (C) 2006-2006 Kees Bakker
6 # Copyright (C) 2006 Brian Matherly
7 # Copyright (C) 2008 Stephen George
8 # Copyright (C) 2012
9 # Copyright (C) 2020 Nick Hall
10 #
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
15 #
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License along
22 # with this program; if not, see <https://www.gnu.org/licenses/>.
23 #
24
25 """
26 update_po.py for Gramps translations.
27
28 Examples:
29 python update_po.py -t
30
31 Tests if 'gettext' and 'python' are well configured.
32
33 python update_po.py -h
34
35 Calls help and command line interface.
36
37 python update_po.py -p
38
39 Generates a new template/catalog (gramps.pot).
40
41 python update_po.py -m de.po
42
43 Merges 'de.po' file with 'gramps.pot'.
44
45 python update_po.py -k de.po
46
47 Checks 'de.po' file, tests to compile and generates a textual resume.
48 """
49
50 from __future__scip-python python python-stdlib 3.11 __future__/__init__: import print_functionscip-python python python-stdlib 3.11 __future__/print_function.print_function.
51
52 import osscip-python python python-stdlib 3.11 os/__init__:
53 import sysscip-python python python-stdlib 3.11 sys/__init__:
54 import shutilscip-python python python-stdlib 3.11 shutil/__init__:
55 from argparsescip-python python python-stdlib 3.11 argparse/__init__: import ArgumentParserscip-python python python-stdlib 3.11 argparse/ArgumentParser#
56 from tokenizescip-python python python-stdlib 3.11 tokenize/__init__: import tokenizescip-python python python-stdlib 3.11 tokenize/tokenize()., STRINGscip-python python python-stdlib 3.11 token/STRING.STRING., COMMENTscip-python python python-stdlib 3.11 token/COMMENT.COMMENT., NLscip-python python python-stdlib 3.11 token/NL.NL., TokenErrorscip-python python python-stdlib 3.11 tokenize/TokenError#
57
58 # Windows OS
59
60 if sysscip-python python python-stdlib 3.11 sys/__init__:.platformscip-python python python-stdlib 3.11 sys/platform.platform. in ["linux", "linux2", "darwin", "cygwin"] or shutilscip-python python python-stdlib 3.11 shutil/__init__:.whichscip-python python python-stdlib 3.11 shutil/which().("msgmerge"):
61 msgmergeCmdscip-python python gramps 6.0.7 `po.update_po`/msgmergeCmd. = "msgmerge"
62 msgfmtCmdscip-python python gramps 6.0.7 `po.update_po`/msgfmtCmd. = "msgfmt"
63 msgattribCmdscip-python python gramps 6.0.7 `po.update_po`/msgattribCmd. = "msgattrib"
64 xgettextCmdscip-python python gramps 6.0.7 `po.update_po`/xgettextCmd. = "xgettext"
65 pythonCmdscip-python python gramps 6.0.7 `po.update_po`/pythonCmd. = osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..joinscip-python python python-stdlib 3.11 genericpath/exists().(sysscip-python python python-stdlib 3.11 sys/__init__:.prefixscip-python python python-stdlib 3.11 sys/prefix.prefix., "bin", "python3")
66 elif sysscip-python python python-stdlib 3.11 sys/__init__:.platformscip-python python python-stdlib 3.11 sys/platform.platform. == "win32":
67 # GetText Win 32 obtained from http://gnuwin32.sourceforge.net/packages/gettext.htm
68 # ....\gettext\bin\msgmerge.exe needs to be on the path
69 msgmergeCmdscip-python python gramps 6.0.7 `po.update_po`/msgmergeCmd. = osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..joinscip-python python python-stdlib 3.11 genericpath/exists().(
70 "C:", "Program Files(x86)", "gettext", "bin", "msgmerge.exe"
71 )
72 msgfmtCmdscip-python python gramps 6.0.7 `po.update_po`/msgfmtCmd. = osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..joinscip-python python python-stdlib 3.11 genericpath/exists().("C:", "Program Files(x86)", "gettext", "bin", "msgfmt.exe")
73 msgattribCmdscip-python python gramps 6.0.7 `po.update_po`/msgattribCmd. = osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..joinscip-python python python-stdlib 3.11 genericpath/exists().(
74 "C:", "Program Files(x86)", "gettext", "bin", "msgattrib.exe"
75 )
76 xgettextCmdscip-python python gramps 6.0.7 `po.update_po`/xgettextCmd. = osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..joinscip-python python python-stdlib 3.11 genericpath/exists().(
77 "C:", "Program Files(x86)", "gettext", "bin", "xgettext.exe"
78 )
79 pythonCmdscip-python python gramps 6.0.7 `po.update_po`/pythonCmd. = osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..joinscip-python python python-stdlib 3.11 genericpath/exists().(sysscip-python python python-stdlib 3.11 sys/__init__:.prefixscip-python python python-stdlib 3.11 sys/prefix.prefix., "bin", "python.exe")
80
81 # Others OS
82
83 elif sysscip-python python python-stdlib 3.11 sys/__init__:.platformscip-python python python-stdlib 3.11 sys/platform.platform. in ["linux", "linux2", "darwin", "cygwin"]:
84 msgmergeCmdscip-python python gramps 6.0.7 `po.update_po`/msgmergeCmd. = "msgmerge"
85 msgfmtCmdscip-python python gramps 6.0.7 `po.update_po`/msgfmtCmd. = "msgfmt"
86 msgattribCmdscip-python python gramps 6.0.7 `po.update_po`/msgattribCmd. = "msgattrib"
87 xgettextCmdscip-python python gramps 6.0.7 `po.update_po`/xgettextCmd. = "xgettext"
88 pythonCmdscip-python python gramps 6.0.7 `po.update_po`/pythonCmd. = osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..joinscip-python python python-stdlib 3.11 genericpath/exists().(sysscip-python python python-stdlib 3.11 sys/__init__:.prefixscip-python python python-stdlib 3.11 sys/prefix.prefix., "bin", "python3")
89 else:
90 printscip-python python python-stdlib 3.11 builtins/print().("Found platform %s, OS %s" % (sysscip-python python python-stdlib 3.11 sys/__init__:.platformscip-python python python-stdlib 3.11 sys/platform.platform., osscip-python python python-stdlib 3.11 os/__init__:.namescip-python python python-stdlib 3.11 os/name.name.))
91 printscip-python python python-stdlib 3.11 builtins/print().("Update PO ERROR: unknown system, don't know msgmerge, ... commands")
92 sysscip-python python python-stdlib 3.11 sys/__init__:.exit(0)
93
94 # List of available languages, useful for grouped actions
95
96 # need files with po extension
97 LANGscip-python python gramps 6.0.7 `po.update_po`/LANG. = [file for file in osscip-python python python-stdlib 3.11 os/__init__:.listdirscip-python python python-stdlib 3.11 os/listdir().(".") if file.endswithscip-python python python-stdlib 3.11 builtins/str#endswith().(".po")]
98 # add a special 'all' argument (for 'check' and 'merge' arguments)
99 LANGscip-python python gramps 6.0.7 `po.update_po`/LANG..appendscip-python python python-stdlib 3.11 builtins/list#append().("all")
100 # visual polish on the languages list
101 LANGscip-python python gramps 6.0.7 `po.update_po`/LANG..sortscip-python python python-stdlib 3.11 builtins/list#sort().()
102
103
104 def testsscip-python python gramps 6.0.7 `po.update_po`/tests().():
105 """
106 Testing installed programs.
107 We made tests (-t flag) by displaying versions of tools if properly
108 installed. Cannot run all commands without 'gettext' and 'python'.
109 """
110 try:
111 printscip-python python python-stdlib 3.11 builtins/print().("\n====='msgmerge'=(merge our translation)================\n")
112 osscip-python python python-stdlib 3.11 os/__init__:.systemscip-python python python-stdlib 3.11 os/system().("""%(program)s -V""" % {"program": msgmergeCmdscip-python python gramps 6.0.7 `po.update_po`/msgmergeCmd.})
113 except:
114 printscip-python python python-stdlib 3.11 builtins/print().(
115 "Please, install %(program)s for updating your translation"
116 % {"program": msgmergeCmdscip-python python gramps 6.0.7 `po.update_po`/msgmergeCmd.}
117 )
118
119 try:
120 printscip-python python python-stdlib 3.11 builtins/print().("\n==='msgfmt'=(format our translation for installation)==\n")
121 osscip-python python python-stdlib 3.11 os/__init__:.systemscip-python python python-stdlib 3.11 os/system().("""%(program)s -V""" % {"program": msgfmtCmdscip-python python gramps 6.0.7 `po.update_po`/msgfmtCmd.})
122 except:
123 printscip-python python python-stdlib 3.11 builtins/print().(
124 "Please, install %(program)s for checking your translation"
125 % {"program": msgfmtCmdscip-python python gramps 6.0.7 `po.update_po`/msgfmtCmd.}
126 )
127
128 try:
129 printscip-python python python-stdlib 3.11 builtins/print().("\n===='msgattrib'==(list groups of messages)=============\n")
130 osscip-python python python-stdlib 3.11 os/__init__:.systemscip-python python python-stdlib 3.11 os/system().("""%(program)s -V""" % {"program": msgattribCmdscip-python python gramps 6.0.7 `po.update_po`/msgattribCmd.})
131 except:
132 printscip-python python python-stdlib 3.11 builtins/print().(
133 "Please, install %(program)s for listing groups of messages"
134 % {"program": msgattribCmdscip-python python gramps 6.0.7 `po.update_po`/msgattribCmd.}
135 )
136
137 try:
138 printscip-python python python-stdlib 3.11 builtins/print().("\n===='xgettext' =(generate a new template)==============\n")
139 osscip-python python python-stdlib 3.11 os/__init__:.systemscip-python python python-stdlib 3.11 os/system().("""%(program)s -V""" % {"program": xgettextCmdscip-python python gramps 6.0.7 `po.update_po`/xgettextCmd.})
140 except:
141 printscip-python python python-stdlib 3.11 builtins/print().(
142 "Please, install %(program)s for generating a new template"
143 % {"program": xgettextCmdscip-python python gramps 6.0.7 `po.update_po`/xgettextCmd.}
144 )
145
146 try:
147 printscip-python python python-stdlib 3.11 builtins/print().("\n=================='python'=============================\n")
148 osscip-python python python-stdlib 3.11 os/__init__:.systemscip-python python python-stdlib 3.11 os/system().("""%(program)s -V""" % {"program": pythonCmdscip-python python gramps 6.0.7 `po.update_po`/pythonCmd.})
149 except:
150 printscip-python python python-stdlib 3.11 builtins/print().("Please, install python")
151
152
153 def mainscip-python python gramps 6.0.7 `po.update_po`/main().():
154 """
155 The utility for handling translation stuff.
156 What is need by Gramps, nothing more.
157 """
158
159 parser = ArgumentParserscip-python python python-stdlib 3.11 argparse/ArgumentParser#(
160 descriptionscip-python python python-stdlib 3.11 argparse/ArgumentParser#__init__().(description)="This program generates a new template and "
161 "also provides some common features.",
162 )
163 parser.add_argumentscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().(
164 "-t",
165 "--test",
166 actionscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().(action)="store_true",
167 destscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().(dest)="test",
168 defaultscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().(default)=True,
169 help="test if 'python' and 'gettext' are properly installed",
170 )
171
172 parser.add_argumentscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().(
173 "-x",
174 "--xml",
175 actionscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().(action)="store_true",
176 destscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().(dest)="xml",
177 defaultscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().(default)=False,
178 help="extract messages from xml based file formats",
179 )
180 parser.add_argumentscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().(
181 "-g",
182 "--glade",
183 actionscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().(action)="store_true",
184 destscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().(dest)="glade",
185 defaultscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().(default)=False,
186 help="extract messages from glade file format only",
187 )
188 parser.add_argumentscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().(
189 "-c",
190 "--clean",
191 actionscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().(action)="store_true",
192 destscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().(dest)="clean",
193 defaultscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().(default)=False,
194 help="remove created files",
195 )
196 parser.add_argumentscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().(
197 "-p",
198 "--pot",
199 actionscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().(action)="store_true",
200 destscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().(dest)="catalog",
201 defaultscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().(default)=False,
202 help="create a new catalog",
203 )
204
205 update = parser.add_argument_groupscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument_group().("Update", "Maintenance around translations")
206
207 # need at least one argument (sv.po, de.po, etc ...)
208
209 # lang.po files maintenance
210 update.add_argumentscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().(
211 "-m", destscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().(dest)="merge", choicesscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().(choices)=LANGscip-python python gramps 6.0.7 `po.update_po`/LANG., help="merge lang.po files with last catalog"
212 )
213
214 update.add_argumentscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().("-k", destscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().(dest)="check", choicesscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().(choices)=LANGscip-python python gramps 6.0.7 `po.update_po`/LANG., help="check lang.po files")
215
216 # testing stage
217 trans = parser.add_argument_groupscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument_group().(
218 "Translation", "Display content of translations file"
219 )
220
221 # need one argument (eg, de.po)
222
223 trans.add_argumentscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().(
224 "-u",
225 destscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().(dest)="untranslated",
226 choicesscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().(choices)=[file for file in osscip-python python python-stdlib 3.11 os/__init__:.listdirscip-python python python-stdlib 3.11 os/listdir().(".") if file.endswithscip-python python python-stdlib 3.11 builtins/str#endswith().(".po")],
227 help="list untranslated messages",
228 )
229 trans.add_argumentscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().(
230 "-f",
231 destscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().(dest)="fuzzy",
232 choicesscip-python python python-stdlib 3.11 argparse/_ActionsContainer#add_argument().(choices)=[file for file in osscip-python python python-stdlib 3.11 os/__init__:.listdirscip-python python python-stdlib 3.11 os/listdir().(".") if file.endswithscip-python python python-stdlib 3.11 builtins/str#endswith().(".po")],
233 help="list fuzzy messages",
234 )
235
236 args = parser.parse_argsscip-python python python-stdlib 3.11 argparse/ArgumentParser#parse_args().()
237 namespace, extra = parser.parse_known_argsscip-python python python-stdlib 3.11 argparse/ArgumentParser#parse_known_args().()
238
239 if args.test:
240 testsscip-python python gramps 6.0.7 `po.update_po`/tests().()
241
242 if args.xml:
243 extract_xmlscip-python python gramps 6.0.7 `po.update_po`/extract_xml().()
244
245 if args.glade:
246 create_filesfilescip-python python gramps 6.0.7 `po.update_po`/create_filesfile().()
247 extract_gladescip-python python gramps 6.0.7 `po.update_po`/extract_glade().()
248 if osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..isfilescip-python python python-stdlib 3.11 genericpath/exists().("tmpfiles"):
249 osscip-python python python-stdlib 3.11 os/__init__:.unlinkscip-python python python-stdlib 3.11 os/unlink().("tmpfiles")
250
251 if args.catalog:
252 retrievescip-python python gramps 6.0.7 `po.update_po`/retrieve().()
253
254 if args.clean:
255 cleanscip-python python gramps 6.0.7 `po.update_po`/clean().()
256
257 if args.merge:
258 # retrieve() windows os?
259 if sysscip-python python python-stdlib 3.11 sys/__init__:.argvscip-python python python-stdlib 3.11 sys/argv.argv.[2:] == ["all"]:
260 sysscip-python python python-stdlib 3.11 sys/__init__:.argvscip-python python python-stdlib 3.11 sys/argv.argv.[2:] = LANGscip-python python gramps 6.0.7 `po.update_po`/LANG.
261 mergescip-python python gramps 6.0.7 `po.update_po`/merge().(sysscip-python python python-stdlib 3.11 sys/__init__:.argvscip-python python python-stdlib 3.11 sys/argv.argv.[2:])
262
263 if args.check:
264 # retrieve() windows os?
265 if sysscip-python python python-stdlib 3.11 sys/__init__:.argvscip-python python python-stdlib 3.11 sys/argv.argv.[2:] == ["all"]:
266 sysscip-python python python-stdlib 3.11 sys/__init__:.argvscip-python python python-stdlib 3.11 sys/argv.argv.[2:] = LANGscip-python python gramps 6.0.7 `po.update_po`/LANG.
267 checkscip-python python gramps 6.0.7 `po.update_po`/check().(sysscip-python python python-stdlib 3.11 sys/__init__:.argvscip-python python python-stdlib 3.11 sys/argv.argv.[2:])
268
269 if args.untranslated:
270 untranslatedscip-python python gramps 6.0.7 `po.update_po`/untranslated().(sysscip-python python python-stdlib 3.11 sys/__init__:.argvscip-python python python-stdlib 3.11 sys/argv.argv.[2:])
271
272 if args.fuzzy:
273 fuzzyscip-python python gramps 6.0.7 `po.update_po`/fuzzy().(sysscip-python python python-stdlib 3.11 sys/__init__:.argvscip-python python python-stdlib 3.11 sys/argv.argv.[2:])
274
275
276 def create_filesfilescip-python python gramps 6.0.7 `po.update_po`/create_filesfile().():
277 """
278 Create a file with all files that we should translate.
279 These are all python files not in POTFILES.skip added with those in
280 POTFILES.in
281 """
282 dir = osscip-python python python-stdlib 3.11 os/__init__:.getcwdscip-python python python-stdlib 3.11 os/getcwd().()
283 topdir = osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..normpathscip-python python python-stdlib 3.11 genericpath/exists().(osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..joinscip-python python python-stdlib 3.11 genericpath/exists().(dir, "..", "gramps"))
284 lentopdir = len(topdir)
285 with openscip-python python python-stdlib 3.11 builtins/open().("POTFILES.in") as f:
286 infiles = dictscip-python python python-stdlib 3.11 builtins/dict#(
287 ["../" + file.stripscip-python python python-stdlib 3.11 builtins/str#strip().(), None]
288 for file in f
289 if file.stripscip-python python python-stdlib 3.11 builtins/str#strip().() and not file[0] == "#"
290 )
291
292 with openscip-python python python-stdlib 3.11 builtins/open().("POTFILES.skip") as f:
293 notinfiles = dictscip-python python python-stdlib 3.11 builtins/dict#(
294 ["../" + file.stripscip-python python python-stdlib 3.11 builtins/str#strip().(), None] for file in f if file and not file[0] == "#"
295 )
296
297 for dirpath, dirnames, filenames in osscip-python python python-stdlib 3.11 os/__init__:.walkscip-python python python-stdlib 3.11 os/walk().(topdir):
298 root, subdir = osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..splitscip-python python python-stdlib 3.11 genericpath/exists().(dirpath)
299 if subdir.startswithscip-python python python-stdlib 3.11 builtins/str#startswith().("."):
300 # don't continue in this dir
301 dirnames[:] = []
302 continue
303 for dirname in dirnames:
304 # Skip hidden and system directories:
305 if dirname.startswithscip-python python python-stdlib 3.11 builtins/str#startswith().(".") or dirname in ["po", "locale"]:
306 dirnames.removescip-python python python-stdlib 3.11 builtins/list#remove().(dirname)
307 # add the files which are python or glade files
308 # if the directory does not exist or is a link, do nothing
309 if not osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..isdirscip-python python python-stdlib 3.11 genericpath/exists().(dirpath) or osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..islinkscip-python python python-stdlib 3.11 genericpath/exists().(dirpath):
310 continue
311
312 for filename in osscip-python python python-stdlib 3.11 os/__init__:.listdirscip-python python python-stdlib 3.11 os/listdir().(dirpath):
313 name = osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..splitscip-python python python-stdlib 3.11 genericpath/exists().(filename)[1]
314 if name.endswithscip-python python python-stdlib 3.11 builtins/str#endswith().((".py", ".glade")):
315 full_filename = osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..joinscip-python python python-stdlib 3.11 genericpath/exists().(dirpath, filename)
316 # Skip the file if in POTFILES.skip
317 if full_filename[lentopdir:] in notinfiles:
318 infiles["../gramps" + full_filename[lentopdir:]] = None
319 # now we write out all the files in form ../gramps/filename
320 with openscip-python python python-stdlib 3.11 builtins/open().("tmpfiles", "w") as f:
321 for file in sortedscip-python python python-stdlib 3.11 builtins/sorted().(infiles.keysscip-python python python-stdlib 3.11 builtins/dict#keys().()):
322 f.writescip-python python python-stdlib 3.11 io/TextIOBase#write().(file)
323 f.writescip-python python python-stdlib 3.11 io/TextIOBase#write().("\n")
324
325
326 def listingscip-python python gramps 6.0.7 `po.update_po`/listing().(namescip-python python gramps 6.0.7 `po.update_po`/listing().(name), extensionlistscip-python python gramps 6.0.7 `po.update_po`/listing().(extensionlist)):
327 """
328 List files according to extensions.
329 Parsing from a textual file (gramps) is faster and easy for maintenance.
330 Like POTFILES.in and POTFILES.skip
331 """
332
333 with openscip-python python python-stdlib 3.11 builtins/open().("tmpfiles") as f:
334 files = [file.stripscip-python python python-stdlib 3.11 builtins/str#strip().() for file in f if file and not file[0] == "#"]
335
336 with openscip-python python python-stdlib 3.11 builtins/open().(namescip-python python gramps 6.0.7 `po.update_po`/listing().(name), "w") as temp:
337 for entry in files:
338 for ext in extensionlistscip-python python gramps 6.0.7 `po.update_po`/listing().(extensionlist):
339 if entry.endswithscip-python python python-stdlib 3.11 builtins/str#endswith().(ext):
340 temp.writescip-python python python-stdlib 3.11 io/TextIOBase#write().(entry)
341 temp.writescip-python python python-stdlib 3.11 io/TextIOBase#write().("\n")
342 break
343
344
345 def headersscip-python python gramps 6.0.7 `po.update_po`/headers().():
346 """
347 Look at existing C file format headers.
348 Generated by 'intltool-extract' but want to get rid of this
349 dependency (perl, just a set of tools).
350 """
351 headers = []
352
353 # in.h; extract_xml
354 if osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..isfilescip-python python python-stdlib 3.11 genericpath/exists().("""fragments.pot"""):
355 headers.appendscip-python python python-stdlib 3.11 builtins/list#append().("""fragments.pot""")
356
357 return headers
358
359
360 def extract_xmlscip-python python gramps 6.0.7 `po.update_po`/extract_xml().():
361 """
362 Extract translation strings from XML based, mime and desktop files.
363 Uses custom ITS rules found in the po/its directory.
364 """
365 if not osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..isfilescip-python python python-stdlib 3.11 genericpath/exists().("gramps.pot"):
366 create_templatescip-python python gramps 6.0.7 `po.update_po`/create_template().()
367
368 for input_file in [
369 "../data/holidays.xml",
370 "../data/tips.xml",
371 "../data/org.gramps_project.Gramps.xml.in",
372 "../data/org.gramps_project.Gramps.metainfo.xml.in",
373 "../data/org.gramps_project.Gramps.desktop.in",
374 ]:
375 osscip-python python python-stdlib 3.11 os/__init__:.systemscip-python python python-stdlib 3.11 os/system().(
376 (
377 "GETTEXTDATADIR=. %(xgettext)s -F -j "
378 "-o gramps.pot --from-code=UTF-8 %(inputfile)s"
379 )
380 % {"xgettext": xgettextCmdscip-python python gramps 6.0.7 `po.update_po`/xgettextCmd., "inputfile": input_file}
381 )
382 printscip-python python python-stdlib 3.11 builtins/print().(input_file)
383
384
385 def create_templatescip-python python gramps 6.0.7 `po.update_po`/create_template().():
386 """
387 Create a new file for template, if it does not exist.
388 """
389 with openscip-python python python-stdlib 3.11 builtins/open().("gramps.pot", "w") as template:
390 pass
391
392
393 def extract_gladescip-python python gramps 6.0.7 `po.update_po`/extract_glade().():
394 """
395 Extract messages from a temp file with all .glade
396 """
397 if not osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..isfilescip-python python python-stdlib 3.11 genericpath/exists().("gramps.pot"):
398 create_templatescip-python python gramps 6.0.7 `po.update_po`/create_template().()
399
400 listingscip-python python gramps 6.0.7 `po.update_po`/listing().("glade.txt", [".glade"])
401 osscip-python python python-stdlib 3.11 os/__init__:.systemscip-python python python-stdlib 3.11 os/system().(
402 """%(xgettext)s -F --add-comments -j -L Glade """
403 """--from-code=UTF-8 -o gramps.pot --files-from=glade.txt"""
404 % {"xgettext": xgettextCmdscip-python python gramps 6.0.7 `po.update_po`/xgettextCmd.}
405 )
406
407
408 def xml_fragmentsscip-python python gramps 6.0.7 `po.update_po`/xml_fragments().():
409 """search through the file for xml fragments that contain the
410 'translate="yes">string<' pattern. These need to be added to the message
411 catalog"""
412 with openscip-python python python-stdlib 3.11 builtins/open().("tmpfiles") as __f:
413 files = [
414 file.stripscip-python python python-stdlib 3.11 builtins/str#strip().()
415 for file in __f
416 if file and not (file[0] == "#") and file.endswithscip-python python python-stdlib 3.11 builtins/str#endswith().(".py\n")
417 ]
418 printscip-python python python-stdlib 3.11 builtins/print().("Checking for XML fragments in Python files")
419 modop = intscip-python python python-stdlib 3.11 builtins/int#(len(files) / 20)
420 wfp = openscip-python python python-stdlib 3.11 builtins/open().("fragments.pot", "w", encodingscip-python python python-stdlib 3.11 builtins/open().(encoding)="utf-8")
421 wfp.writescip-python python python-stdlib 3.11 io/TextIOBase#write().('msgid ""\n')
422 wfp.writescip-python python python-stdlib 3.11 io/TextIOBase#write().('msgstr ""\n')
423 wfp.writescip-python python python-stdlib 3.11 io/TextIOBase#write().('"Content-Type: text/plain; charset=UTF-8\\n"\n\n')
424 for indx, filename in enumeratescip-python python python-stdlib 3.11 builtins/enumerate#(files):
425 if not indx % modop:
426 printscip-python python python-stdlib 3.11 builtins/print().(intscip-python python python-stdlib 3.11 builtins/int#(indx / len(files) * 100), endscip-python python python-stdlib 3.11 builtins/print().(end)="\r")
427 fp = openscip-python python python-stdlib 3.11 builtins/open().(filename, "rb")
428 try:
429 tokens = tokenizescip-python python python-stdlib 3.11 tokenize/tokenize().(fp.readlinescip-python python python-stdlib 3.11 io/IOBase#readline().)
430 in_string = False
431 for _token, _text, _start, _end, _line in tokens:
432 if _text.startswithscip-python python python-stdlib 3.11 builtins/str#startswith().(('"""', "'''")):
433 _text = _text[3:]
434 elif _text.startswithscip-python python python-stdlib 3.11 builtins/str#startswith().(('"', "'")):
435 _text = _text[1:]
436 if _text.endswithscip-python python python-stdlib 3.11 builtins/str#endswith().(('"""', "'''")):
437 _text = _text[:-3]
438 elif _text.endswithscip-python python python-stdlib 3.11 builtins/str#endswith().(('"', "'")):
439 _text = _text[:-1]
440 if _token == STRINGscip-python python python-stdlib 3.11 token/STRING.STRING. and not in_string:
441 in_string = True
442 line_no = _start[0]
443 text = _text
444 continue
445 elif _token == STRINGscip-python python python-stdlib 3.11 token/STRING.STRING. and in_string:
446 text += _text
447 continue
448 elif _token == COMMENTscip-python python python-stdlib 3.11 token/COMMENT.COMMENT. or _token == NLscip-python python python-stdlib 3.11 token/NL.NL. and in_string:
449 # need to ignore comments and concatinate strings
450 _ml = True
451 continue
452 elif in_string:
453 in_string = False
454 end = 0
455 # _find_message_in_xml(text)
456 while True:
457 fnd = text.find('translatable="yes">', end)
458 if fnd == -1:
459 break
460 end = text.find("<", fnd)
461 if end == -1:
462 printscip-python python python-stdlib 3.11 builtins/print().(
463 "\nBad xml fragment '%s' at %s line %d"
464 % (text[fnd:], filename, _start[0])
465 )
466 break
467 msg = text[fnd + 19 : end]
468 if "%s" in msg or (msg.startswith("{") and msg.endswith("}")):
469 printscip-python python python-stdlib 3.11 builtins/print().(
470 "\n#: %s:%d Are you sure you want to "
471 'translate the "%%s"???' % (filename, line_no)
472 )
473 break
474 wfp.writescip-python python python-stdlib 3.11 io/TextIOBase#write().(
475 '#: %s:%d\nmsgid "%s"\nmsgstr ""\n'
476 % (filename, line_no, msg)
477 )
478 except TokenErrorscip-python python python-stdlib 3.11 tokenize/TokenError# as e:
479 printscip-python python python-stdlib 3.11 builtins/print().(
480 "\n%s: %s, line %d, column %d"
481 % (e.argsscip-python python python-stdlib 3.11 builtins/BaseException#args.[0], filename, e.argsscip-python python python-stdlib 3.11 builtins/BaseException#args.[1][0], e.argsscip-python python python-stdlib 3.11 builtins/BaseException#args.[1][1]),
482 filescip-python python python-stdlib 3.11 builtins/print().(file)=sysscip-python python python-stdlib 3.11 sys/__init__:.stderrscip-python python python-stdlib 3.11 sys/stderr.stderr.,
483 )
484 finally:
485 fp.closescip-python python python-stdlib 3.11 io/IOBase#close().()
486 wfp.closescip-python python python-stdlib 3.11 io/IOBase#close().()
487
488
489 def retrievescip-python python gramps 6.0.7 `po.update_po`/retrieve().():
490 """
491 Extract messages from all files used by Gramps (python, glade, xml)
492 """
493 create_templatescip-python python gramps 6.0.7 `po.update_po`/create_template().()
494
495 create_filesfilescip-python python gramps 6.0.7 `po.update_po`/create_filesfile().()
496 xml_fragmentsscip-python python gramps 6.0.7 `po.update_po`/xml_fragments().()
497
498 listingscip-python python gramps 6.0.7 `po.update_po`/listing().("python.txt", [".py", ".py.in"])
499
500 # additional keywords must always be kept in sync with those in genpot.sh
501 osscip-python python python-stdlib 3.11 os/__init__:.systemscip-python python python-stdlib 3.11 os/system().(
502 """%(xgettext)s -F --add-comments=Translators -j """
503 """--directory=./ -d gramps -L Python """
504 """-o gramps.pot --files-from=python.txt --debug """
505 """--keyword=_ --keyword=_:1,2c """
506 """--keyword=_T_ --keyword=_T_:1,2c """
507 """--keyword=trans_text --keyword=trans_text:1,2c """
508 """--keyword=ngettext --keyword=sgettext """
509 """--from-code=UTF-8""" % {"xgettext": xgettextCmdscip-python python gramps 6.0.7 `po.update_po`/xgettextCmd.}
510 )
511
512 extract_gladescip-python python gramps 6.0.7 `po.update_po`/extract_glade().()
513 extract_xmlscip-python python gramps 6.0.7 `po.update_po`/extract_xml().()
514
515 # C format header (.h extension)
516 for h in headersscip-python python gramps 6.0.7 `po.update_po`/headers().():
517 printscip-python python python-stdlib 3.11 builtins/print().("xgettext for %s" % h)
518 osscip-python python python-stdlib 3.11 os/__init__:.systemscip-python python python-stdlib 3.11 os/system().(
519 """%(xgettext)s -F --add-comments=Translators -j """
520 """-o gramps.pot --keyword=N_ --from-code=UTF-8 %(head)s"""
521 % {"xgettext": xgettextCmdscip-python python gramps 6.0.7 `po.update_po`/xgettextCmd., "head": h}
522 )
523 cleanscip-python python gramps 6.0.7 `po.update_po`/clean().()
524
525
526 def cleanscip-python python gramps 6.0.7 `po.update_po`/clean().():
527 """
528 Remove created files (C format headers, temp listings)
529 """
530 for h in headersscip-python python gramps 6.0.7 `po.update_po`/headers().():
531 if osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..isfilescip-python python python-stdlib 3.11 genericpath/exists().(h):
532 osscip-python python python-stdlib 3.11 os/__init__:.unlinkscip-python python python-stdlib 3.11 os/unlink().(h)
533 printscip-python python python-stdlib 3.11 builtins/print().("Remove %(head)s" % {"head": h})
534
535 if osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..isfilescip-python python python-stdlib 3.11 genericpath/exists().("python.txt"):
536 osscip-python python python-stdlib 3.11 os/__init__:.unlinkscip-python python python-stdlib 3.11 os/unlink().("python.txt")
537 printscip-python python python-stdlib 3.11 builtins/print().("Remove 'python.txt'")
538
539 if osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..isfilescip-python python python-stdlib 3.11 genericpath/exists().("glade.txt"):
540 osscip-python python python-stdlib 3.11 os/__init__:.unlinkscip-python python python-stdlib 3.11 os/unlink().("glade.txt")
541 printscip-python python python-stdlib 3.11 builtins/print().("Remove 'glade.txt'")
542
543 if osscip-python python python-stdlib 3.11 os/__init__:.pathscip-python python python-stdlib 3.11 os/path..isfilescip-python python python-stdlib 3.11 genericpath/exists().("tmpfiles"):
544 osscip-python python python-stdlib 3.11 os/__init__:.unlinkscip-python python python-stdlib 3.11 os/unlink().("tmpfiles")
545 printscip-python python python-stdlib 3.11 builtins/print().("Remove 'tmpfiles'")
546
547
548 def mergescip-python python gramps 6.0.7 `po.update_po`/merge().(argsscip-python python gramps 6.0.7 `po.update_po`/merge().(args)):
549 """
550 Merge messages with 'gramps.pot'
551 """
552 for arg in argsscip-python python gramps 6.0.7 `po.update_po`/merge().(args):
553 if arg == "all":
554 continue
555 printscip-python python python-stdlib 3.11 builtins/print().("Merge %(lang)s with current template" % {"lang": arg})
556 osscip-python python python-stdlib 3.11 os/__init__:.systemscip-python python python-stdlib 3.11 os/system().(
557 """%(msgmerge)s -U %(lang)s gramps.pot"""
558 % {"msgmerge": msgmergeCmdscip-python python gramps 6.0.7 `po.update_po`/msgmergeCmd., "lang": arg}
559 )
560 printscip-python python python-stdlib 3.11 builtins/print().("Updated file: '%(lang)s'." % {"lang": arg})
561
562
563 def checkscip-python python gramps 6.0.7 `po.update_po`/check().(argsscip-python python gramps 6.0.7 `po.update_po`/check().(args)):
564 """
565 Check the translation file
566 """
567 for arg in argsscip-python python gramps 6.0.7 `po.update_po`/check().(args):
568 if arg == "all":
569 continue
570 printscip-python python python-stdlib 3.11 builtins/print().(
571 "Checked file: '%(lang.po)s'. See '%(txt)s.txt'."
572 % {"lang.po": arg, "txt": arg[:-3]}
573 )
574 osscip-python python python-stdlib 3.11 os/__init__:.systemscip-python python python-stdlib 3.11 os/system().(
575 """%(python)s ./check_po -s %(lang.po)s > %(lang)s.txt"""
576 % {"python": pythonCmdscip-python python gramps 6.0.7 `po.update_po`/pythonCmd., "lang.po": arg, "lang": arg[:-3]}
577 )
578 osscip-python python python-stdlib 3.11 os/__init__:.systemscip-python python python-stdlib 3.11 os/system().(
579 """%(msgfmt)s -c -v %(lang.po)s""" % {"msgfmt": msgfmtCmdscip-python python gramps 6.0.7 `po.update_po`/msgfmtCmd., "lang.po": arg}
580 )
581
582
583 def untranslatedscip-python python gramps 6.0.7 `po.update_po`/untranslated().(argscip-python python gramps 6.0.7 `po.update_po`/untranslated().(arg)):
584 """
585 List untranslated messages
586 """
587 osscip-python python python-stdlib 3.11 os/__init__:.systemscip-python python python-stdlib 3.11 os/system().(
588 """%(msgattrib)s --untranslated %(lang.po)s"""
589 % {"msgattrib": msgattribCmdscip-python python gramps 6.0.7 `po.update_po`/msgattribCmd., "lang.po": argscip-python python gramps 6.0.7 `po.update_po`/untranslated().(arg)[0]}
590 )
591
592
593 def fuzzyscip-python python gramps 6.0.7 `po.update_po`/fuzzy().(argscip-python python gramps 6.0.7 `po.update_po`/fuzzy().(arg)):
594 """
595 List fuzzy messages
596 """
597 osscip-python python python-stdlib 3.11 os/__init__:.systemscip-python python python-stdlib 3.11 os/system().(
598 """%(msgattrib)s --only-fuzzy --no-obsolete %(lang.po)s"""
599 % {"msgattrib": msgattribCmdscip-python python gramps 6.0.7 `po.update_po`/msgattribCmd., "lang.po": argscip-python python gramps 6.0.7 `po.update_po`/fuzzy().(arg)[0]}
600 )
601
602
603 if __name__scip-python python gramps 6.0.7 `po.update_po`/ == "__main__":
604 mainscip-python python gramps 6.0.7 `po.update_po`/main().()