From 00037ee16b0cb16352d1ae279bf60045dddc33fd Mon Sep 17 00:00:00 2001 From: Skycoder42 Date: Tue, 27 Feb 2018 18:00:49 +0100 Subject: [PATCH] added settings ts generator --- bin/qsettingstranslator.py | 38 +++++++++++++++++++++ examples/mvvmcore/SampleCore/SampleCore.pro | 8 +++-- examples/mvvmcore/SampleCore/settings.xml | 36 ++++++++++--------- mkspecs/features/qsettingstranslator.prf | 23 +++++++++++++ src/mvvmcore/mvvmcore.pro | 25 ++++++++++---- 5 files changed, 104 insertions(+), 26 deletions(-) create mode 100755 bin/qsettingstranslator.py create mode 100644 mkspecs/features/qsettingstranslator.prf diff --git a/bin/qsettingstranslator.py b/bin/qsettingstranslator.py new file mode 100755 index 0000000..a4aadac --- /dev/null +++ b/bin/qsettingstranslator.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python3 +# Usage: qsettingstranslator.py + +import sys +import os +from xml.etree.ElementTree import Element, parse + +if len(sys.argv) != 3: + print("Usage: qsettingstranslator.py ", file=sys.stderr) + exit(1) + +infile = sys.argv[1] +outfile = sys.argv[2] + +strings = set() +tree = parse(infile) +root = Element("TS") +for elem in tree.iter(): + if elem.tag == "SearchKey": + strings.add(elem.text) + else: + if "title" in elem.attrib: + strings.add(elem.attrib["title"]) + if "tooltip" in elem.attrib: + strings.add(elem.attrib["tooltip"]) + if "ts" in elem.attrib and elem.attrib["ts"].lower() == "true": + strings.add(elem.text) + if "tsdefault" in elem.attrib and elem.attrib["tsdefault"].lower() == "true": + strings.add(elem.attrib["default"]) + +with open(outfile, "w") as file: + file.write("#include \n\n") + file.write("void dummyfn() {\n") + for string in strings: + string = string.replace("\\", "\\\\") + string = string.replace("\"", "\\\"") + file.write("\tQCoreApplication::translate(\"{}\", \"{}\");\n".format(os.path.basename(infile), string)) + file.write("}\n") diff --git a/examples/mvvmcore/SampleCore/SampleCore.pro b/examples/mvvmcore/SampleCore/SampleCore.pro index f5959b3..03c7b71 100644 --- a/examples/mvvmcore/SampleCore/SampleCore.pro +++ b/examples/mvvmcore/SampleCore/SampleCore.pro @@ -22,8 +22,12 @@ SOURCES += \ drawerviewmodel.cpp \ tabviewmodel.cpp +RESOURCES += \ + sample_core.qrc + +QTMVVM_TS_SETTINGS += settings.xml + target.path = $$[QT_INSTALL_EXAMPLES]/mvvmcore/$$TARGET INSTALLS += target -RESOURCES += \ - sample_core.qrc +samples_in_build: QMAKE_QSETTINGSTRANSLATOR = $$PWD/../../../bin/qsettingstranslator.py diff --git a/examples/mvvmcore/SampleCore/settings.xml b/examples/mvvmcore/SampleCore/settings.xml index 9c530f2..8f2412a 100644 --- a/examples/mvvmcore/SampleCore/settings.xml +++ b/examples/mvvmcore/SampleCore/settings.xml @@ -15,7 +15,7 @@ - Enter a nice name + Enter a nice name @@ -24,17 +24,18 @@ title="Open &system settings"> Trigger Action - You can use this to trigger whatever kind of action you need + You can use this to trigger whatever kind of action you need + default="Variant B" + tsdefault="true"> - Variant A - Variant B - Variant C + Variant A + Variant B + Variant C @@ -53,31 +54,31 @@ default="3"> - Value A + Value A 1 - Value B + Value B 2 - Value C + Value C 4 - Value A+B + Value A+B 3 - Value A+C + Value A+C 5 - Value B+C + Value B+C 6 - Value A+B+C + Value A+B+C 7 @@ -92,17 +93,18 @@ + default="Text 2" + tsdefault="true"> true - Text 1 - Text 2 + Text 1 + Text 2 - https://example.org/test + https://example.org/test