Code: Alles auswählen
<trans-unit id="79758" identifier="94740966b6ba0011f746c7ffd1b2ffb9">
<source>! %1 mode is %2 %3</source>
<target state="translated">! %1 模式是 %2 %3</target>
<note>Context: QObject ../src/formatter.cpp:172</note>
</trans-unit>
Ich möchte also diesen ausschneiden und z.B. als Exceldatei zwischenspeichern, die dann übersetzt wird.
Vermutlich würde es für den nächsten Schritt Sinn ergeben, der Zeile noch die trans-unit id vorzustellen.
Als nächstes würde ich dann nämlich die Übersetzungen wieder in einer ähnlichen XML Datei benötigen.
Leider habe ich bisher kaum Erfahrung mit XML. Gibt es da leichte Techniken, die mir dabei helfen würden?
Bei meinen Recherchen fand ich nun das xml.etree.ElementTree welches erstmal vielversprechend aussieht.
Genaue Tests sind noch offen. Bis dato habe ich einen groben Ablauf entworfen. Scheint mir aber aufwändig?
Code: Alles auswählen
def read_source_file():
""" Open a well defined source file, read it and return its content."""
file_handler = None
content = ""
return content
def get_ids(content_handler):
""" Return a list of IDs from a well defined XML content."""
ids = []
return ids
def get_texts(content_handler):
""" Return a list of both ID and text content for each translation text."""
texts = []
return texts
def write_file(texts_to_write):
""" Save both ID and texts to a simple file format ready for translation."""
return
def read_translation_file():
""" Open a well defined file with translations, read it and return its content."""
return
def replace_translations(translated_texts):
""" Carefully place the translations in the place indicated by their ID."""
return
def save_new_file(xml_to_write):
""" Save a well defined XML file with a new name to the place where it belongs."""
return
def main():
source_content = read_source_file()
ids = get_ids(source_content)
print(len(ids))
print(len(set(ids)))
return
# are the IDs really unique ???
texts = get_texts(source_content)
write_file(texts)
# pause here for actual translation ???
translated_content = read_translation_file()
updated_source_contents = replace_translations(translated_content) # ???
save_new_file(updated_source_contents)
if __name__ == '__main__':
main()