Qt World Summit: Submit your Presentation

How to use multiple locale at the same time?

  • Hi,

    I'm developing an HTTP server with Qt! I have internationalized my application and i know how to switch the locale of the complete application.

    I would like each client of the web interface can select his desired language. So each client session can have a different locale.

    One ugly solution i found should be to use mutex around each string to translate:
    tr("the string")

    But this will lack performance when multiple client are connected at the same time, because only one thread can get a string at the same time.

    I would like to know if there is not a better solution like a native tr() function with an additional parameters.

    For example, i would like to use:
    tr("mystring", "fr");
    tr("mystring", "de");
    tr("mystring", "en");

    Thank for your help

  • You shoud look at "QTranslator":http://qt-project.org/doc/qt-4.8/qtranslator.html
    You should instantiate one translator for each locale, and use the @QTranslator::translate(...)@ methods directly.

  • Thank you very much. I think i can deal with that.

Log in to reply