From eb81a8abcfb9d7059a56a04848a18d5c619eb2b5 Mon Sep 17 00:00:00 2001 From: Inso <insomniak.fr@gmail.com> Date: Mon, 11 May 2015 14:50:47 +0200 Subject: [PATCH] Adding script to generate binary translations --- .gitignore | 3 +++ gen_resources.py | 1 + gen_translations.py | 58 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 gen_translations.py diff --git a/.gitignore b/.gitignore index 5b0725e7..0a45e37a 100644 --- a/.gitignore +++ b/.gitignore @@ -40,5 +40,8 @@ nosetests.xml # Generated files src/cutecoin/gen_resources/* src/icons_rc.py +src/i18n_rc.py +res/i18n/qm +res/i18n/lang-* out .directory diff --git a/gen_resources.py b/gen_resources.py index 4afcfea6..1f17d37b 100644 --- a/gen_resources.py +++ b/gen_resources.py @@ -5,6 +5,7 @@ import sys, os, multiprocessing, subprocess resources = os.path.abspath(os.path.join(os.path.dirname(__file__), 'res')) gen_ui = os.path.abspath(os.path.join(os.path.dirname(__file__), 'src', 'cutecoin', 'gen_resources')) gen_resources = os.path.abspath(os.path.join(os.path.dirname(__file__), 'src')) + def convert_ui(args, **kwargs): subprocess.call(args, **kwargs) diff --git a/gen_translations.py b/gen_translations.py new file mode 100644 index 00000000..9aee1f1e --- /dev/null +++ b/gen_translations.py @@ -0,0 +1,58 @@ +import sys, os, multiprocessing, subprocess, time + +gen_resources = os.path.abspath(os.path.join(os.path.dirname(__file__), 'src')) +ts = os.path.abspath(os.path.join(os.path.dirname(__file__), 'res', 'i18n', 'ts')) +qm = os.path.abspath(os.path.join(os.path.dirname(__file__), 'res', 'i18n', 'qm')) + +translations = [] +qm_files = [] +qm_shortnames = [] + +def prepare_qm(): + for root, dirs, files in os.walk(ts): + for f in files: + if f.endswith('.ts'): + tsfilename = os.path.join(root, f) + qmshort = "{0}qm".format(f[:-2]) + qmfilename = os.path.join(qm, qmshort) + srcdest = (tsfilename, qmfilename) + translations.append(srcdest) + qm_shortnames.append(qmshort) + else: + continue + print(os.path.join(root, f)) + + for (ts_file, qm_file) in translations: + subprocess.call(["lrelease-qt5", ts_file, "-qm", qm_file]) + print(ts_file + " >> " + qm_file) + +def build_resources(): + files = "" + for file in qm_shortnames: + files += """ +<file alias="{0}">qm/{0}.qm</file>""".format(file[:-3]) + rccfile = """<RCC> + <qresource prefix="i18n">{0} + </qresource> + </RCC> + """.format(files) + + qrc_filename = os.path.abspath(os.path.join(os.path.dirname(__file__), + 'res', + 'i18n', + 'langs-{0}.qrc'.format(int(time.time())) + )) + + pyc_filename = os.path.abspath(os.path.join(gen_resources, 'i18n_rc.py')) + with open(qrc_filename, 'w') as outfile: + outfile.write(rccfile) + + try: + subprocess.call(["pyrcc5", "-o", pyc_filename, qrc_filename]) + print(qrc_filename + " >> " + pyc_filename) + finally: + os.remove(qrc_filename) + + +prepare_qm() +build_resources() -- GitLab