Qt Linguist Manual: Release Manager
Qt Linguist Manual: Release Manager
Qt为发布管理器(Release Manager)提供了lupdate 和 lrelease 这两个工具。这两个工具可以用来处理qmake 项目文件(.pro),或者直接在文件系统上操作。
Qt Project Files
利用.pro文件来使用lupdate和lrelease是最方便的一种方式。在.pro文件中的TRANSLATIONS字段里面,必须为每一个需要被翻译成为
的语言加一个条目。典型的情况如下:
TRANSLATIONS = arrowpad_fr.ts \
arrowpad_nl.ts
在翻译文件名中加入语言信息,对在运行时决定加载哪一种语言是很有用的。这个在Programmers章节中有更多的解释。
一个带有四个翻译源文件的完整的.pro文件例子:
HEADERS = main-dlg.h \
options-dlg.h
SOURCES = main-dlg.cpp \
options-dlg.cpp \
main.cpp
FORMS = search-dlg.ui
TRANSLATIONS = superapp_dk.ts \
superapp_fi.ts \
superapp_no.ts \
superapp_se.ts
CODECFORTR = ISO-8859-5
使用QTextCodec::setCodecForTr(),可以为tr()里的literal strings选择8-bit编码。这对于源语言是中文或日文等文字的应用来说
是很有用的。如果没有设置编码方式,tr()默认使用Latin1。
如果确实在程序中使用了QTextCodec::setCodecForTr()机制,Qt Linguist要求在.pro文件中同时设置CODEFORTR条目。例如:
CODECFORTR = ISO-8859-5
同时,如果你的编译器对它的运行时系统和源代码使用不同的编码方式,并且你想在string中使用非ASCII字符,你需要设置
CODEFORSRC,例如:
CODECFORSRC = UTF-8
Microsoft Visual Studio 2005 .NET好像是唯一需要上述设置的。然而,如果你想写通用的代码,建议你在源文件中避免是用
非ASCII字符。当然你可以通过使用反斜线方式来使用非ASCII字符,例如:
label->setText(tr("F\374r \310lise"));
lupdate
语法:lupdate myproject.pro
lupdate是一个命令行工具,用来在源文件,头文件和.ui文件中寻找指定的可翻译的字符串,并且生成或更新.ts翻译文件。
需要处理或更新的文件可以在命令行中指定,或者在作为参数所提供的.pro文件中指定。生成的.ts文件可以用Qt Linguist操作。
TS文件格式是一种简单可读的XML格式,如果需要,可以被版本控制系统使用。lipdate也可以处理Localization Interchange File Format (XLIFF)格式文件;这种格式的文件已.xlf作为后缀名。
注意:XLIFF格式文件的最低支持版本为1.1,1.0版本不支持。
在lupdate选项中键入-help可以获得所支持的选项:
Usage:
lupdate [options] [project-file]
lupdate [options] [source-file|path]... -ts ts-files
Options:
-help Display this information and exit.
-noobsolete
Drop all obsolete strings.
-extensions <ext>[,<ext>]...
Process files with the given extensions only.
The extension list must be separated with commas, not with whitespace.
Default: 'ui,c,c++,cc,cpp,cxx,ch,h,h++,hh,hpp,hxx'.
-pluralonly
Only include plural form messages.
-silent
Do not explain what is being done.
-version
Display the version of lupdate and exit.
Qt Linguist也可以用来导入导出XLIFF文件。查看Translators章节获得更多信息。
lrelease
语法:lrelease myproject.pro
lrelease是一个命令行工具,用来从TS(.ts)文件生成QM(.qm)文件。QM文件是一种可以被本地化程序使用的压缩的二进制格式文件。它对翻译的查找非常快。需要处理的TS文件可以在命令行中指定,或者在作为参数所提供的.pro文件中指定。
注意,lrelease仅会处理被标记为"finished"的翻译。否则将会用原生文本代替。
在lrelease选项中键入-help可以获得所支持的选项:
Usage:
lrelease [options] project-file
lrelease [options] ts-files [-qm qm-file]
lrelease is part of Qt's Linguist tool chain. It can be used as a
stand-alone tool to convert XML-based translations files in the TS
format into the 'compiled' QM format used by QTranslator objects.
Options:
-help Display this information and exit
-idbased
Use IDs instead of source strings for message keying
-compress
Compress the QM files
-nounfinished
Do not include unfinished translations
-removeidentical
If the translated text is the same as
the source text, do not include the message
-markuntranslated <prefix>
If a message has no real translation, use the source text
prefixed with the given string instead
-silent
Do not explain what is being done
-version
Display the version of lrelease and exit
lupdate和prelease都可能与不完整的TS文件一起使用。在运行时,缺少的翻译将被替换为母语短语。