Update the check_lacked_trans.py script to work with latest codebase and use python 3

This commit is contained in:
Miguel Jacq 2018-01-16 16:17:23 +11:00
parent c1d9f5c1b4
commit 5a36f945b1

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" """
@ -54,7 +54,6 @@ def main():
src = files_in(dir, 'onionshare') + files_in(dir, 'onionshare_gui') src = files_in(dir, 'onionshare') + files_in(dir, 'onionshare_gui')
pysrc = [p for p in src if p.endswith('.py')] pysrc = [p for p in src if p.endswith('.py')]
htmlsrc = [p for p in src if p.endswith('.html')]
translate_keys = set() translate_keys = set()
# load translate key from python source # load translate key from python source
@ -67,20 +66,12 @@ def main():
key = arg.split(',')[0].strip('''"' ''') key = arg.split(',')[0].strip('''"' ''')
translate_keys.add(key) translate_keys.add(key)
# load translate key from html source
for line in fileinput.input(htmlsrc, openhook=fileinput.hook_encoded('utf-8')):
# search `{{strings.translate_key}}`
m = re.search(r'{{.*strings\.([-a-zA-Z0-9_]+).*}}', line)
if m:
key = m.group(1)
translate_keys.add(key)
if args.show_all_keys: if args.show_all_keys:
for k in sorted(translate_keys): for k in sorted(translate_keys):
print k print(k)
sys.exit() sys.exit()
locale_files = [f for f in files_in(dir, 'locale') if f.endswith('.json')] locale_files = [f for f in files_in(dir, 'share/locale') if f.endswith('.json')]
for locale_file in locale_files: for locale_file in locale_files:
with codecs.open(locale_file, 'r', encoding='utf-8') as f: with codecs.open(locale_file, 'r', encoding='utf-8') as f:
trans = json.load(f) trans = json.load(f)
@ -92,10 +83,10 @@ def main():
locale, ext = os.path.splitext(os.path.basename(locale_file)) locale, ext = os.path.splitext(os.path.basename(locale_file))
for k in sorted(disused): for k in sorted(disused):
print locale, 'disused', k print(locale, 'disused', k)
for k in sorted(lacked): for k in sorted(lacked):
print locale, 'lacked', k print(locale, 'lacked', k)
if __name__ == '__main__': if __name__ == '__main__':