diff --git a/bin/qsettingstranslator.py b/bin/qsettingstranslator.py index d7961e4..b533628 100755 --- a/bin/qsettingstranslator.py +++ b/bin/qsettingstranslator.py @@ -7,33 +7,41 @@ try: except ImportError: from xml.etree.ElementTree import parse -if len(sys.argv) != 3: - print("Usage: qsettingstranslator.py ", file=sys.stderr) - exit(1) -infile = sys.argv[1] -outfile = sys.argv[2] +def create_settings_ts(infile, outfile): + strings = [] + tree = parse(infile) + for elem in tree.iter(): + if elem.tag == "SearchKey": + strings.append(elem.text) + else: + if "title" in elem.attrib: + strings.append(elem.attrib["title"]) + if "tooltip" in elem.attrib: + strings.append(elem.attrib["tooltip"]) + if "tr" in elem.attrib and elem.attrib["tr"].lower() == "true": + strings.append(elem.text) + if "trdefault" in elem.attrib and elem.attrib["trdefault"].lower() == "true": + strings.append(elem.attrib["default"]) + # legaxy keys, because of a typo... + if "ts" in elem.attrib and elem.attrib["ts"].lower() == "true": + strings.append(elem.text) + if "tsdefault" in elem.attrib and elem.attrib["tsdefault"].lower() == "true": + strings.append(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(\"qtmvvm_settings_xml\", \"{}\");\n".format(string)) + file.write("}\n") -strings = set() -tree = parse(infile) -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(\"qtmvvm_settings_xml\", \"{}\");\n".format(string)) - file.write("}\n") +if __name__ == '__main__': + if len(sys.argv) != 3: + print("Usage: qsettingstranslator.py ", file=sys.stderr) + exit(1) + else: + create_settings_ts(*sys.argv[1:3]) diff --git a/examples/mvvmcore/SampleCore/samplecore_de.ts b/examples/mvvmcore/SampleCore/samplecore_de.ts index b23752a..245d0f9 100644 --- a/examples/mvvmcore/SampleCore/samplecore_de.ts +++ b/examples/mvvmcore/SampleCore/samplecore_de.ts @@ -81,77 +81,81 @@ qtmvvm_settings_xml - + + + Select a &mode - + + Variant B - + This is another section - + Variant C - + https://example.org/test - + Value C - + Enter a nice name - + Value A+B - + Value A+B+C - + bool - + Open &system settings - + Value A+C - + &Check me - + + property - + Another Section @@ -161,87 +165,88 @@ - + Another main category - + + Text 2 - + This is a tooltip - + Enter a &value - + Choose a &font - + Variant A - + Value A - + Enter a &name - + I am a checkbox! - + Enter a &number - + You can use this to trigger whatever kind of action you need - + Value B - + The value must be between 0 and 1 - + Non existing type - + Text 1 - + Sub-Group - + Value B+C diff --git a/examples/mvvmcore/SampleCore/settings.xml b/examples/mvvmcore/SampleCore/settings.xml index 80fbb91..d089987 100644 --- a/examples/mvvmcore/SampleCore/settings.xml +++ b/examples/mvvmcore/SampleCore/settings.xml @@ -15,7 +15,8 @@ - Enter a nice name + property + Enter a nice name @@ -24,18 +25,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 + trdefault="true"> - Variant A - Variant B - Variant C + Variant A + Variant B + Variant C @@ -54,31 +55,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 @@ -94,17 +95,17 @@ type="selection" title="Select a &mode" default="Text 2" - tsdefault="true"> + trdefault="true"> true - Text 1 - Text 2 + Text 1 + Text 2 - https://example.org/test + https://example.org/test