PDA

View Full Version : QLocale::system().name() returns "C" instead of "de"



momesana
18th February 2008, 15:25
Hi, I am working on a german windows 2000 workstation and wanted to try out a little application that I have written for our company. I had created translation files and wanted to load them at startup but realised they were not loaded. After putting in debug print statements I found out that the locale returned is "C" -- the fallback default locale -- as opposed to "de" which should be the case since this is a german windows installation. Can anybody tell me what I am doing wrong? May it be a windows 2000 issue?



#include <QApplication>
#include <QDebug>
#include <QLocale>
#include <QTranslator>
#include "pollmonitor.h"
#include "mainwindow.h"

#include <iostream> // DEBUG

int main(int argc, char* argv[])
{
QApplication app(argc, argv);
app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));

// Settings
QCoreApplication::setOrganizationName("MLHB");
QCoreApplication::setOrganizationDomain("mlhb.de");
QCoreApplication::setApplicationName("Hygiene-Befund");

// Translations
QString locale = QLocale::system().name();
qDebug() << locale; // DEBUG

QTranslator appTranslator;
QTranslator qtTranslator;
QString appTranslation = app.applicationDirPath()
+ "/../translations/" + QString("dirmon_" + locale + ".qm");
QString qtTranslation = app.applicationDirPath()
+ "/../translations/" + QString("qt_" + locale + ".qm");

// Load App Translation file
bool b;
b = appTranslator.load(appTranslation);
if (!b)
qDebug() << app.tr("couldn't load translation file %1").arg(appTranslation).toLatin1();

// Load Qt Translation file
b = qtTranslator.load(qtTranslation);
if (!b)
qDebug() << app.tr("couldn't load translation file %1").arg(qtTranslation);

app.installTranslator(&appTranslator);
app.installTranslator(&qtTranslator);

// Main Window
MainWindow mw;
mw.show();
return app.exec();
}

jgvaldecasas
18th February 2008, 15:59
I have found the same error in other project. But still, i haven't found the reason. Maybe someone can enlighten us :)