问题
A part of my .ts file, created with pylupdate4, looks like:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS><TS version="2.0">
<context>
<name>Main</name>
<message>
<location filename="Main.py" line="2369"/>
<source>Translate me to Ukululu</source>
<translation type="unfinished"></translation>
</message>
Two questions:
1: The translation comes between the <translation>
-tags, right?
2: The translation seems to need the line in the main file where the translation is to be inserted ("line=2369"). But everytime I modify the code, the lines change. Hence, do I have to create a new translation file, where I have to manually insert all the (unchanged) translations between the tags again? This seems like a crazy amount of work. Correct me if I am wrong or please explain, how it works (better)!
回答1:
You are right. The original text comes in the tag <source>
while the translation comes in the tag <translation>
. When the translation is finished the attribute type="unfinished"
will also be removed.
Usually you don't edit ts files manually but you use the QtLinguist tool. I never edit them by hand, since QtLinguist is very easy to use...
In any case, when you change the source code, you simply run
pylupdate4 your_project.pro
This will update all the references to the lines in the ts file, and it will keep the translation already finished. It is smart enough to update the translations even if you move them to a different source file.
You can get further information here
http://pyqt.sourceforge.net/Docs/PyQt4/i18n.html
http://qt-project.org/doc/qt-4.8/linguist-manager.html
Hope this helps
来源:https://stackoverflow.com/questions/18921213/translation-file-still-working-after-modifying-the-source