mirror of
https://github.com/onionshare/onionshare.git
synced 2024-12-29 01:06:16 -05:00
Merge branch 'update_check_translation_script' of https://github.com/mig5/onionshare into mig5-update_check_translation_script
This commit is contained in:
commit
7d5eda6fac
@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
@ -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
|
||||
|
||||
|
||||
@ -54,7 +56,8 @@ 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')]
|
||||
|
||||
lang_code = args.lang_code
|
||||
|
||||
translate_keys = set()
|
||||
# load translate key from python source
|
||||
@ -67,20 +70,15 @@ 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')]
|
||||
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)]
|
||||
for locale_file in locale_files:
|
||||
with codecs.open(locale_file, 'r', encoding='utf-8') as f:
|
||||
trans = json.load(f)
|
||||
@ -92,10 +90,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__':
|
||||
|
Loading…
Reference in New Issue
Block a user