0

This question has unfortunately been asked before but I'm going insane here. In my Qt Application the user is able to dynamically change the language which works perfect for all my own translations. It does not work for my calls to QFileDialog. The respective code:

void myapp::change_language(std::string& lang_str){
    // my own translations works
    qApp->removeTranslator(&this->app_lang);
    this->app_lang.load(QString::fromStdString(lang_str));
    qApp->installTranslator(&this->app_lang);

    // system translations, works not for qfiledialog
    qApp->removeTranslator(&this->app_lang_qt);
    bool test = this->app_lang_qt.load("qt_fr.qm"); // returns true
    qApp->installTranslator(&this->app_lang_qt);
}

And

void myapp::changeEvent(QEvent* event){
    if(event->type() == QEvent::LanguageChange){
        this->ui.retranslateUi(this);
    }
    QMainWindow::changeEvent(event);
}

With

QTranslator app_lang;
QTranslator app_lang_qt;

The fixed string "qt_fr.qm" is just for testing purpose because french is easily detectable.

What I want is to change the language in static calls to QFileDialog and QMessageBox but the language is only changed in QMessageBox, not in QFileDialog. For both classes I'm only calling the static members to that can't be the issue. I also tried to install this translator in the main.cpp with the same results.

Community
  • 1
  • 1
Bowdzone
  • 3,827
  • 11
  • 39
  • 52
  • One thing the other solution differs, is that it loads the Qt translation FIRST. And also does not use app_lang_qt but instead bothe calls are to `installTranslator`. – RedX Mar 31 '14 at 14:01
  • Thanks for your reply. I will try to change the order although it shouldn't make a difference as the documentation states multiple translators can be installed. I don't really understand the second part of your comment. The linked solution is in the main function and therefore can use a local QTranslator. I implemented a dynamic change which requires me to save the QTranslator somewhere, so i have the two variables. Besides, moving the code to main() does not solve the problem. – Bowdzone Mar 31 '14 at 14:07
  • Yeah unfortunately, changing the order did not solve the issue. – Bowdzone Mar 31 '14 at 16:25

1 Answers1

3

By default, QFileDialog will use the native file browser rather than a custom Qt-based dialog. The native file browser is will be using the OS language, rather than the Qt language, and will not have Qt translations applied to it. You can override this behaviour using the DontUseNativeDialog option for QFileDialog.

deGoot
  • 996
  • 4
  • 11