Saulius Žemaitaitis
Saulius Žemaitaitis

Reputation: 2974

Add specific phrases from Qt framework to my application's translation files

Is there a way to add specific phrases from Qt frameworks's internal .ts files to my application's translation files? I only need to translate several phrases for QMessageBox and friends.

EDIT:

I also want to:

  1. Bundle the phrases inside my application's .ts file
  2. Prevent them from going obsolete after a routine lupdate

There's always an alternative to subclass QMessageBox, but I'd like to try a perfectionist solution first.

EDIT #2:

I've solved the problem the ugly way by shipping a .qm file with my application from the Qt distribution. I'll keep this question open in case somebody comes up with a more elegant solution.

Upvotes: 1

Views: 381

Answers (2)

Johnny
Johnny

Reputation: 1974

EDITED: For custom translation of internal Qt phrases you only need to do some steps:

  1. Modify appropriate qt_lang.ts in translation folder inside Qt SDK directory. I strongly recommend you to use Qt linguist for this purpose.
  2. Use lrelease utility on qt_lang.ts to produce .qm file.
  3. Modify your code. You need to install generated translation file in your app by using QTranslator class.
  4. Distribute your app with generated .qm. All .qm files must be arranged in special dir relative to your app binary. By default it is translations folder, but you can change this dir by using custom qt.conf.

So when you change app language you'll get needed (translated by you) phrases.

For example, if you want to achieve custom translation for russian friends you need to open qt_ru.ts in Qt Linguist, locate there QMessageBox context and translate all needed phrases. Then follow described above instruction.

Upvotes: 1

armonge
armonge

Reputation: 3138

In Qt you can load various ts files for your application, i would try not to extract the needed phrases but load the qt ts files along with your own translation

Upvotes: 0

Related Questions