fixed a locale display bug

master
Qiaoyong Zhong 11 years ago
parent 194054e6fd
commit 557d2597ec

@ -31,7 +31,7 @@ HEADERS += \
TRANSLATIONS = ts/2048-qt_zh_CN.ts TRANSLATIONS = ts/2048-qt_zh_CN.ts
VERSION = 0.1.1 VERSION = 0.1.2
VERSTR = '\\"$${VERSION}\\"' VERSTR = '\\"$${VERSION}\\"'
DEFINES += VER=\"$${VERSTR}\" DEFINES += VER=\"$${VERSTR}\"

@ -13,7 +13,13 @@ int main(int argc, char *argv[])
settings.setVersion(QString(VER)); settings.setVersion(QString(VER));
// Localization // 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; QString tsFile = "2048-qt_" + locale;
QTranslator translator; QTranslator translator;

@ -93,9 +93,9 @@ ApplicationWindow {
text: qsTr("English") text: qsTr("English")
checkable: true checkable: true
exclusiveGroup: languageSettingsGroup exclusiveGroup: languageSettingsGroup
checked: settings.value("language", "en_US") === "en_US" ? true : false checked: settings.value("language") === "en_US" ? true : false
onTriggered: { onTriggered: {
if (settings.value("language", "en_US") !== "en_US") { if (settings.value("language") !== "en_US") {
settings.setValue("language", "en_US"); settings.setValue("language", "en_US");
changeLanguageDialog.open(); changeLanguageDialog.open();
} }
@ -105,9 +105,9 @@ ApplicationWindow {
text: qsTr("Simplified Chinese") text: qsTr("Simplified Chinese")
checkable: true checkable: true
exclusiveGroup: languageSettingsGroup exclusiveGroup: languageSettingsGroup
checked: settings.value("language", "en_US") === "zh_CN" ? true : false checked: settings.value("language") === "zh_CN" ? true : false
onTriggered: { onTriggered: {
if (settings.value("language", "en_US") !== "zh_CN") { if (settings.value("language") !== "zh_CN") {
settings.setValue("language", "zh_CN"); settings.setValue("language", "zh_CN");
changeLanguageDialog.open(); changeLanguageDialog.open();
} }

@ -8,6 +8,10 @@ Settings::~Settings() {
delete settings_; delete settings_;
} }
bool Settings::contains(const QString & key) const {
return settings_->contains(key);
}
void Settings::setValue(const QString &key, const QVariant &value) { void Settings::setValue(const QString &key, const QVariant &value) {
settings_->setValue(key, value); settings_->setValue(key, value);
} }

@ -16,6 +16,7 @@ public:
Q_INVOKABLE QString getVersion(); Q_INVOKABLE QString getVersion();
void setVersion(const QString version); void setVersion(const QString version);
bool contains(const QString & key) const;
signals: signals:

Loading…
Cancel
Save