QT 国际化扩展所感 an extending QT Translator (自己实现翻译逻辑,编辑更方便)

本文介绍了如何在QT中不依赖QTranslator,而是通过自定义的基于XML文件的翻译机制来实现国际化。作者提出创建XML文件存储翻译内容,并提供了一个名为Mytranslator的类,用于读取、解析这些文件,从而在程序中动态地添加和编辑翻译。
摘要由CSDN通过智能技术生成
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


我想大部分代码工作者都会这么做,确实,但是当你不断想增加一些翻译资料,你就不得不反复的重复上述的步骤。


这里我提供一个基于文件的翻译机制给大家分享一下:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值