我正在尝试使用 pylupdate 创建翻译文件。
import sys
from PyQt5 import QtCore
from PyQT5.QtCore import QT_TRANSLATE_NOOP
_translate = QtCore.QCoreApplication.translate
if __name__ == '__main__':
app = QApplication(sys.argv)
qt_translator = QtCore.QTranslator(app)
list_translate = [
QT_TRANSLATE_NOOP("test", "fake"),
QT_TRANSLATE_NOOP("test", "thing"),
QT_TRANSLATE_NOOP("test", "something")
]
for item in list_translate:
_translate("test", item, "1")
_translate("test", "other thing")
从这里我找到了 QT_TRANSLATE_NOOP。但我无法弄清楚如何让 pylupdate 继续使用消歧义评论。每次我运行它时,它都会将我在文件中的那个标记为过时并创建一个新条目。有没有办法在文字中指定注释?
.ts 开始:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS><TS version="2.0">
<context>
<name>test</name>
<message>
<location filename="test.py" line="17"/>
<source>other thing</source>
<translation>tran</translation>
</message>
<message>
<location filename="test.py" line="11"/>
<source>fake</source>
<comment>1</comment>
<translation>slate</translation>
</message>
<message>
<location filename="test.py" line="12"/>
<source>thing</source>
<translation>something</translation>
</message>
<message>
<location filename="test.py" line="13"/>
<source>something</source>
<translation>still something</translation>
</message>
</context>
</TS>
运行后的.ts文件
pylupdate5 -verbose test.py -ts translate/test.ts
注意第 14 行:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS><TS version="2.0">
<context>
<name>test</name>
<message>
<location filename="test.py" line="17"/>
<source>other thing</source>
<translation>tran</translation>
</message>
<message>
<location filename="test.py" line="11"/>
<source>fake</source>
<comment>1</comment>
**<translation type="obsolete">slate</translation>**
</message>
<message>
<location filename="test.py" line="12"/>
<source>thing</source>
<translation>something</translation>
</message>
<message>
<location filename="test.py" line="13"/>
<source>something</source>
<translation>still something</translation>
</message>
<message>
<location filename="test.py" line="11"/>
<source>fake</source>
<translation type="unfinished">slate</translation>
</message>
</context>
</TS>