Git Product home page Git Product logo

i18n's Introduction

Qt5.10 多语言动态翻译

Build Status

  • 不需要重启程序

I18n

编译运行

qmake && make -j8 && ./I18n

或者使用qtcreator导入pro并运行

翻译步骤整理

  1. qml 中使用qsTr 标记要翻译的文本

  2. 在pro中添加翻译文件ts,例如:

TRANSLATIONS += I18n_zh.ts \
        I18n_en.ts
  1. 使用lupdate (通过命令行,或者qtcreator->Tools->External->Linguist->lupdate),会在源码路径下生成ts文件

  2. 使用linguist (Qt5.10.0/5.10.0/gcc_64/bin/linguist)导入ts文件,进行翻译

  3. 使用lrelease,(通过命令行,qtcreator 或者 linguist),生成qm文件。

    ts文件是xml格式的文本,qm文件是对其压缩过的二进制格式。两者都可以使用linguist导入

  4. qm文件放入运行路径,或者加入qrc资源

  5. 使用QTranslator加载qm文件

  6. 在需要切换语言的地方,切换Translater,并触发QQmlEngine::retranslate

QCoreApplication::removeTranslator

QCoreApplication::installTranslator

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.