QT中提供了支持国际化的QTranslator, 这一工具确实很方便实现简单而且功能丰富的国际化功能,但是如何自己实现自定义的国家化翻译工具呢,如何通过file-driven来实现翻译工具呢?
相比大家知道,我在上篇文章中提到了关于如何使用QTranslator的心得和建议。通过lupdate,linguist,lrelease来对代码中我们标定的tr()字符来进行翻译。
转载请注明出处: http://blog.csdn.net/elfprincexu
总结下来就是:
- surround all literal strings (the ones to be translated) with tr() functions, i.e. tr("This will be translated");
- use lupdate command to extract translatable text into translation files (.ts)
- translate the text files by means of Qt Linguist (since .ts files are actually XML files, they can even be edited with any text editor)
- use lrelease command to transform the translated .ts files (text) into a binary representation format (.qm) files
具体参考我的上一篇文章: 个人亲测: QT Translate 国际化和本地化的一些使用心得和注意点 http://blog.csdn.net/elfprincexu/article/details/37698129
我想大部分代码工作者都会这么做,确实,但是当你不断想增加一些翻译资料,你就不得不反复的重复上述的步骤。
这里我提供一个基于文件的翻译机制给大家分享一下: