Detect system locale.
This commit is contained in:
parent
5414848bbd
commit
202f2b6f10
@ -4,6 +4,8 @@
|
||||
#include "core/settings.h"
|
||||
#include "qtsingleapplication/qtsingleapplication.h"
|
||||
|
||||
#include <QPointer>
|
||||
#include <QApplication>
|
||||
#include <QTranslator>
|
||||
#include <QDir>
|
||||
#include <QFileInfoList>
|
||||
@ -12,6 +14,42 @@
|
||||
Localization::Localization() {
|
||||
}
|
||||
|
||||
void Localization::load() {
|
||||
QTranslator *qt_translator = new QTranslator(qApp);
|
||||
QTranslator *app_translator = new QTranslator(qApp);
|
||||
QString locale_system = QLocale::system().name();
|
||||
QString locale_name = Settings::instance()->value(APP_CFG_GEN,
|
||||
"language",
|
||||
locale_system).toString();
|
||||
|
||||
qDebug("Try to load application localization. "
|
||||
"System locale was detected as '%s'. "
|
||||
"Trying to load localization for '%s'.",
|
||||
qPrintable(locale_system),
|
||||
qPrintable(locale_name));
|
||||
|
||||
if (app_translator->load(QString("rssguard_%1.qm").arg(locale_name),
|
||||
APP_LANG_PATH)) {
|
||||
QApplication::installTranslator(app_translator);
|
||||
qDebug("Application localization '%s' loaded successfully.",
|
||||
qPrintable(locale_name));
|
||||
}
|
||||
else {
|
||||
qWarning("Application localization '%s' was not loaded.", qPrintable(locale_name));
|
||||
}
|
||||
if (qt_translator->load(QString("qt_%1.qm").arg(locale_name),
|
||||
APP_LANG_PATH)) {
|
||||
QApplication::installTranslator(qt_translator);
|
||||
qDebug("Qt localization '%s' loaded successfully.",
|
||||
qPrintable(locale_name));
|
||||
}
|
||||
else {
|
||||
qWarning("Qt localization '%s' was not loaded.", qPrintable(locale_name));
|
||||
}
|
||||
|
||||
QLocale::setDefault(QLocale(locale_name));
|
||||
}
|
||||
|
||||
QList<Language> Localization::installedLanguages() {
|
||||
QList<Language> languages;
|
||||
QDir file_dir(APP_LANG_PATH);
|
||||
|
@ -1,34 +1,7 @@
|
||||
#ifndef LOCALIZATION_H
|
||||
#define LOCALIZATION_H
|
||||
|
||||
// Loads currently active language.
|
||||
// NOTE: Macro is used due to QTranslator persistency.
|
||||
#define LoadLocalization(); \
|
||||
QString locale_name = Settings::instance()->value( \
|
||||
APP_CFG_GEN, \
|
||||
"language", \
|
||||
"en").toString(); \
|
||||
QTranslator qt_translator, app_translator; \
|
||||
if (app_translator.load(QString("rssguard_%1.qm").arg(locale_name), \
|
||||
APP_LANG_PATH)) { \
|
||||
QApplication::installTranslator(&app_translator); \
|
||||
qDebug("Application localization '%s' loaded successfully.", \
|
||||
qPrintable(locale_name)); \
|
||||
} \
|
||||
else { \
|
||||
qWarning("Application localization '%s' was not loaded.", qPrintable(locale_name)); \
|
||||
} \
|
||||
if (qt_translator.load(QString("qt_%1.qm").arg(locale_name), \
|
||||
APP_LANG_PATH)) { \
|
||||
qDebug("Qt localization '%s' loaded successfully.", \
|
||||
qPrintable(locale_name)); \
|
||||
} \
|
||||
else { \
|
||||
qWarning("Qt localization '%s' was not loaded.", qPrintable(locale_name)); \
|
||||
} \
|
||||
QLocale::setDefault(QLocale(locale_name));
|
||||
|
||||
#include <QPointer>
|
||||
#include <QString>
|
||||
|
||||
|
||||
struct Language {
|
||||
@ -45,6 +18,9 @@ class Localization {
|
||||
explicit Localization();
|
||||
|
||||
public:
|
||||
// Loads currently active language.
|
||||
static void load();
|
||||
|
||||
// Returns list of installed application localizations.
|
||||
// This list is used ie. in settings dialog.
|
||||
static QList<Language> installedLanguages();
|
||||
|
@ -66,7 +66,8 @@ int main(int argc, char *argv[]) {
|
||||
SkinFactory::instance()->loadCurrentSkin();
|
||||
|
||||
// Load localization and setup locale before any widget is constructed.
|
||||
LoadLocalization();
|
||||
//LoadLocalization();
|
||||
Localization::load();
|
||||
|
||||
// These settings needs to be set before any QSettings object.
|
||||
QtSingleApplication::setApplicationName(APP_NAME);
|
||||
|
Loading…
x
Reference in New Issue
Block a user