Skip to content

Commit

Permalink
fix: Don't show unicode replacement boxes on unsupported languages.
Browse files Browse the repository at this point in the history
Instead, show the language in English and say "(no fonts)".
  • Loading branch information
iphydf committed Nov 18, 2024
1 parent b699420 commit cd8d48a
Show file tree
Hide file tree
Showing 53 changed files with 283 additions and 18 deletions.
94 changes: 80 additions & 14 deletions src/widget/form/settings/generalform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "ui_generalsettings.h"

#include <QFileDialog>
#include <QFontDatabase>
#include <cmath>

#include "src/core/core.h"
Expand Down Expand Up @@ -75,20 +76,83 @@ QStringList locales = {
"zh_TW"
};
// clang-format on

QFontDatabase::WritingSystem writingSystem(QLocale::Script script)
{
switch (script) {
case QLocale::Script::AnyScript:
return QFontDatabase::WritingSystem::Any;
case QLocale::Script::ArabicScript:
return QFontDatabase::WritingSystem::Arabic;
case QLocale::Script::ArmenianScript:
return QFontDatabase::WritingSystem::Armenian;
case QLocale::Script::BengaliScript:
return QFontDatabase::WritingSystem::Bengali;
case QLocale::Script::CyrillicScript:
return QFontDatabase::WritingSystem::Cyrillic;
case QLocale::Script::DevanagariScript:
return QFontDatabase::WritingSystem::Devanagari;
case QLocale::Script::GeorgianScript:
return QFontDatabase::WritingSystem::Georgian;
case QLocale::Script::GreekScript:
return QFontDatabase::WritingSystem::Greek;
case QLocale::Script::GujaratiScript:
return QFontDatabase::WritingSystem::Gujarati;
case QLocale::Script::GurmukhiScript:
return QFontDatabase::WritingSystem::Gurmukhi;
case QLocale::Script::HebrewScript:
return QFontDatabase::WritingSystem::Hebrew;
case QLocale::Script::JapaneseScript:
return QFontDatabase::WritingSystem::Japanese;
case QLocale::Script::KannadaScript:
return QFontDatabase::WritingSystem::Kannada;
case QLocale::Script::KhmerScript:
return QFontDatabase::WritingSystem::Khmer;
case QLocale::Script::KoreanScript:
return QFontDatabase::WritingSystem::Korean;
case QLocale::Script::LaoScript:
return QFontDatabase::WritingSystem::Lao;
case QLocale::Script::LatinScript:
return QFontDatabase::WritingSystem::Latin;
case QLocale::Script::MalayalamScript:
return QFontDatabase::WritingSystem::Malayalam;
case QLocale::Script::MyanmarScript:
return QFontDatabase::WritingSystem::Myanmar;
case QLocale::Script::OriyaScript:
return QFontDatabase::WritingSystem::Oriya;
case QLocale::Script::SinhalaScript:
return QFontDatabase::WritingSystem::Sinhala;
case QLocale::Script::TamilScript:
return QFontDatabase::WritingSystem::Tamil;
case QLocale::Script::TeluguScript:
return QFontDatabase::WritingSystem::Telugu;
case QLocale::Script::ThaiScript:
return QFontDatabase::WritingSystem::Thai;
case QLocale::Script::TibetanScript:
return QFontDatabase::WritingSystem::Tibetan;
case QLocale::Script::SimplifiedChineseScript:
return QFontDatabase::WritingSystem::SimplifiedChinese;
case QLocale::Script::TraditionalChineseScript:
return QFontDatabase::WritingSystem::TraditionalChinese;

default:
qWarning() << "Unknown script" << script;
return QFontDatabase::WritingSystem::Any;
}
}

} // namespace

