Add comments for translator to .tmpl files (#1473)

They are ignored in CTemplate, because the string doesn't reference it
as {N}
This commit is contained in:
Alexey Sokolov
2017-12-14 10:26:07 +00:00
committed by GitHub
parent fd83bb3473
commit 4a2c223379
3 changed files with 8 additions and 4 deletions
+4 -2
View File
@@ -36,14 +36,16 @@ pot_list = []
tmpl_pot = args.tmp_prefix + '_tmpl.pot'
tmpl_uniq_pot = args.tmp_prefix + '_tmpl_uniq.pot'
tmpl = []
pattern = re.compile(r'<\?\s*(?:FORMAT|(PLURAL))\s+(?:CTX="([^"]+?)"\s+)?"([^"]+?)"(?(1)\s+"([^"]+?)"|).*?\?>')
pattern = re.compile(r'<\?\s*(?:FORMAT|(PLURAL))\s+(?:CTX="([^"]+?)"\s+)?"([^"]+?)"(?(1)\s+"([^"]+?)"|).*?(?:"TRANSLATORS:\s*([^"]+?)")?\s*\?>')
for tmpl_dir in args.tmpl_dirs:
for fname in glob.iglob(tmpl_dir + '/*.tmpl'):
fbase = fname[len(args.strip_prefix):]
with open(fname, 'rt', encoding='utf8') as f:
for linenum, line in enumerate(f):
for x in pattern.finditer(line):
text, plural, context = x.group(3), x.group(4), x.group(2)
text, plural, context, comment = x.group(3), x.group(4), x.group(2), x.group(5)
if comment:
tmpl.append('# {}'.format(comment))
tmpl.append('#: {}:{}'.format(fbase, linenum + 1))
if context:
tmpl.append('msgctxt "{}"'.format(context))