How to get current application language
-
wrote on 11 Jul 2011, 08:14 last edited by
Hi,
Is there way to get current application language that is set to ?
QLocale and Qt mobility gives only system language but i want to identify what is the current application language set to.
My application set language based on user selection, However to avoid what user has set and store in some variable. If it is possible to get current application language. I would save tiny portion of memory :)
-
wrote on 11 Jul 2011, 09:01 last edited by
Here is a wiki content with sample codes which should solve your problem:
"How to create a multi lingual application that can switch the language at runtime":http://developer.qt.nokia.com/wiki/How_to_create_a_multi_language_application? -
wrote on 11 Jul 2011, 09:59 last edited by
Thanks for the post but i am looking for an API to give me an application language that is set instead of storing it in the application.
However but it seems like there is no API for that and i will have to handle it in my app accordingly.
-
wrote on 18 Jan 2015, 22:06 last edited by
Bumping this old thread, but I have the same problem.
I need a way to get the current application language, or perhaps the list of loaded translations. Is it possible now?
-
wrote on 18 Jan 2015, 22:06 last edited by
Bumping this old thread, but I have the same problem.
I need a way to get the current application language, or perhaps the list of loaded translations. Is it possible now?
-
Just see whether this can help..
@ QString str = loc.languageToString(loc.language());
qDebug() << " String ="<<str << endl;@ -
Just see whether this can help..
@ QString str = loc.languageToString(loc.language());
qDebug() << " String ="<<str << endl;@ -
wrote on 19 Jan 2015, 18:43 last edited by
Thank you Dheerendra, but I don't think that helps.
I'm using QTranslator::load() and QCoreApplication::installTranslator() to translate the menus. But later I'd like to get the loaded language, out of the function that has the locale object.I already have a workaround for this, but I was just wondering if there is a direct way to get this information.
-
wrote on 19 Jan 2015, 18:43 last edited by
Thank you Dheerendra, but I don't think that helps.
I'm using QTranslator::load() and QCoreApplication::installTranslator() to translate the menus. But later I'd like to get the loaded language, out of the function that has the locale object.I already have a workaround for this, but I was just wondering if there is a direct way to get this information.
-
wrote on 27 Jan 2015, 01:17 last edited by
[quote author="koplersky" date="1421693019"]Thank you Dheerendra, but I don't think that helps.
I'm using QTranslator::load() and QCoreApplication::installTranslator() to translate the menus. But later I'd like to get the loaded language, out of the function that has the locale object.I already have a workaround for this, but I was just wondering if there is a direct way to get this information.[/quote]
What workaround did you use?
-
wrote on 27 Jan 2015, 01:17 last edited by
[quote author="koplersky" date="1421693019"]Thank you Dheerendra, but I don't think that helps.
I'm using QTranslator::load() and QCoreApplication::installTranslator() to translate the menus. But later I'd like to get the loaded language, out of the function that has the locale object.I already have a workaround for this, but I was just wondering if there is a direct way to get this information.[/quote]
What workaround did you use?
-
a little trick would be to add a translation for e.g. APP_LANGUAGE to every translation file and to translate it to the language's native name for each.
Then you simply can use
@
QObject::tr("APP_LANGUAGE")
@ -
a little trick would be to add a translation for e.g. APP_LANGUAGE to every translation file and to translate it to the language's native name for each.
Then you simply can use
@
QObject::tr("APP_LANGUAGE")
@ -
wrote on 27 Jan 2015, 20:05 last edited by
It turns out to be very simple:
http://stackoverflow.com/questions/28161888/how-to-find-current-qlocale-in-qt-pyqt-pysideJust enter
x=QtCore.QLocale()and then all the QLocale methods apply to x. E.g.,
x.language()That's Python, probably similar in c++
-
wrote on 27 Jan 2015, 20:05 last edited by
It turns out to be very simple:
http://stackoverflow.com/questions/28161888/how-to-find-current-qlocale-in-qt-pyqt-pysideJust enter
x=QtCore.QLocale()and then all the QLocale methods apply to x. E.g.,
x.language()That's Python, probably similar in c++
-
wrote on 28 Jan 2015, 07:47 last edited by
The current locale is not the same as the current application language. We allow switching the application language manually for instance (though the default is based on the locale).
-
wrote on 28 Jan 2015, 07:47 last edited by
The current locale is not the same as the current application language. We allow switching the application language manually for instance (though the default is based on the locale).
-
wrote on 28 Jan 2015, 10:51 last edited by
How about managing it logically?
Example: Maintain a member variable called m_currentLanguage to contain the information about current language and refer it whenever required.
-
wrote on 28 Jan 2015, 10:51 last edited by
How about managing it logically?
Example: Maintain a member variable called m_currentLanguage to contain the information about current language and refer it whenever required.
-
wrote on 24 Mar 2025, 01:04 last edited by
10 years later, but it was an issue for me too. So here's the simple solution, the QLocale() default constructor returns the current application settings, so the following returns the current application language as a string:
QLocale::languageToString ( QLocale().language() )