Skip to content

Using Google Translate to translate your Qt application

Jaco Naude edited this page Apr 2, 2014 · 3 revisions

This article describes an easy way that can be used to translate your Qt application into any language supported by Google Translate. This is done using the Google Translation Toolkit (so you need a Google account to use it).

This article assumes that you are at the point where you've successfully exported all tr'ed strings in your source code to a .ts file. If that is not the case, the following is a good place to start: Qt Linguist Manual

Upload your .ts to the Google Translation Toolkit

  • First we need to convert the .ts file into a format supported by the translation toolkit. I decided to use GNU gettext (.PO) because Qt's own lconvert supports it.
  • Converting .ts to .po file is done like this:
lconvert <file>.ts -o <file>.po

There are also alternative tools to do the conversion, see this post.

  • On the Translation Toolkit page click the Upload button and select the .po file.
  • Follow the steps (skip the translation services step) and you will end up with a page which contains automatic translations for all strings in your .ts in the language you selected.
  • Note that the automatic translations should be checked by someone with knowledge of the target translation since the toolkit does not understand things such as the & characters used by key accelerators (see Alt Key Accelerators and Ctrl Key Accelerators on this page for more information). Also, it does not handle numbered arguments (the %1, %2 etc.) and escaped quotation marks (") properly.

Download completed translations

  • Download the completed translation using File -> Download in the Translation editor.
  • The downloaded .po file can now be converted back into a .ts file which can be imported back into Qt Linguist in order to verify and release it.
lconvert -locations relative <file>.po -o <file>.ts

At this point, it is worth to mention that the things mentioned in the last bullet of the previous section can mess things up. Luckily lconvert give line numbers where problems are found and they can normally be easily fixed. For example:

PO parsing error: invalid escape '\σ' (line 1792).
PO parsing error: invalid escape '\µ' (line 1805).
PO parsing error: invalid escape '\ ' (line 1850).
PO parsing error: invalid escape '\ ' (line 1850).
PO parsing error: invalid escape '\ ' (line 1850).
  • Once all issues were solved, open the generated .ts file in Qt Linguist and do some checks on it before running it through lrelease.

Lessons learned

  • Google Translate Toolkit should really be used as a helper tool to accelerate the translation process. For high quality translations a native language speaker should review the actual translations.