Skip to content

Commit 2f61cba

Browse files
committed
GUI - Minor tweaks relating to the UI language option
* Add Basque and generic English to the list of language names * Add a message in the language options panel when the translations fail to load * Set fallback language code to en_GB instead of en (so it's clear which English translation is being used) * Tweak some log messages from SonicPii18n
1 parent 9372da9 commit 2f61cba

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

app/gui/qt/utils/sonicpi_i18n.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ QString SonicPii18n::determineUILanguage(QString lang_pref) {
4646
QStringList preferred_languages = locale.uiLanguages();
4747
// If the setting is set to system_language...
4848
// ...run through the list of preferred languages
49-
std::cout << "Looping through preferred ui languages" << std::endl;
49+
std::cout << "[GUI] [i18n] - Looping through preferred ui languages" << std::endl;
5050

5151
QString l;
5252
for (int i = 0; i < preferred_languages.length(); i += 1) {
@@ -68,7 +68,7 @@ QString SonicPii18n::determineUILanguage(QString lang_pref) {
6868
QStringList SonicPii18n::findSystemLanguages() {
6969
QLocale locale;
7070
QStringList preferred_languages = locale.uiLanguages();
71-
std::cout << "Looping through preferred ui languages" << std::endl;
71+
std::cout << "[GUI] [i18n] - Looping through preferred ui languages" << std::endl;
7272
for (int i = 0; i < preferred_languages.length(); i += 1) {
7373
preferred_languages[i] = preferred_languages[i].replace("-", "_");
7474
}
@@ -108,12 +108,12 @@ bool SonicPii18n::loadTranslations(QString lang) {
108108
app->removeTranslator(&translator);
109109
app->removeTranslator(&qtTranslator);
110110

111-
std::cout << "Loading translations for " << language.toUtf8().constData() << std::endl;
111+
std::cout << "[GUI] [i18n] - Loading translations for " << language.toUtf8().constData() << std::endl;
112112

113113
i18n = translator.load("sonic-pi_" + language, ":/lang/") || language == "en_GB" || language == "en" || language == "C";
114114
if (!i18n) {
115-
std::cout << "Error: Failed to load language translation for " << language.toUtf8().constData() << std::endl;
116-
language = "en";
115+
std::cout << "[GUI] [i18n] - Error: Failed to load language translation for " << language.toUtf8().constData() << std::endl;
116+
language = "en_GB";
117117
}
118118
app->installTranslator(&translator);
119119

@@ -153,14 +153,14 @@ QString SonicPii18n::getNativeLanguageName(QString lang) {
153153
// language found
154154
return native_language_names[lang];
155155
} else {
156-
std::cout << "Warning: Predefined language name not found: '" << lang.toUtf8().constData() << "'" << std::endl;
156+
std::cout << "[GUI] [i18n] - Warning: Predefined language name not found: '" << lang.toUtf8().constData() << "'" << std::endl;
157157
// Try using QLocale to find the native language name
158158
QLocale locale(lang);
159159
QString name = locale.nativeLanguageName();
160160
if (name != "C" && name != "") {
161161
return locale.nativeLanguageName();
162162
} else {
163-
std::cout << "Warning: Invalid language code: '" << lang.toUtf8().constData() << "'" << std::endl;
163+
std::cout << "[GUI] [i18n] - Warning: Invalid language code: '" << lang.toUtf8().constData() << "'" << std::endl;
164164
return lang;
165165
}
166166
}

app/gui/qt/widgets/settingswidget.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -600,9 +600,8 @@ void SettingsWidget::updateUILanguage(int index) {
600600
emit uiLanguageChanged(piSettings->language);
601601

602602
language_details_label->setText(
603-
tr("<b>The new language will be applied when you next start Sonic Pi.</b>")
604-
+ " "
605-
+ tr("Current UI language: %1").arg(sonicPii18n->getNativeLanguageName(sonicPii18n->currentlyLoadedLanguage()))
603+
tr("<b>The new language will be applied when you next start Sonic Pi.</b><br>")
604+
+ tr("Current UI language: %1\n").arg(sonicPii18n->getNativeLanguageName(sonicPii18n->currentlyLoadedLanguage()))
606605
);
607606

608607
QMessageBox restartMsgBox(this);
@@ -807,11 +806,17 @@ void SettingsWidget::updateSettings() {
807806

808807
void SettingsWidget::settingsChanged() {
809808
language_combo->setCurrentIndex(available_languages.indexOf(piSettings->language));
809+
QString language_detail_text = "";
810+
if (!i18n) {
811+
language_detail_text += "<b>Failed to load language translation. Using English (UK).</b>";
812+
}
810813
if (piSettings->language == "system_language") {
811-
language_details_label->setText(
812-
tr("System languages: %1").arg(sonicPii18n->getNativeLanguageNames(sonicPii18n->getSystemLanguages()).join(", ")) + "\n" + tr("Current UI language: %1").arg(sonicPii18n->getNativeLanguageName(sonicPii18n->currentlyLoadedLanguage()))
814+
language_detail_text += (
815+
tr("System languages: %1\n").arg(sonicPii18n->getNativeLanguageNames(sonicPii18n->getSystemLanguages()).join(", "))
816+
+ tr("Current UI language: %1\n").arg(sonicPii18n->getNativeLanguageName(sonicPii18n->currentlyLoadedLanguage()))
813817
);
814818
}
819+
language_details_label->setText(language_detail_text);
815820

816821
mixer_invert_stereo->setChecked(piSettings->mixer_invert_stereo);
817822
mixer_force_mono->setChecked(piSettings->mixer_force_mono);

app/server/ruby/bin/qt-doc.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@
4141
"da" => "Dansk", # Danish
4242
"de" => "Deutsch", # German
4343
"el" => "ελληνικά", # Greek
44+
"en" => "English", # English
4445
"en_AU" => "English (Australian)", # English (Australian)
4546
"en_GB" => "English (UK)", # English (UK) - default language
4647
"en_US" => "English (US)", # English (US)
4748
"eo" => "Esperanto", # Esperanto
4849
"es" => "Español", # Spanish
4950
"et" => "Eesti keel", # Estonian
51+
"eu" => "Euskara", # Basque
5052
"fa" => "فارسی", # Persian
5153
"fi" => "Suomi", # Finnish
5254
"fr" => "Français", # French

0 commit comments

Comments
 (0)