diff --git a/.lupdate/translations/en_US.ts.stamp b/.lupdate/translations/en_US.ts.stamp new file mode 100644 index 0000000..e69de29 diff --git a/.lupdate/translations/ru_RU.ts.stamp b/.lupdate/translations/ru_RU.ts.stamp new file mode 100644 index 0000000..e69de29 diff --git a/main.cpp b/main.cpp index edd4e1f..e0498fa 100644 --- a/main.cpp +++ b/main.cpp @@ -48,16 +48,12 @@ int main(int argc, char *argv[]) { QString lang = "en_US"; if (s.get_all_settings().contains("language")) { - std::cout << "settings" << std::endl; lang = QString::fromStdString(s.get_all_settings()["language"]); } else if (translator.load(":/translation/"+QLocale::system().name()+".qm")) { - std::cout << "system" << std::endl; lang = QLocale::system().name(); } else { - std::cout << "default" << std::endl; lang = QString::fromStdString("en_US"); } - std::cout << lang.toStdString() << std::endl; translator.load(":/translation/" + lang + ".qm"); a.installTranslator(&translator); diff --git a/settings/settings.cpp b/settings/settings.cpp index bdfa92b..d4f2513 100644 --- a/settings/settings.cpp +++ b/settings/settings.cpp @@ -26,7 +26,6 @@ Settings::Settings(std::string path) { "stores_modules_url":"https://foxarmy.org/checks-parser/modules/stores/", "print_header": true, "print_total": true, - "language":"en_US", "output_order": { "goods_name": { "position":1, diff --git a/settingsdialog.cpp b/settingsdialog.cpp index 4c06072..f74a101 100644 --- a/settingsdialog.cpp +++ b/settingsdialog.cpp @@ -35,8 +35,18 @@ SettingsDialog::SettingsDialog(QWidget *parent) ui->printHeaderCheckBox->setChecked(this->settings.get_all_settings()["print_header"]); ui->printTotalCheckBox->setChecked(this->settings.get_all_settings()["print_total"]); - int index = ui->languageComboBox->findText(QString::fromStdString(this->settings.get_all_settings()["language"])); - ui->languageComboBox->setCurrentIndex(index); + + int currentLanguageIndex = 0; + if (!this->settings.get_all_settings().contains("language")) { + currentLanguageIndex = ui->languageComboBox->findText(QLocale::system().name()); + if (currentLanguageIndex < 0) { + currentLanguageIndex = ui->languageComboBox->findText("en_US"); + } + } else { + currentLanguageIndex = ui->languageComboBox->findText(QString::fromStdString(this->settings.get_all_settings()["language"])); + } + ui->languageComboBox->setCurrentIndex(currentLanguageIndex); + } SettingsDialog::~SettingsDialog() { delete ui; } @@ -127,7 +137,12 @@ void SettingsDialog::on_buttonBox_accepted() { this->settings.flush(); } void SettingsDialog::on_buttonBox_rejected() { this->close(); } void SettingsDialog::on_languageComboBox_currentTextChanged(const QString &changed) { - if (changed == QString::fromStdString(this->settings.get_all_settings()["language"])) return; + if (this->settings.get_all_settings().contains("language")) { + if (changed == QString::fromStdString(this->settings.get_all_settings()["language"])) return; + } else { + if (changed == QLocale::system().name()) return; + } + this->settings.get_all_settings()["language"] = changed.toStdString(); QMessageBox infoDialog; diff --git a/translations/en_US.ts b/translations/en_US.ts index a6f47fb..5e1a6b4 100644 --- a/translations/en_US.ts +++ b/translations/en_US.ts @@ -311,12 +311,12 @@ SettingsDialog - + You need to restart program to apply language changes You need to restart program to apply language changes - + Restart required Restart required diff --git a/translations/ru_RU.ts b/translations/ru_RU.ts index 6b93b4b..1896d6f 100644 --- a/translations/ru_RU.ts +++ b/translations/ru_RU.ts @@ -307,12 +307,12 @@ SettingsDialog - + You need to restart program to apply language changes Требуется перезагрузить программу, чтобы применить изменения языка - + Restart required Требуется перезагрузка