Results 1 to 5 of 5

Thread: QCalendarWidget and dynamic language switching

  1. #1
    Join Date
    Jan 2008
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QCalendarWidget and dynamic language switching

    I'm using in my application a QCalendarWidget but I'm not able to find where the translations related to this widget are. Looking in qt_*.ts there is no hint to this widget.
    What do I have to do to dynamically change the language of this widget?

    Thanks in advance

  2. #2
    Join Date
    Sep 2009
    Posts
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QCalendarWidget and dynamic language switching

    use QLocale

    QCalendarWidget *w = new QCalendarWidget;

    w->setLocale( QLocale::English );

  3. The following user says thank you to Matriarch for this useful post:

    tora (22nd September 2009)

  4. #3
    Join Date
    Jan 2008
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QCalendarWidget and dynamic language switching

    The problem is that I'm doing dynamic language switching like explained in "C++ GUI Programming with Qt4", i.e. implementing in every form/window a method retranslateUi() where all the GUI strings are set and overriding the changeEvent(QEvent*) method so that every time the event is a LanguageChange event, retranslateUi() is called. in the event handler changeEvent I've no information about which language was set (which qm file was loaded) and then I cannot map it to the correct locale.
    I do not understand why QCalender widget behaves so differently, the reason why its translateble strings are not in qt_*.ts.

  5. #4
    Join Date
    Sep 2009
    Posts
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QCalendarWidget and dynamic language switching

    I never used Qt internalization, so I don't know how it exactly works. But If your customer needs behaviour like you described, just try some "quick and dirty" trick.

    1) create ISO language name holding label, which is translatable and non visible for user.

    QLabel *locale = new QLabel(this);
    locale->setText( tr("en") );
    locale->hide();

    2) Put other ISO language names to your .ts file and use QLocale::QLocale ( const QString & name ) constructor. Look for inspiration in: http://www.w3.org/WAI/ER/IG/ert/iso639.htm

    switch (e->type()) {
    case QEvent::LanguageChange:
    retranslateUi();
    myCalendarWidget->setLocale(QLocale(locale->text));
    break;
    default:
    break;
    }

    There will be surely much clearer way to achieve this, but as i said i never used internalization...

  6. #5
    Join Date
    Jan 2008
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QCalendarWidget and dynamic language switching

    Thank you Matriarch for your help.
    Yes the only solution seems to be to have a "global" string that contains the locale corresponding to the last loaded .qm.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.