Initial localization switching.
This commit is contained in:
parent
60da04aa4d
commit
5cafffed4c
@ -286,6 +286,8 @@ if(WIN32)
|
|||||||
RUNTIME DESTINATION ./)
|
RUNTIME DESTINATION ./)
|
||||||
install(DIRECTORY resources/graphics/themes/mini-oxygen
|
install(DIRECTORY resources/graphics/themes/mini-oxygen
|
||||||
DESTINATION ./themes)
|
DESTINATION ./themes)
|
||||||
|
install(DIRECTORY resources/graphics/flags
|
||||||
|
DESTINATION ./)
|
||||||
install(FILES resources/graphics/${APP_LOW_NAME}_128.png
|
install(FILES resources/graphics/${APP_LOW_NAME}_128.png
|
||||||
DESTINATION ./
|
DESTINATION ./
|
||||||
RENAME ${APP_LOW_NAME}.png)
|
RENAME ${APP_LOW_NAME}.png)
|
||||||
@ -302,6 +304,8 @@ elseif(UNIX)
|
|||||||
RUNTIME DESTINATION bin)
|
RUNTIME DESTINATION bin)
|
||||||
install(DIRECTORY resources/graphics/themes/mini-oxygen
|
install(DIRECTORY resources/graphics/themes/mini-oxygen
|
||||||
DESTINATION share/${APP_LOW_NAME}/themes)
|
DESTINATION share/${APP_LOW_NAME}/themes)
|
||||||
|
install(DIRECTORY resources/graphics/flags
|
||||||
|
DESTINATION share/${APP_LOW_NAME}/)
|
||||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/resources/desktop/${APP_LOW_NAME}.desktop
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/resources/desktop/${APP_LOW_NAME}.desktop
|
||||||
DESTINATION share/applications)
|
DESTINATION share/applications)
|
||||||
install(FILES resources/graphics/${APP_LOW_NAME}_128.png
|
install(FILES resources/graphics/${APP_LOW_NAME}_128.png
|
||||||
|
@ -92,7 +92,7 @@
|
|||||||
<message>
|
<message>
|
||||||
<source>LANG_EMAIL</source>
|
<source>LANG_EMAIL</source>
|
||||||
<extracomment>Email of translator - optional.</extracomment>
|
<extracomment>Email of translator - optional.</extracomment>
|
||||||
<translation>martinrotter@users.sourceforge.net</translation>
|
<translation>rotter.martinos@gmail.com</translation>
|
||||||
</message>
|
</message>
|
||||||
</context>
|
</context>
|
||||||
</TS>
|
</TS>
|
||||||
|
@ -92,7 +92,7 @@
|
|||||||
<message>
|
<message>
|
||||||
<source>LANG_EMAIL</source>
|
<source>LANG_EMAIL</source>
|
||||||
<extracomment>Email of translator - optional.</extracomment>
|
<extracomment>Email of translator - optional.</extracomment>
|
||||||
<translation>martinrotter@users.sourceforge.net</translation>
|
<translation>rotter.martinos@gmail.com</translation>
|
||||||
</message>
|
</message>
|
||||||
</context>
|
</context>
|
||||||
</TS>
|
</TS>
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
#define APP_CFG_PATH "data/config/config.ini"
|
#define APP_CFG_PATH "data/config/config.ini"
|
||||||
#define APP_CFG_GUI "gui"
|
#define APP_CFG_GUI "gui"
|
||||||
#define APP_CFG_GEN "main"
|
#define APP_CFG_GEN "main"
|
||||||
#define APP_CFG_LANG "localization"
|
|
||||||
|
|
||||||
#define APP_DB_PATH "data/storage/database.db"
|
#define APP_DB_PATH "data/storage/database.db"
|
||||||
#define APP_PREFIX "@CMAKE_INSTALL_PREFIX@"
|
#define APP_PREFIX "@CMAKE_INSTALL_PREFIX@"
|
||||||
@ -32,6 +31,7 @@
|
|||||||
#define APP_SKIN_PATH APP_PREFIX + QString("/share/rssguard/skins")
|
#define APP_SKIN_PATH APP_PREFIX + QString("/share/rssguard/skins")
|
||||||
#define APP_INFO_PATH APP_PREFIX + QString("/share/rssguard/information")
|
#define APP_INFO_PATH APP_PREFIX + QString("/share/rssguard/information")
|
||||||
#define APP_THEME_PATH APP_PREFIX + QString("/share/rssguard/themes")
|
#define APP_THEME_PATH APP_PREFIX + QString("/share/rssguard/themes")
|
||||||
|
#define APP_FLAGS_PATH APP_PREFIX + QString("/share/rssguard/flags")
|
||||||
#define APP_ICON_PATH APP_PREFIX + QString("/share/icons/hicolor/128x128/apps/@APP_LOW_NAME@.png")
|
#define APP_ICON_PATH APP_PREFIX + QString("/share/icons/hicolor/128x128/apps/@APP_LOW_NAME@.png")
|
||||||
#define APP_ICON_PLAIN_PATH APP_PREFIX + QString("/share/icons/hicolor/128x128/apps/@APP_LOW_NAME@_plain.png")
|
#define APP_ICON_PLAIN_PATH APP_PREFIX + QString("/share/icons/hicolor/128x128/apps/@APP_LOW_NAME@_plain.png")
|
||||||
#elif defined(Q_OS_WIN)
|
#elif defined(Q_OS_WIN)
|
||||||
@ -39,6 +39,7 @@
|
|||||||
#define APP_SKIN_PATH QApplication::applicationDirPath() + QString("/skins")
|
#define APP_SKIN_PATH QApplication::applicationDirPath() + QString("/skins")
|
||||||
#define APP_INFO_PATH QApplication::applicationDirPath()
|
#define APP_INFO_PATH QApplication::applicationDirPath()
|
||||||
#define APP_THEME_PATH QApplication::applicationDirPath() + QString("/themes")
|
#define APP_THEME_PATH QApplication::applicationDirPath() + QString("/themes")
|
||||||
|
#define APP_FLAGS_PATH QApplication::applicationDirPath() + QString("/flags")
|
||||||
#define APP_ICON_PATH QApplication::applicationDirPath() + QString("/@APP_LOW_NAME@.png")
|
#define APP_ICON_PATH QApplication::applicationDirPath() + QString("/@APP_LOW_NAME@.png")
|
||||||
#define APP_ICON_PLAIN_PATH QApplication::applicationDirPath() + QString("/@APP_LOW_NAME@_plain.png")
|
#define APP_ICON_PLAIN_PATH QApplication::applicationDirPath() + QString("/@APP_LOW_NAME@_plain.png")
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,6 +1,71 @@
|
|||||||
#include "localization.h"
|
#include <QTranslator>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QFileInfoList>
|
||||||
|
|
||||||
|
#include "qtsingleapplication/qtsingleapplication.h"
|
||||||
|
#include "core/localization.h"
|
||||||
|
#include "core/defs.h"
|
||||||
|
#include "core/settings.h"
|
||||||
|
|
||||||
|
|
||||||
Localization::Localization()
|
Localization::Localization() {
|
||||||
{
|
}
|
||||||
|
|
||||||
|
QList<Language> Localization::getInstalledLanguages() {
|
||||||
|
QList<Language> languages;
|
||||||
|
QDir file_dir(APP_LANG_PATH);
|
||||||
|
QFileInfoList file_list = file_dir.entryInfoList(QStringList() << "rssguard_*.qm",
|
||||||
|
QDir::Files,
|
||||||
|
QDir::Name);
|
||||||
|
QTranslator translator;
|
||||||
|
|
||||||
|
foreach (QFileInfo file, file_list) {
|
||||||
|
if (translator.load(file.absoluteFilePath())) {
|
||||||
|
Language new_language;
|
||||||
|
new_language.m_name = translator.translate("QObject", "LANG_NAME");
|
||||||
|
new_language.m_code = translator.translate("QObject", "LANG_ABBREV");
|
||||||
|
new_language.m_version = translator.translate("QObject", "LANG_VERSION");
|
||||||
|
new_language.m_author = translator.translate("QObject", "LANG_AUTHOR");
|
||||||
|
new_language.m_email = translator.translate("QObject", "LANG_EMAIL");
|
||||||
|
|
||||||
|
languages << new_language;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return languages;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Localization::set(const QString &locale_name) {
|
||||||
|
Settings::getInstance()->setValue(APP_CFG_GEN,
|
||||||
|
"language",
|
||||||
|
locale_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Localization::load() {
|
||||||
|
// Obtain all needed data.
|
||||||
|
QString locale_name = Settings::getInstance()->value(APP_CFG_GEN,
|
||||||
|
"language",
|
||||||
|
"en").toString();
|
||||||
|
QTranslator qt_translator, app_translator;
|
||||||
|
|
||||||
|
// Load localizations and setup locales.
|
||||||
|
if (app_translator.load(QString("rssguard_%1.qm").arg(locale_name),
|
||||||
|
APP_LANG_PATH)) {
|
||||||
|
qDebug("Application localization %s loaded successfully. Setting up locale.",
|
||||||
|
qPrintable(locale_name));
|
||||||
|
QLocale::setDefault(QLocale(locale_name));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
qDebug("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. Setting up locale.",
|
||||||
|
qPrintable(locale_name));
|
||||||
|
QLocale::setDefault(QLocale(locale_name));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
qDebug("Qt localization %s was not loaded.", qPrintable(locale_name));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,31 @@
|
|||||||
#ifndef LOCALIZATION_H
|
#ifndef LOCALIZATION_H
|
||||||
#define LOCALIZATION_H
|
#define LOCALIZATION_H
|
||||||
|
|
||||||
|
#include <QPointer>
|
||||||
|
|
||||||
class Localization
|
|
||||||
{
|
struct Language {
|
||||||
|
QString m_name;
|
||||||
|
QString m_code;
|
||||||
|
QString m_version;
|
||||||
|
QString m_author;
|
||||||
|
QString m_email;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Localization {
|
||||||
// TODO: Finish implementation of this class.
|
// TODO: Finish implementation of this class.
|
||||||
private:
|
private:
|
||||||
Localization();
|
Localization();
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Sets up localization strings and locale from application settings.
|
||||||
|
static void load();
|
||||||
|
|
||||||
|
static void set(const QString &locale_name);
|
||||||
|
|
||||||
|
// Returns list of installed application localizations.
|
||||||
|
// This list is used ie. in settings dialog.
|
||||||
|
static QList<Language> getInstalledLanguages();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LOCALIZATION_H
|
#endif // LOCALIZATION_H
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
|
#include <QMessageBox>
|
||||||
|
#include <QProcess>
|
||||||
|
|
||||||
#include "gui/formsettings.h"
|
#include "gui/formsettings.h"
|
||||||
#include "gui/themefactory.h"
|
#include "gui/themefactory.h"
|
||||||
#include "gui/systemtrayicon.h"
|
#include "gui/systemtrayicon.h"
|
||||||
#include "gui/formmain.h"
|
#include "gui/formmain.h"
|
||||||
#include "core/settings.h"
|
#include "core/settings.h"
|
||||||
#include "core/defs.h"
|
#include "core/defs.h"
|
||||||
|
#include "core/localization.h"
|
||||||
#include "core/systemfactory.h"
|
#include "core/systemfactory.h"
|
||||||
|
|
||||||
|
|
||||||
@ -14,12 +18,28 @@ FormSettings::FormSettings(QWidget *parent) : QDialog(parent), m_ui(new Ui::Form
|
|||||||
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog);
|
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog);
|
||||||
setWindowIcon(ThemeFactory::fromTheme("preferences-system"));
|
setWindowIcon(ThemeFactory::fromTheme("preferences-system"));
|
||||||
|
|
||||||
|
// Setup behavior.
|
||||||
|
m_ui->m_treeLanguages->setColumnCount(5);
|
||||||
|
m_ui->m_treeLanguages->setHeaderHidden(false);
|
||||||
|
m_ui->m_treeLanguages->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
|
||||||
|
m_ui->m_treeLanguages->header()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
|
||||||
|
m_ui->m_treeLanguages->header()->setSectionResizeMode(2, QHeaderView::ResizeToContents);
|
||||||
|
m_ui->m_treeLanguages->header()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
|
||||||
|
m_ui->m_treeLanguages->header()->setSectionResizeMode(4, QHeaderView::ResizeToContents);
|
||||||
|
m_ui->m_treeLanguages->setHeaderLabels(QStringList()
|
||||||
|
<< tr("Language")
|
||||||
|
<< tr("Code")
|
||||||
|
<< tr("Version")
|
||||||
|
<< tr("Author")
|
||||||
|
<< tr("Email"));
|
||||||
|
|
||||||
// Establish needed connections.
|
// Establish needed connections.
|
||||||
connect(this, &FormSettings::accepted, this, &FormSettings::saveSettings);
|
connect(this, &FormSettings::accepted, this, &FormSettings::saveSettings);
|
||||||
|
|
||||||
// Load all settings.
|
// Load all settings.
|
||||||
loadGeneral();
|
loadGeneral();
|
||||||
loadInterface();
|
loadInterface();
|
||||||
|
loadLanguage();
|
||||||
}
|
}
|
||||||
|
|
||||||
FormSettings::~FormSettings() {
|
FormSettings::~FormSettings() {
|
||||||
@ -30,9 +50,60 @@ void FormSettings::saveSettings() {
|
|||||||
// Save all settings.
|
// Save all settings.
|
||||||
saveGeneral();
|
saveGeneral();
|
||||||
saveInterface();
|
saveInterface();
|
||||||
|
saveLanguage();
|
||||||
|
}
|
||||||
|
|
||||||
// Make sure that settings is synced.
|
void FormSettings::loadLanguage() {
|
||||||
Settings::getInstance()->checkSettings();
|
QList<Language> languages = Localization::getInstalledLanguages();
|
||||||
|
|
||||||
|
foreach (Language lang, languages) {
|
||||||
|
QTreeWidgetItem *item = new QTreeWidgetItem(m_ui->m_treeLanguages);
|
||||||
|
item->setText(0, lang.m_name);
|
||||||
|
item->setText(1, lang.m_code);
|
||||||
|
item->setText(2, lang.m_version);
|
||||||
|
item->setText(3, lang.m_author);
|
||||||
|
item->setText(4, lang.m_email);
|
||||||
|
item->setIcon(0, QIcon(APP_FLAGS_PATH + "/" + lang.m_code + ".png"));
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<QTreeWidgetItem*> matching_items = m_ui->m_treeLanguages->findItems(Settings::getInstance()->value(APP_CFG_GEN,
|
||||||
|
"language",
|
||||||
|
"en").toString(),
|
||||||
|
Qt::MatchExactly,
|
||||||
|
1);
|
||||||
|
if (!matching_items.isEmpty()) {
|
||||||
|
m_ui->m_treeLanguages->setCurrentItem(matching_items[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FormSettings::saveLanguage() {
|
||||||
|
QString actual_lang = Settings::getInstance()->value(APP_CFG_GEN,
|
||||||
|
"language",
|
||||||
|
"en").toString();
|
||||||
|
QString new_lang = m_ui->m_treeLanguages->currentItem()->text(1);
|
||||||
|
|
||||||
|
if (new_lang != actual_lang) {
|
||||||
|
Settings::getInstance()->setValue(APP_CFG_GEN, "language", new_lang);
|
||||||
|
|
||||||
|
QMessageBox msg_question(this);
|
||||||
|
msg_question.setText(tr("Language of Qonverter was changed. Note that changes will take effect on next Qonverter start."));
|
||||||
|
msg_question.setInformativeText(tr("Do you want to restart now?"));
|
||||||
|
msg_question.setWindowTitle(tr("Language changed"));
|
||||||
|
msg_question.setIcon(QMessageBox::Question);
|
||||||
|
msg_question.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
||||||
|
msg_question.setDefaultButton(QMessageBox::Yes);
|
||||||
|
|
||||||
|
if (msg_question.exec() == QMessageBox::Yes) {
|
||||||
|
if (!QProcess::startDetached(qApp->applicationFilePath())) {
|
||||||
|
QMessageBox::warning(this,
|
||||||
|
tr("Problem with RSS Guard restart"),
|
||||||
|
tr("Qonverter couldn't be restarted, please restart it manually for changes to take effect."));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
qApp->quit();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormSettings::loadGeneral() {
|
void FormSettings::loadGeneral() {
|
||||||
|
@ -28,6 +28,9 @@ class FormSettings : public QDialog {
|
|||||||
void loadGeneral();
|
void loadGeneral();
|
||||||
void saveGeneral();
|
void saveGeneral();
|
||||||
|
|
||||||
|
void loadLanguage();
|
||||||
|
void saveLanguage();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::FormSettings *m_ui;
|
Ui::FormSettings *m_ui;
|
||||||
};
|
};
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QStackedWidget" name="m_stackedSettings">
|
<widget class="QStackedWidget" name="m_stackedSettings">
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>1</number>
|
<number>2</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="m_pageGeneral">
|
<widget class="QWidget" name="m_pageGeneral">
|
||||||
<layout class="QFormLayout" name="formLayout_5">
|
<layout class="QFormLayout" name="formLayout_5">
|
||||||
@ -202,7 +202,44 @@
|
|||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QWidget" name="m_pageLanguage"/>
|
<widget class="QWidget" name="m_pageLanguages">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QTreeWidget" name="m_treeLanguages">
|
||||||
|
<property name="editTriggers">
|
||||||
|
<set>QAbstractItemView::NoEditTriggers</set>
|
||||||
|
</property>
|
||||||
|
<property name="indentation">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="itemsExpandable">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="allColumnsShowFocus">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="expandsOnDoubleClick">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="columnCount">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0" colspan="2">
|
<item row="1" column="0" colspan="2">
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include "core/defs.h"
|
#include "core/defs.h"
|
||||||
#include "core/debugging.h"
|
#include "core/debugging.h"
|
||||||
|
#include "core/localization.h"
|
||||||
#include "core/settings.h"
|
#include "core/settings.h"
|
||||||
#include "gui/themefactory.h"
|
#include "gui/themefactory.h"
|
||||||
#include "gui/formmain.h"
|
#include "gui/formmain.h"
|
||||||
@ -57,6 +58,9 @@ int main(int argc, char *argv[]) {
|
|||||||
// Add an extra path for non-system icon themes.
|
// Add an extra path for non-system icon themes.
|
||||||
ThemeFactory::setupSearchPaths();
|
ThemeFactory::setupSearchPaths();
|
||||||
|
|
||||||
|
// Load localization and setup locale.
|
||||||
|
Localization::load();
|
||||||
|
|
||||||
// These settings needs to be set before any QSettings object.
|
// These settings needs to be set before any QSettings object.
|
||||||
QtSingleApplication::setApplicationName(APP_NAME);
|
QtSingleApplication::setApplicationName(APP_NAME);
|
||||||
QtSingleApplication::setApplicationVersion(APP_VERSION);
|
QtSingleApplication::setApplicationVersion(APP_VERSION);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user