问题
I try to set localization for standard save or open dialogs, but everything except window caption remains English.
I use Qt 4.7.4 and KDE of the same version.
The following example application:
#include <QApplication>
#include <QFileDialog>
#include <QTranslator>
#include <QLibraryInfo>
#include <QDebug>
int main(int argc, char **argv)
{
QApplication app(argc,argv);
QTranslator qTranslator;
QString transPath=QLibraryInfo::location(QLibraryInfo::TranslationsPath);
qTranslator.load("qt_ru",transPath);
app.installTranslator(&qTranslator);
qDebug() << transPath;
QFileDialog fileDialog(0, 0/*default caption*/,
QDir::currentPath(), "All files (*.*)");
fileDialog.exec();
return 0;
}
prints "/usr/share/qt4/translations"
(path to translations) and the warning:
KGlobal::locale::Warning your global KLocale is being recreated with a valid main
component instead of a fake component, this usually means you tried to call i18n related
functions before your main component was created. You should not do that since it most
likely will not work
I also tried some other more supported languages, such as German(qt_de), French(qt_fr) and Polish, but result was the same: only caption was affected.
But if I open a "Save" dialog in any application installed with KDE, all texts in dialog appear in Russian, and no warnings are printed to console. I tried dialogs in Kwrite, Firefox(it uses default KDE dialog), Konsole and Kaffeine.
Is the above code correct from the point of view of translation? Maybe there is another way to set localization for my app?
Why are the dialogs in other applications translated? Do they use other translation files, than files provided in /usr/share/qt4/translations
directory?
回答1:
Priviet Are You still have that problem? For this moment my solution is to add:
QFileDialog fileDialog(0, 0/*default caption*/,
QDir::currentPath(), "All files (*.*)", QFileDialog::DontUseNativeDialog);
to invoke a file dialog.
However in this way dialogs are Qt-native and doesn't respect KDE.
But I'm digging to find solution How to get KDE dialog in system language intead.
来源:https://stackoverflow.com/questions/12571895/save-open-dialog-localization-in-qt