From ce1b2bd513ce68d9ea0291620ec1a6ca6bcfcacc Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Tue, 16 Jan 2018 16:17:23 +1100 Subject: [PATCH 1/4] Update the check_lacked_trans.py script to work with latest codebase and use python 3 --- install/check_lacked_trans.py | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/install/check_lacked_trans.py b/install/check_lacked_trans.py index 6dc145a7..dcaa9fda 100644 --- a/install/check_lacked_trans.py +++ b/install/check_lacked_trans.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ @@ -54,7 +54,6 @@ def main(): src = files_in(dir, 'onionshare') + files_in(dir, 'onionshare_gui') pysrc = [p for p in src if p.endswith('.py')] - htmlsrc = [p for p in src if p.endswith('.html')] translate_keys = set() # load translate key from python source @@ -67,20 +66,12 @@ def main(): key = arg.split(',')[0].strip('''"' ''') 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: for k in sorted(translate_keys): - print k + print(k) 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: with codecs.open(locale_file, 'r', encoding='utf-8') as f: trans = json.load(f) @@ -92,10 +83,10 @@ def main(): locale, ext = os.path.splitext(os.path.basename(locale_file)) for k in sorted(disused): - print locale, 'disused', k + print(locale, 'disused', k) for k in sorted(lacked): - print locale, 'lacked', k + print(locale, 'lacked', k) if __name__ == '__main__': From c3bf8f0739486d3273c6aadf01b77d0c5c09e069 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Tue, 16 Jan 2018 16:32:26 +1100 Subject: [PATCH 2/4] Add -l arg to check_lacked_trans.py, to filter on a specific language code --- install/check_lacked_trans.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/install/check_lacked_trans.py b/install/check_lacked_trans.py index dcaa9fda..8ed3636f 100644 --- a/install/check_lacked_trans.py +++ b/install/check_lacked_trans.py @@ -36,7 +36,9 @@ def arg_parser(): p.add_argument('-d', default='.', help='onionshare directory', metavar='ONIONSHARE_DIR', dest='onionshare_dir') p.add_argument('--show-all-keys', action='store_true', - help='show translation key in source and exit') + help='show translation key in source and exit'), + p.add_argument('-l', default='all', help='language code (default: all)', + metavar='LANG_CODE', dest='lang_code') return p @@ -55,6 +57,8 @@ def main(): src = files_in(dir, 'onionshare') + files_in(dir, 'onionshare_gui') pysrc = [p for p in src if p.endswith('.py')] + lang_code = args.lang_code + translate_keys = set() # load translate key from python source for line in fileinput.input(pysrc, openhook=fileinput.hook_encoded('utf-8')): @@ -71,7 +75,10 @@ def main(): print(k) sys.exit() - locale_files = [f for f in files_in(dir, 'share/locale') if f.endswith('.json')] + if lang_code == 'all': + locale_files = [f for f in files_in(dir, 'share/locale') if f.endswith('.json')] + else: + locale_files = [f for f in files_in(dir, 'share/locale') if f.endswith('.json') and lang_code in f] for locale_file in locale_files: with codecs.open(locale_file, 'r', encoding='utf-8') as f: trans = json.load(f) From 83e0d9f4de7c368c1e78b950c343cbd973836b7b Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Tue, 16 Jan 2018 16:45:54 +1100 Subject: [PATCH 3/4] Better match for lang code filter --- install/check_lacked_trans.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/check_lacked_trans.py b/install/check_lacked_trans.py index 8ed3636f..2486758e 100644 --- a/install/check_lacked_trans.py +++ b/install/check_lacked_trans.py @@ -78,7 +78,7 @@ def main(): if lang_code == 'all': locale_files = [f for f in files_in(dir, 'share/locale') if f.endswith('.json')] else: - locale_files = [f for f in files_in(dir, 'share/locale') if f.endswith('.json') and lang_code in f] + locale_files = [f for f in files_in(dir, 'share/locale') if f.endswith('%s.json' % lang_code)] for locale_file in locale_files: with codecs.open(locale_file, 'r', encoding='utf-8') as f: trans = json.load(f) From 0333ec915c8a39b96d17226b4a73925112b70cb3 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Tue, 16 Jan 2018 16:48:35 +1100 Subject: [PATCH 4/4] Fix indentation... --- install/check_lacked_trans.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/check_lacked_trans.py b/install/check_lacked_trans.py index 2486758e..3313db7c 100644 --- a/install/check_lacked_trans.py +++ b/install/check_lacked_trans.py @@ -78,7 +78,7 @@ def main(): if lang_code == 'all': locale_files = [f for f in files_in(dir, 'share/locale') if f.endswith('.json')] else: - locale_files = [f for f in files_in(dir, 'share/locale') if f.endswith('%s.json' % lang_code)] + locale_files = [f for f in files_in(dir, 'share/locale') if f.endswith('%s.json' % lang_code)] for locale_file in locale_files: with codecs.open(locale_file, 'r', encoding='utf-8') as f: trans = json.load(f)