lunes, 24 de octubre de 2011

Translations in Qt

I want to talk about a great feature in Qt, translations! I'm sure everyone have used a translated Software, as a Developer I was thinking how all that work, but I found how easy was to do it using Qt and I will explain it now.

First you need to add a line to your .pro indicating all translation you want, like this:

TRANSLATIONS = OrderMyPhotos_en.ts

Then you need to run the tool lupdate with your project file as a parameter.

lupdate project.pro

That generates the file OrderMyPhotos_en.ts

You have to open that using Qt Linguistic and start to translate, once you are done you have to run lrelease with your translated file

lrelease OrderMyPhotos_en.ts

That will generate OrderMyPhotos_en.qm

In order to use that you just have to do

QTranslator translator;
translator.load("OrderMyPhotos_en");
a.installTranslator(&translator);

And that's it, 

No hay comentarios:

Publicar un comentario