Skip to content

esutton/qt-translation-example

Repository files navigation

qt-translation-example

  • Use menu to switch between German and English.
  • Tested on macOS and Android using Qt 5.9.4 LTS

Based on this example:

Working with Qt Translation

  1. Add languages you wish to support to your Qt project file (*.pro) and run qmake again
TRANSLATIONS += \
    languages/TranslationExample_en.ts  \
    languages/TranslationExample_de.ts
  1. Use Qt lupdate to auto-generate your inital ts files.

    • From Qt Creator menu select:
      • Tools > External > Linguist > Update Translations (lupdate)
  2. For each <message> found in each TSL file translate the <source> text and paste into <translation>

    • Manually change translation/@type attribute from "unfinished" to "finished".
    • Or delete translation/@type attribute after translation.
    • When you run lupdate again, it will removed all translation/@type=finished attributes
      • Missing type attribute is same as "finished"
      • Y
    • For small one-by-word projects, use free web browser Google Transalte.
    • I made this node.js script that requires a commercial Google Trnaslate API key:
  3. Use Qt lrelease to generate compressed *.qm files from translated *.ts files

    • From Qt Creator menu select:
      • Tools > External > Linguist > Release Translations (lrelease)
  4. Copy *.qm files to the embedded resource folder ./res/translation

    • ToDo: Add code to *.pro file to copy *.qm to ./res/translation

Automated Translation Using Google Translate

I created this i18n-translate-qt-ts as a node.js command line utility.

Use requires a commercial Google Translate API key:

To add translations to all ./languages/*.ts files in the qt-translation-example project:

# Use environment variable to store your API key
export API_KEY=AIzy0Vj...AIzy0VjQ
node index.js ${API_KEY} languages en
  • If errors occur, you may need to run multiple times until all strings have translations.
    • Perhaps throttling the API calls might help this.
  • If needed, send auto-translations to a native speaker for improvements.
    • i18n-translate-qt-ts will not update a manual translation unless translation/@type=unfinished or source string is non-empty and <translation> is empty.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published