/**
* @class GeneralForm
* @class GeneralForm7
*
* This form contains all settings that are not suited to other forms
*/
GeneralForm::GeneralForm(SettingsWidget* myParent, Settings& settings_, Style& style)
GeneralForm::GeneralForm(Settings& settings_, Style& style)
: GenericForm(QPixmap(":/img/settings/general.png"), style)
, bodyUI(new Ui::GeneralSettings)
, bodyUI{new Ui::GeneralSettings}
, settings{settings_}
{
parent = myParent;

bodyUI->setupUi(this);

// block all child signals during initialization
Expand All @@ -107,16 +171,20 @@ GeneralForm::GeneralForm(SettingsWidget* myParent, Settings& settings_, Style& s
for (int i = 0; i < locales.size(); ++i) {
QString langName;

if (locales[i].startsWith(QLatin1String("eo"))) // QTBUG-57802
langName = QLocale::languageToString(QLocale::Esperanto);
else if (locales[i].startsWith(QLatin1String("jbo")))
if (locales[i].startsWith(QLatin1String("jbo")))
langName = QLatin1String("Lojban");
else if (locales[i].startsWith(QLatin1String("pr")))
langName = QLatin1String("Pirate");
else if (locales[i] == (QLatin1String("pt"))) // QTBUG-47891
langName = QStringLiteral("português");
else
langName = QLocale(locales[i]).nativeLanguageName();
else {
const QLocale locale{locales[i]};
if (!QFontDatabase::families(writingSystem(locale.script())).isEmpty())
langName = locale.nativeLanguageName();
else
langName = tr("%1 (no fonts)").arg(QLocale::languageToString(locale.language()));
if (langName.isEmpty()) {
langName = QLocale::languageToString(locale.language());
}
}

bodyUI->transComboBox->insertItem(i, langName);
}
Expand Down Expand Up @@ -146,7 +214,6 @@ GeneralForm::GeneralForm(SettingsWidget* myParent, Settings& settings_, Style& s
/ 1024 / 1024);
bodyUI->autoacceptFiles->setChecked(settings.getAutoSaveEnabled());


#ifndef QTOX_PLATFORM_EXT
bodyUI->autoAwayLabel->setEnabled(false); // these don't seem to change the appearance of the widgets,
bodyUI->autoAwaySpinBox->setEnabled(false); // though they are unusable
Expand All @@ -159,7 +226,6 @@ GeneralForm::GeneralForm(SettingsWidget* myParent, Settings& settings_, Style& s
GeneralForm::~GeneralForm()
{
Translator::unregister(this);
delete bodyUI;
}

void GeneralForm::on_transComboBox_currentIndexChanged(int index)
Expand Down
5 changes: 2 additions & 3 deletions src/widget/form/settings/generalform.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class GeneralForm : public GenericForm
{
Q_OBJECT
public:
GeneralForm(SettingsWidget* parent, Settings& settings, Style& style);
GeneralForm(Settings& settings, Style& style);
~GeneralForm();
QString getFormName() final
{
Expand Down Expand Up @@ -49,7 +49,6 @@ private slots:
void retranslateUi();

private:
Ui::GeneralSettings* bodyUI;
SettingsWidget* parent;
const std::unique_ptr<Ui::GeneralSettings> bodyUI;
Settings& settings;
};
2 changes: 1 addition & 1 deletion src/widget/form/settingswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ SettingsWidget::SettingsWidget(UpdateCheck* updateCheck, IAudioControl& audio, C
settingsWidgets->setTabPosition(QTabWidget::North);
bodyLayout->addWidget(settingsWidgets.get());

std::unique_ptr<GeneralForm> gfrm(new GeneralForm(this, settings, style));
std::unique_ptr<GeneralForm> gfrm(new GeneralForm(settings, style));
connect(gfrm.get(), &GeneralForm::updateIcons, parent, &Widget::updateIcons);

std::unique_ptr<UserInterfaceForm> uifrm(new UserInterfaceForm(smileyPack, settings, style, this));
Expand Down
4 changes: 4 additions & 0 deletions translations/ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,10 @@ so you can save the file on Windows.</source>
<source>General</source>
<translation>عام</translation>
</message>
<message>
<source>%1 (no fonts)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>GeneralSettings</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/be.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,10 @@ so you can save the file on Windows.</source>
<comment>popup title</comment>
<translation>Выбраць каталог для аўтаматычна прынятых файлаў</translation>
</message>
<message>
<source>%1 (no fonts)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>GeneralSettings</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/bg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,10 @@ so you can save the file on Windows.</source>
<comment>popup title</comment>
<translation>Изберете папка за автоматично приемане</translation>
</message>
<message>
<source>%1 (no fonts)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>GeneralSettings</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/bn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,10 @@ so you can save the file on Windows.</source>
<comment>popup title</comment>
<translation type="unfinished"></translation>
</message>
<message>
<source>%1 (no fonts)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>GeneralSettings</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/cs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,10 @@ takže můžete soubor uložit i v systému Windows.</translation>
<source>General</source>
<translation>Obecné</translation>
</message>
<message>
<source>%1 (no fonts)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>GeneralSettings</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/da.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,10 @@ so you can save the file on Windows.</source>
<comment>popup title</comment>
<translation type="unfinished"></translation>
</message>
<message>
<source>%1 (no fonts)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>GeneralSettings</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,10 @@ um sie in Windows speichern zu können.</translation>
<comment>popup title</comment>
<translation>Speicherort für empfangenen Dateien wählen</translation>
</message>
<message>
<source>%1 (no fonts)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>GeneralSettings</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/el.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,10 @@ so you can save the file on Windows.</source>
<source>General</source>
<translation>Γενικά</translation>
</message>
<message>
<source>%1 (no fonts)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>GeneralSettings</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/eo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,10 @@ so you can save the file on Windows.</source>
<source>General</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>%1 (no fonts)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>GeneralSettings</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,10 @@ para que puedas guardar el archivo en windows.</translation>
<comment>popup title</comment>
<translation>Elige un directorio para transferencias automáticas</translation>
</message>
<message>
<source>%1 (no fonts)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>GeneralSettings</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/et.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,10 @@ ja sa saad seda faili nüüd Windowsis salvestada.</translation>
<source>General</source>
<translation>Üldine</translation>
</message>
<message>
<source>%1 (no fonts)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>GeneralSettings</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/fa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,10 @@ so you can save the file on Windows.</source>
<comment>popup title</comment>
<translation>یک پوشه برای دریافت فایلها به شکل خودکار انتخاب کنید</translation>
</message>
<message>
<source>%1 (no fonts)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>GeneralSettings</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/fi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,10 @@ joten voit tallentaa tiedoston Windowsissa.</translation>
<comment>popup title</comment>
<translation>Valitse hakemisto automaattisesti hyväksyttäville tiedostoille</translation>
</message>
<message>
<source>%1 (no fonts)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>GeneralSettings</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,10 @@ afin que vous puissiez enregistrer le fichier sur windows.</translation>
<comment>popup title</comment>
<translation>Sélectionner un répertoire d&apos;acceptation automatique</translation>
</message>
<message>
<source>%1 (no fonts)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>GeneralSettings</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/gl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,10 @@ so you can save the file on Windows.</source>
<comment>popup title</comment>
<translation>Elixa un cartafol para aceptados automáticamente</translation>
</message>
<message>
<source>%1 (no fonts)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>GeneralSettings</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/he.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,10 @@ so you can save the file on Windows.</source>
<comment>popup title</comment>
<translation type="unfinished"></translation>
</message>
<message>
<source>%1 (no fonts)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>GeneralSettings</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/hr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,10 @@ so you can save the file on Windows.</source>
<comment>popup title</comment>
<translation>Odaberi direktorij za automatsko prihvaćanje</translation>
</message>
<message>
<source>%1 (no fonts)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>GeneralSettings</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/hu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,10 @@ so you can save the file on Windows.</source>
<comment>popup title</comment>
<translation>Válasszon egy mappát az automatikus elfogadáshoz</translation>
</message>
<message>
<source>%1 (no fonts)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>GeneralSettings</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/is.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,10 @@ so you can save the file on Windows.</source>
<comment>popup title</comment>
<translation type="unfinished"></translation>
</message>
<message>
<source>%1 (no fonts)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>GeneralSettings</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,10 @@ in modo da poter salvare il file su Windows.</translation>
<comment>popup title</comment>
<translation>Scegli dove salvare i file accettati automaticamente</translation>
</message>
<message>
<source>%1 (no fonts)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>GeneralSettings</name>
Expand Down
4 changes: 4 additions & 0 deletions translations/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,10 @@ so you can save the file on Windows.</source>
<source>General</source>
<translation>一般</translation>
</message>
<message>
<source>%1 (no fonts)</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>GeneralSettings</name>
Expand Down
Loading

0 comments on commit cd8d48a

Please sign in to comment.