Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
System language in Harmattan?
I'm looking for a way to find out the system language from a Qt application in Harmattan (I mean the language set in the N950 System Settings) because QLocale::system() always returns en_US for me.
File a bug for Qt then, please, if your system language does not match what you get from QLocale.
You seem to be right about that:
QLocale test = QLocale::system();
qDebug() << "System locale:" << test.name();
qDebug() << "MLocale:" << locale.name();
System locale: "en_US"
@Andre: yes, I thought about that, but then I've found this closed bug report: https://bugreports.qt.nokia.com/browse/QTBUG-15851
@gri: thanks, looks like we need to use MLocale for this. One problem with this solution is that the header MLocale is only available in QtCreator when using the build configuration "Harmattan Platform API" and not in "Meego 1.2 Harmattan API". And of course, requires conditional compilation in multiplatform projects.
Interesting reasoning in that bugreport. I would try to reopen it. Perhaps Harmattan doesn't work "the unix way" in this, but how is that the problem of the Qt user? What's more, isn't Harmattan a Nokia product as well? Such a conditional belongs, IMHO, in QLocale or the underlying platform plugins, not in the end users code.
@Andre: agreed. Windows doesn't follow POSIX either, but QLocale::system() returns in Windows the correct and expected results. I don't understand why we need to use a low level native approach on Harmattan.
Don't judge too fast here.
If you use qt-components in harmattan, recent versions have a global "locale" context property. "locale.name" in qml should return the two letter code.
See the exposed properties here: https://qt.gitorious.org/qt-components/qt-components/blobs/master/src/meego/i18n/mlocalewrapper.h#line197
@plcl: I have not even installed the Meego 1.2 version of the SDK since it contains less libraries than the Harmattan Platform API (which is also missing many things that have to be copied from Scratchbox)
@gri: that will be nice for pure QML applications. Unfortunately, in latest Qt SDK 1.1.3 released on September 1st is not available.
It's not a problem of the SDK, more of the version on your device. Mine also doesn't seem to have this recent version of qt-components, though.
So you may change to "Harmattan Platform API", which contains almost the same APIs as the "Nokia Meego 1.2" thingy and use ifdefs which is not that evil :)
Hmmm.... I thought the point of Qt was "code once, deploy everywhere". This kind-of negates that, doesn't it?
I do appreciate that there are work-arounds, but that is not the point. IMHO, work-arounds, Harmattan-only solutions should not be needed. It is certainly not the direction Qt should go into. It will result in different flavours of Qt, that are not compatible with each other, with lots of pitfals in porting from the one to the other. IMO, that is not a desireable situation.
Ever tried to write a software which runs on linux, mac, windows and some phones? I bet you can't do it without ifdefs. In most cases "code once" applies to your backend, but the gui has to be done for mobile and desktop platforms separately.
For example Qt Mobility does not even provide a native contact picker. Sometimes even behavior is different between the platforms. "code once" does not mean "don't code ifdefs" :)
I also read this some time ago that you should create your backend and the qml gui is throwaway for every platform.
EDIT: This doesn't mean I would not like to have QLocale working on harmattan :)
For GUI's, especially between desktop and the mobile, you are right. However, QLocale is not part of QtGui, it is in QtCore which is supposed to be working on all platforms.
ggiovanni88 last edited by
I have successfully used QString locale = QLocale::system().name() to translate a mobile application for harmattan, n950 with latest firmware. Used meego 1.2 harmattan api and it returned it_IT with my current settings.