1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Do not show languages without translations in UI

This commit is contained in:
Ivan Savenko 2023-03-12 23:33:38 +02:00
parent 1ff317058e
commit 66df19352f
5 changed files with 26 additions and 15 deletions

View File

@ -59,7 +59,7 @@ void FirstLaunchView::changeEvent(QEvent * event)
if(event->type() == QEvent::LanguageChange)
{
ui->retranslateUi(this);
Languages::fillLanguages(ui->listWidgetLanguage);
Languages::fillLanguages(ui->listWidgetLanguage, false);
}
QWidget::changeEvent(event);
}
@ -102,9 +102,7 @@ void FirstLaunchView::on_comboBoxLanguage_currentIndexChanged(int index)
void FirstLaunchView::enterSetup()
{
// TODO: block all UI except FirstLaunchView
Languages::fillLanguages(ui->listWidgetLanguage);
Languages::fillLanguages(ui->comboBoxLanguage);
Languages::fillLanguages(ui->listWidgetLanguage, false);
}
void FirstLaunchView::setSetupProgress(int progress)
@ -253,6 +251,8 @@ QString FirstLaunchView::heroesLanguageDetect()
void FirstLaunchView::heroesLanguageUpdate()
{
Languages::fillLanguages(ui->comboBoxLanguage, true);
QString language = heroesLanguageDetect();
bool success = !language.isEmpty();
@ -266,6 +266,7 @@ void FirstLaunchView::heroesLanguageUpdate()
ui->comboBoxLanguage->insertItem(0, itemName, QString("auto"));
ui->comboBoxLanguage->setCurrentIndex(0);
}
ui->labelDataFailure->setVisible(!success);
ui->labelDataSuccess->setVisible(success);
ui->pushButtonDataNext->setEnabled(success);

View File

@ -17,7 +17,7 @@
#include <QListWidget>
// list of language names, for generation of translations. Do not use directly, use Languages namespace instead
static const std::array<std::string, 11> languageTranslatedNamesGenerator = {
static const std::array<std::string, 12> languageTranslatedNamesGenerator = {
{
QT_TRANSLATE_NOOP("Language", "Chinese"),
QT_TRANSLATE_NOOP("Language", "English"),
@ -26,6 +26,7 @@ static const std::array<std::string, 11> languageTranslatedNamesGenerator = {
QT_TRANSLATE_NOOP("Language", "Korean"),
QT_TRANSLATE_NOOP("Language", "Polish"),
QT_TRANSLATE_NOOP("Language", "Russian"),
QT_TRANSLATE_NOOP("Language", "Spanish"),
QT_TRANSLATE_NOOP("Language", "Ukrainian"),
QT_TRANSLATE_NOOP("Language", "Other (East European)"),
QT_TRANSLATE_NOOP("Language", "Other (Cyrillic Script)"),
@ -53,7 +54,7 @@ QString Languages::generateLanguageName(const Languages::Options & language)
return displayName;
}
void Languages::fillLanguages(QComboBox * widget)
void Languages::fillLanguages(QComboBox * widget, bool includeAll)
{
widget->blockSignals(true); // we do not want calls caused by initialization
widget->clear();
@ -62,6 +63,9 @@ void Languages::fillLanguages(QComboBox * widget)
for(const auto & language : Languages::getLanguageList())
{
if (!language.hasTranslation && !includeAll)
continue;
QString displayName = generateLanguageName(language);
QVariant userData = QString::fromStdString(language.identifier);
@ -73,7 +77,7 @@ void Languages::fillLanguages(QComboBox * widget)
widget->blockSignals(false);
}
void Languages::fillLanguages(QListWidget * widget)
void Languages::fillLanguages(QListWidget * widget, bool includeAll)
{
widget->blockSignals(true); // we do not want calls caused by initialization
widget->clear();
@ -82,6 +86,9 @@ void Languages::fillLanguages(QListWidget * widget)
for(const auto & language : Languages::getLanguageList())
{
if (!language.hasTranslation && !includeAll)
continue;
QString displayName = generateLanguageName(language);
QVariant userData = QString::fromStdString(language.identifier);

View File

@ -19,7 +19,8 @@ namespace Languages
QString generateLanguageName(const Languages::Options & identifier);
void fillLanguages(QComboBox * widget);
void fillLanguages(QListWidget * widget);
/// if includeAll is set, all languages including encoding placeholders will be included into widget
void fillLanguages(QComboBox * widget, bool includeAll);
void fillLanguages(QListWidget * widget, bool includeAll);
}

View File

@ -97,7 +97,7 @@ void CSettingsView::loadSettings()
ui->comboBoxAutoSave->setCurrentIndex(settings["general"]["saveFrequency"].Integer() > 0 ? 1 : 0);
Languages::fillLanguages(ui->comboBoxLanguage);
Languages::fillLanguages(ui->comboBoxLanguage, false);
std::string cursorType = settings["video"]["cursor"].String();
size_t cursorTypeIndex = boost::range::find(cursorTypesList, cursorType) - cursorTypesList;
@ -312,7 +312,7 @@ void CSettingsView::changeEvent(QEvent *event)
if(event->type() == QEvent::LanguageChange)
{
ui->retranslateUi(this);
Languages::fillLanguages(ui->comboBoxLanguage);
Languages::fillLanguages(ui->comboBoxLanguage, false);
}
QWidget::changeEvent(event);
}

View File

@ -18,9 +18,10 @@ enum class ELanguages
ENGLISH,
FRENCH,
GERMAN,
KOREAN,
KOREAN, // currently has no translations or detection
POLISH,
RUSSIAN,
SPANISH,
UKRAINIAN,
// Pseudo-languages, that have no translations but can define H3 encoding to use
@ -54,15 +55,16 @@ struct Options
inline const auto & getLanguageList()
{
static const std::array<Options, 11> languages
static const std::array<Options, 12> languages
{ {
{ "chinese", "Chinese", "简体中文", "GBK", true, true },
{ "chinese", "Chinese", "简体中文", "GBK", true, true }, // Note: actually Simplified Chinese
{ "english", "English", "English", "CP1252", true, true },
{ "french", "French", "Français", "CP1252", true, true },
{ "german", "German", "Deutsch", "CP1252", true, true },
{ "korean", "Korean", "한국어", "CP949", false, true },
{ "korean", "Korean", "한국어", "CP949", false, false },
{ "polish", "Polish", "Polski", "CP1250", true, true },
{ "russian", "Russian", "Русский", "CP1251", true, true },
{ "spanish", "Spanish", "Español", "CP1252", false, true },
{ "ukrainian", "Ukrainian", "Українська", "CP1251", true, true },
{ "other_cp1250", "Other (East European)", "", "CP1251", false, false },