[Pkg-anonymity-tools] [onionshare] 01/57: add a script that check translation lacked or disused

Ulrike Uhlig u-guest at moszumanska.debian.org
Tue May 19 18:18:53 UTC 2015


This is an automated email from the git hooks/post-receive script.

u-guest pushed a commit to annotated tag 0.7
in repository onionshare.

commit 8f884aa4e0af82288a69190e2e08ca1d9ac05114
Author: kkka <kkka at users.noreply.github.com>
Date:   Thu Sep 25 02:18:03 2014 +0900

    add a script that check translation lacked or disused
---
 check_lacked_trans.py | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 104 insertions(+)

diff --git a/check_lacked_trans.py b/check_lacked_trans.py
new file mode 100644
index 0000000..50306a4
--- /dev/null
+++ b/check_lacked_trans.py
@@ -0,0 +1,104 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+'''
+Check translation lacked or disused.
+
+Example:
+in OninShare directory
+$ check_lacked_trans.py
+de disused choose_file
+de disused gui_starting_server
+de lacked gui_canceled
+de lacked gui_starting_server1
+de lacked gui_starting_server2
+de lacked gui_starting_server3
+en disused choose_file
+es disused choose_file
+es disused gui_starting_server
+...
+
+
+1. search `{{strings.translation_key}}` and `strings._('translation_key')`
+   from .py or .html files.
+2. load translation key from locale/*.json.
+3. compare these.
+
+'''
+
+
+import fileinput, argparse, re, os, codecs, json, sys
+
+
+def arg_parser():
+    desc = __doc__.strip().splitlines()[0]
+    p = argparse.ArgumentParser(description=desc)
+    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')
+    return p
+
+
+def files_in(*dirs):
+    dir = os.path.join(*dirs)
+    files = os.listdir(dir)
+    return [os.path.join(dir, f) for f in files]
+
+
+def main():
+    parser = arg_parser()
+    args = parser.parse_args()
+
+    dir = args.onionshare_dir
+
+    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
+    for line in fileinput.input(pysrc, openhook=fileinput.hook_encoded('utf-8')):
+        # search `strings._('translate_key')`
+        #        `strings._('translate_key', True)`
+        m = re.search(r'strings\._\((.*?)\)', line)
+        if m:
+            arg = m.group(1)
+            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
+        sys.exit()
+
+
+    locale_files = [f for f in files_in(dir, '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)
+        # trans -> {"key1": "translate-text1", "key2": "translate-text2", ...}
+        locale_keys = set(trans.keys())
+
+        disused = locale_keys - translate_keys
+        lacked = translate_keys - locale_keys
+
+        locale, ext = os.path.splitext(os.path.basename(locale_file))
+        for k in sorted(disused):
+            print locale, 'disused', k
+
+        for k in sorted(lacked):
+            print locale, 'lacked', k
+
+
+if __name__ == '__main__':
+    main()

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/collab-maint/onionshare.git



More information about the Pkg-anonymity-tools mailing list