From 557d2597ec18fbf9776854995f7f0aa6534d4026 Mon Sep 17 00:00:00 2001 From: Qiaoyong Zhong Date: Sat, 26 Apr 2014 18:57:49 +0800 Subject: [PATCH] fixed a locale display bug --- 2048-qt.pro | 2 +- main.cpp | 8 +++++++- qml/main.qml | 8 ++++---- settings.cpp | 4 ++++ settings.h | 1 + 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/2048-qt.pro b/2048-qt.pro index 49bee4d..6717543 100644 --- a/2048-qt.pro +++ b/2048-qt.pro @@ -31,7 +31,7 @@ HEADERS += \ TRANSLATIONS = ts/2048-qt_zh_CN.ts -VERSION = 0.1.1 +VERSION = 0.1.2 VERSTR = '\\"$${VERSION}\\"' DEFINES += VER=\"$${VERSTR}\" diff --git a/main.cpp b/main.cpp index 985bf46..ba58fe2 100644 --- a/main.cpp +++ b/main.cpp @@ -13,7 +13,13 @@ int main(int argc, char *argv[]) settings.setVersion(QString(VER)); // Localization - QString locale = settings.value("language", QLocale::system().name()).toString(); + QString locale; + if (settings.contains("language")) { + locale = settings.value("language").toString(); + } else { + locale = QLocale::system().name(); + settings.setValue("language", locale); + } QString tsFile = "2048-qt_" + locale; QTranslator translator; diff --git a/qml/main.qml b/qml/main.qml index 03c97b8..b258090 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -93,9 +93,9 @@ ApplicationWindow { text: qsTr("English") checkable: true exclusiveGroup: languageSettingsGroup - checked: settings.value("language", "en_US") === "en_US" ? true : false + checked: settings.value("language") === "en_US" ? true : false onTriggered: { - if (settings.value("language", "en_US") !== "en_US") { + if (settings.value("language") !== "en_US") { settings.setValue("language", "en_US"); changeLanguageDialog.open(); } @@ -105,9 +105,9 @@ ApplicationWindow { text: qsTr("Simplified Chinese") checkable: true exclusiveGroup: languageSettingsGroup - checked: settings.value("language", "en_US") === "zh_CN" ? true : false + checked: settings.value("language") === "zh_CN" ? true : false onTriggered: { - if (settings.value("language", "en_US") !== "zh_CN") { + if (settings.value("language") !== "zh_CN") { settings.setValue("language", "zh_CN"); changeLanguageDialog.open(); } diff --git a/settings.cpp b/settings.cpp index 5f4ba7b..9d556aa 100644 --- a/settings.cpp +++ b/settings.cpp @@ -8,6 +8,10 @@ Settings::~Settings() { delete settings_; } +bool Settings::contains(const QString & key) const { + return settings_->contains(key); +} + void Settings::setValue(const QString &key, const QVariant &value) { settings_->setValue(key, value); } diff --git a/settings.h b/settings.h index 57c5d2f..7a8ef02 100644 --- a/settings.h +++ b/settings.h @@ -16,6 +16,7 @@ public: Q_INVOKABLE QString getVersion(); void setVersion(const QString version); + bool contains(const QString & key) const; signals: