How can my program have 2 languages?



  • [quote author="Joey Dumont" date="1309262146"]Just make sure that when you write user-visible stuff (like the title of a dialog) you put the option tr("Insert text here") enabled. This will ease the translation process.

    I know you have accents in Greek, so it may be better to use

    @trUtf8("Insert text here")@ [/quote]

    That's what am i using..

    [quote author="Vass" date="1309261862"]Qt have good integrated system for it.
    See "QTranslator":http://developer.qt.nokia.com/doc/qt-4.7/QTranslator.html[/quote]

    Could i have some tips at this? I don't know nothing about QTranslator.. Any example with a simple layer saying "Hello", i don't know something more than just a Class Reference :/

    EDIT: I am now reading Qt Linguist Manual. I hope it will help me..





  • I just created my first translation file.. I will try to do it my own.. I will check the FAQ later.. Thanks :)



  • If you consider your problem as solved, could you please the thread title and add [SOLVED].

    Thanks!



  • You should read documentations carefully and you will have no problem.

    In case that you couldn't managed to do the stuff, do these:

    1- In your qt project file (.pro) add this line:
    @TRANSLATIONS += program_gr.ts@
    Of course names and number of translations are optional.

    2- start lupdate tool (which is an executable installed with Qt SDK) given your project file name. for example:
    @
    lupdate ./program.pro
    @
    this scans your source code tree and determines translatable strings, then generates a XML-based translation file. in above example generates program_gr.ts.

    3- Now you can perform actual translation! open your translation file with Qt Linguist and translate strings. then save the file and exit. It's easy !

    4- Now that you have translated strings, you should make binary translation file. just call lrealease and give your ts file name:
    @
    lrealease program_gr.ts
    @
    this will generate profram_gr.qm that you can load in your program.

    5- when application starts, load your qm file using QTranslator class. in a widget-based application it may look like this:
    @
    #include <QtGui/QApplication>
    #include <QTranslator>
    #include "mainwindow.h"

    int main(int argc, char argv[])
    {
    QApplication a(argc, argv);
    QTranslator
    translator;
    translator->load(a.applicationDirPath()+"/program_gr.qm"); // or other place that you put your .qm file
    a.installTranslator(translator);
    MainWindow w;
    w.show();
    return a.exec();
    }
    @

    note that you can load translations dynamically and use them whenever you need. but you should be careful about calling translation method for all of dialogs.



  • Basically i saw a tutorial here ( http://www.youtube.com/watch?v=V9Gep6-r8ns ). It is the same with yours except that i can't understant what the guy is saying at Indonesia language..

    Also at step 5 i have this

    @QTranslator translator;
    translator.load("program_gr");
    a.installTranslator(&translator);@

    Ok so i create the gm file. BUT. As i said my program is for Ubuntu so i will make a deb file ( like setup.exe files at Windows.. ).. How can i provide the greek translation file and how after the program is installed users can translate the app to greek? ( Install my greek translation file so they can see the app translated at greek )



  • Ok, it looks like an "Installation and Deployment" problem...

    In linux directories used for configuration files are:
    /etc/program and /home/user_name/.program and /usr/share/program/

    Due to linux file system standards I suggest put your translation files in /usr/share/program/translations.



  • Ok thanks for the info! I will try it.. When everything is ok i will edit my post to [SOLVED] :D



  • The translations at /usr/share/program/translations must be at .ts format or .qm format?



  • [quote author="Leon" date="1309285305"]The translations at /usr/share/program/translations must be at .ts format or .qm format?[/quote]

    .qm

    .ts format for developers (translation source)
    .qm format for end users (translation binary)



  • [quote author="Leon" date="1309285305"]The translations at /usr/share/program/translations must be at .ts format or .qm format?[/quote]

    You need only qm files in runtime. ts files are used to translate. at runtime you want to load translated data.
    Also notice that there is no magic with /usr/share/program/translations. that was just a suggestion. you could put your translations in every other location...



  • Ok thanks guys.. I am working on it..

    soroush i know it is a suggestion :P


  • Moderators

    The .qm files can also be included as resources, too.



  • I am thinking of having english greek dutch and french language at my program.. Should i have a combobox with this 4 languages only ( using the resource file) or should i check for file existences at the path that i have my translations and then add them to the combobox?



  • Second way sounds better - this allow your users adding new languages for your app without re-compilation.
    of course if your public .ts file.



  • Yes but who would do that? I think i will go with the first one and if anyone translate my app i will add the language at another version.. :)



  • Hello again! What do you suggest? After the language has been changed ( at a combobox probably ) instantly everything change to the language you selected with "this way":http://developer.qt.nokia.com/faq/answer/how_can_i_dynamically_switch_between_languages_in_my_application_using_e.g_ or change the language after you restart the application?



  • What I did was this:

    1- Create a proxy subclass of QDialog named ProxyDialog wich have only one method: retranslateUI()
    2- Subclass all dialogs from ProxyDialog
    3- When you need to translate UI, just iterate over children of type ProxyDialog* and call retranslate UI for all of them. this is possible using findChildren function.



  • So you suggest that i should translate everything instantly?



  • Yes. I'm not sure if there is a better way or not, but I looked around a lot and couldn't fount anything.
    This works well for my applications.
    You don't have to restart your application to see translation results. All open dialogs will be translated on-the-fly.



  • Ok then, thanks again!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.