This complete guides is based on the Qt Linguist Manual for Qt 4.1 by Trolltech
Translators Guide
This guide should give a quick hint how to translate kommute for your language.
- The developer's way
- The non developer's way
- The translation
- Compiling and testing
- Submit the translation
1) The developer's way
This way is only for developers. You need:
- cvs access
- qt 4
- some time
- open the src.pro to edit in there
- search the translations entry. There are some entries like "translations/kommute_de.ts" before. The "translations/kommute_<language>.ts" is always the same
- we should know the language code of the language you want to translate to. If you want to translate to French, the language code will be fr. For german, it's de. And for the USA us. And so on. The language codes can be found here.Only the iso-codes should be used.
If you wish, you can add a the country code after the language code. For german in switzerland this would be de_CH, were the CH is the country code for switzerland, the de the language code. The country codes can be found here. The first column lists the country codes. In the later parts of this guide,the language code is always mentioned. If you wish to use a country code, feel free to use it. If you want to load the de_DE translation which can't be found, Qt loads the de translation if this is available.
But be aware: If you only give a translation for de_DE ( german in Germany ) and somebody in Austria ( de_AT ) or Switzerland ( de_CH ) starts kommute, they will get an untranslated version. But de_DE, de_AT and de_CH all use a de translation, if no country specific can be found. - So we add a translation code to the src.pro. If you want to do a French translation, add translations/kommute_fr.ts to the src.pro
- Save the file and open a terminal in the folder, where your src.pro is
- Type
lupdate src.pro
- This will produce a file called kommute_fr.ts in the translations folder
The next steps are the same as for the non developer way, so we continue at 3)
2) The non developer's way
Non developers need to subscribe to the kommute translation list. If they are subscribed, they can send a message there with the subject: translation support: language, where language would be the language you want to translate to. Please include your email address in the message. On of the developers will send you a translation file.
3) The translation
- Open the file kommute_language.ts in the Qt Linguist
- Open a new Phrase book by using on Phrases/Open Phrase Book. If a phrase book for the language you want to translate to exists already, use this. It will contain some basic translations which should be used. First it is easier for you to translate and we get overall translations for the same strings in various applications.
- Left are the different modules, use the first one and start the translation. For this, in the middle window is a field called Source text and a field called Translation. Under Translations you can place some text. Write the translation here for the word or text here. Special cases are the textboxes. If there is html text in there, you will see the whole html stuff also in there, with all fields. For the German translation I copied the whole stuff down to Translation and translated the text after that. This isn't a nice way, but the only one if we want to use the Qt-Designer and let the ui_ files be created automatically.
- If your translation for the word/text is done, press the Done & Next button. It will move you to the next untranslated word/text. But you don't need to translate all words/texts. Some of them are only numbers or have no real translation in the other language. In this case, leave the translation field blank. At html text sometimes the Done & Next button isn't available. In this case, continue translation and restart the Qt-Linguist with the translation file if you finished the rest. Now go to the words/texts again and press the Done & Next button.
- Now all your words/texts shall be translated, so move on to 4)
4) Compile and install Kommute
- First we need to compile the translated file. For this, start a console, go back to the directory where the src.pro is located. Now call
lrelease src.pro
This will compile the ts files to a qm file. This one can be read by the application. - Start kommute with ./kommute. If you translated kommute into your system language, then the language file will be loaded at start. If not, you need to edit the main.cpp. Open the main.cpp and look for a line called
QString locale = QLocale::system().name();
Under this line place alocale = QString("languagecode");with the language code you want in your app. Later I will add a possibility to set the locale at start. - Look at the output from kommute. It will tell you which locale it finds and what it tries to load. If the language file for that locale can't be found, the English messages are used.
- If all is working and you're happy with the result, move on to 5). Otherwise, go back to3)
5) Submit the translation
- If you are a developer, post a message on the kommute-translation mailing list and upload the translation file ( one the ts file, not the qm ) to the translations folder at cvs.
- For not developers, post a message on the kommute-translation mailing list with attached translation file. A developer will bring this to cvs then.
Programmers Guide
This guide should give a quick hint for programmers how to prepare the kommute source for translation.
- Preparing User-Visible Strings
- Preparing special cases of User-Visible Strings
- Let Kommute load the language file at startup
1) Preparing User-Visible Strings
In most cases the user-visible strings are in user interfaces, as example in a QDialog. So they are in a class derived from QObject. In all this QObject subclasses, also user ones, you replace
button = new QPushButton("&Quit", this);
withbutton = new QPushButton(tr("&Quit"), this);
All QObject subclasses that use the Q_OBJECT macro implement the tr() function.In most cases the user-visible strings will be part of a gui created with the Qt-Designer. The strings used there have the tr() function already in there. Have a look at the retranslateUi functions in the ui_ files created out of the designer files ( .ui ). The above mentioned is in the kommute project only necessary at strings that change during runtime. An example can be found in setupwizard.cpp, where the "Next" button transforms to a "Finish" button at the last widget.
2) Preparing special cases of User-Visible Strings
You can also translate Ctrl key accelerators:
exitAct = new QAction(tr("Exit") this);
exitAct->setShortcut(tr("Ctrl+Q", "Quit"));
There are also other cases, but these cases are so rare, so if there are problems, look at QT 4.1 Linguist Programmers Guide or mail to the kommute-devel mailing list
3) Let Kommute load the language file at startup
Yes, it's true. Qt loads the translation at runtime, it doesn't need them at compile time. Through this behavior it's possible to provide language files if their is no update to the kommute source.
But now, how to set Kommute to load the language file:
Your main.cpp (here starts every c++ app) consists of something like
QApplication app(argc, argv);After this lines, insert
QString locale = QLocale::system().name();This isn't necessary anymore, the main.cpp of Kommute is already prepared to translate Kommute.&
QTranslator translator;
translator.load(QString("kommute_") + locale);
app.installTranslator(&translator);
Credits
- Niels Sandholt Busch has written Kommute
- Andy Gebauer has written this guide.
