mirror of
https://github.com/onionshare/onionshare.git
synced 2025-01-10 19:52:50 -03:00
Merge pull request #152 from kkka/check-lacked-translation
Add a script that check translation lacked or disused
This commit is contained in:
commit
381d046a94
12 changed files with 109 additions and 19 deletions
104
check_lacked_trans.py
Normal file
104
check_lacked_trans.py
Normal file
|
@ -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()
|
|
@ -16,7 +16,6 @@
|
|||
"download_page_loaded": "Seite geladen",
|
||||
"other_page_loaded": "URL geladen",
|
||||
"close_on_finish": "Den Server automatisch anhalten",
|
||||
"choose_file": "Wählen Sie eine Datei",
|
||||
"closing_automatically": "Halte automatisch an, da der Download beendet wurde",
|
||||
"large_filesize": "Warnung: Das Senden von großen Dateien kann Stunden dauern",
|
||||
"error_tails_invalid_port": "Ungültiger Wert, Port muss eine ganze Zahl sein",
|
||||
|
@ -37,6 +36,5 @@
|
|||
"gui_copy_url": "URL kopieren",
|
||||
"gui_downloads": "Downloads:",
|
||||
"gui_copied_url": "URL wurde in die Zwischenablage kopiert",
|
||||
"gui_starting_server": "Bitte warten, der Server startet...",
|
||||
"gui_please_wait": "Bitte warten..."
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
"download_page_loaded": "Download page loaded",
|
||||
"other_page_loaded": "URL loaded",
|
||||
"close_on_finish": "Stop server automatically",
|
||||
"choose_file": "Choose a file to share",
|
||||
"closing_automatically": "Closing automatically because download finished",
|
||||
"large_filesize": "Warning: Sending large files could take hours",
|
||||
"error_tails_invalid_port": "Invalid value, port must be an integer",
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
"download_page_loaded": "La página de descarga está lista.",
|
||||
"other_page_loaded": "La URL está lista.",
|
||||
"close_on_finish": "Apagar el servidor automáticamente.",
|
||||
"choose_file": "Elija un archivo para compartir",
|
||||
"closing_automatically": "Apagando automáticamente porque la descarga finalizó",
|
||||
"error_tails_invalid_port": "Valor inválido, el puerto debe ser un entero",
|
||||
"error_tails_unknown_root": "Error desconocido en el proceso de Tails corriendo como root",
|
||||
|
@ -35,6 +34,5 @@
|
|||
"gui_stop_server": "Detener el Servidor",
|
||||
"gui_copy_url": "Copiar URL",
|
||||
"gui_downloads": "Descargas:",
|
||||
"gui_copied_url": "Se copió la URL en el portapapeles",
|
||||
"gui_starting_server": "Por favor espere, levantando el servidor..."
|
||||
"gui_copied_url": "Se copió la URL en el portapapeles"
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
"download_page_loaded": "Lataussivu ladattu",
|
||||
"other_page_loaded": "URL-osoite ladattu",
|
||||
"close_on_finish": "Pysäytä palvelin automaattisesti",
|
||||
"choose_file": "Valitse jaettava tiedosto",
|
||||
"closing_automatically": "Lataus valmis. Suljetaan automaattisesti",
|
||||
"large_filesize": "Varoitus: Isojen tiedostojen lähetys saattaa kestää tunteja",
|
||||
"error_tails_invalid_port": "Väärä arvo, portti pitää olla koknaisluku",
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
"download_page_loaded": "Page de téléchargement chargée",
|
||||
"other_page_loaded": "URL chargée",
|
||||
"close_on_finish": "Arrêter le serveur automatiquement",
|
||||
"choose_file": "Sélectionnez un fichier à partager",
|
||||
"closing_automatically": "Fermeture automatique car le téléchargement est fini",
|
||||
"error_tails_invalid_port": "Valeur invalide, le port doit être un nombre entier",
|
||||
"error_tails_unknown_root": "Erreur inconnue avec un processus root sur Tails",
|
||||
|
@ -34,6 +33,5 @@
|
|||
"gui_stop_server": "Arrêter le serveur",
|
||||
"gui_copy_url": "Copier URL",
|
||||
"gui_downloads": "Téléchargements :",
|
||||
"gui_copied_url": "URL copié dans le presse-papier",
|
||||
"gui_starting_server": "Veuillez patienter, le serveur démarre..."
|
||||
"gui_copied_url": "URL copié dans le presse-papier"
|
||||
}
|
||||
|
|
|
@ -7,6 +7,5 @@
|
|||
"gui_copied_url": "URL copiato negli appunti",
|
||||
"download_page_loaded": "Pagina di download caricata",
|
||||
"other_page_loaded": "Un altra pagina é stata caricata",
|
||||
"close_on_finish": "Chiudi automaticamente",
|
||||
"choose_file": "Scegli un file da condividere"
|
||||
"close_on_finish": "Chiudi automaticamente"
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
"download_page_loaded": "Downloadpagina geladen",
|
||||
"other_page_loaded": "URL geladen",
|
||||
"close_on_finish": "Stop server automatisch",
|
||||
"choose_file": "Kies een bestand om te delen",
|
||||
"closing_automatically": "Sluit nu automatisch omdat download gereed is",
|
||||
"large_filesize": "Waarschuwing: Versturen van grote bestanden kan uren duren",
|
||||
"error_tails_invalid_port": "Ongeldige waarde, poort moet een integer zijn",
|
||||
|
|
|
@ -7,6 +7,5 @@
|
|||
"gui_copied_url": "Kopierte URL-en til utklippstavlen",
|
||||
"download_page_loaded": "Nedlastingsside lastet",
|
||||
"other_page_loaded": "En annen side har blitt lastet",
|
||||
"close_on_finish": "Lukk automatisk",
|
||||
"choose_file": "Velg en fil å dele"
|
||||
"close_on_finish": "Lukk automatisk"
|
||||
}
|
||||
|
|
|
@ -7,6 +7,5 @@
|
|||
"gui_copied_url": "URL foi copiado para área de transferência",
|
||||
"download_page_loaded": "Página de download carregada",
|
||||
"other_page_loaded": "Outra página tem sido carregada",
|
||||
"close_on_finish": "Fechar automaticamente",
|
||||
"choose_file": "Escolhe um arquivo para compartilhar"
|
||||
"close_on_finish": "Fechar automaticamente"
|
||||
}
|
||||
|
|
|
@ -8,6 +8,5 @@
|
|||
"download_page_loaded": "Страница закачки загружена",
|
||||
"other_page_loaded": "Другая страница была загружена",
|
||||
"close_on_finish": "Закрыть автоматически",
|
||||
"choose_file": "Выберите файл",
|
||||
"gui_copy_url": "Скопировать ссылку"
|
||||
}
|
||||
|
|
|
@ -8,6 +8,5 @@
|
|||
"download_page_loaded": "İndirme sayfası yüklendi",
|
||||
"other_page_loaded": "Diğer sayfa yüklendi",
|
||||
"close_on_finish": "Kendiliğinden kapan",
|
||||
"choose_file": "Paylaşım için bir dosya seç",
|
||||
"gui_copy_url": "URL Kopyala"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue