From b7c4fdd312ab3a1f1677a2eeddc927af37b2fcc3 Mon Sep 17 00:00:00 2001 From: Ryo Nakano Date: Sat, 12 Oct 2024 15:50:17 +0900 Subject: [PATCH] LanguageView: Respect "main country" for locale selection --- src/Helpers/LocaleHelper.vala | 4 ++++ src/Views/LanguageView.vala | 25 ++++++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/Helpers/LocaleHelper.vala b/src/Helpers/LocaleHelper.vala index 13b538de2..0a383007f 100644 --- a/src/Helpers/LocaleHelper.vala +++ b/src/Helpers/LocaleHelper.vala @@ -42,6 +42,10 @@ namespace LocaleHelper { public string alpha_2; public string alpha_3; public string name; + + public unowned string get_code () { + return alpha_2 ?? alpha_3; + } } private static Gee.HashMap lang_entries; diff --git a/src/Views/LanguageView.vala b/src/Views/LanguageView.vala index c25bfea0b..970ff968f 100644 --- a/src/Views/LanguageView.vala +++ b/src/Views/LanguageView.vala @@ -65,6 +65,8 @@ public class Installer.LanguageView : AbstractInstallerView { lang_variant_widget = new VariantWidget (); + lang_variant_widget.variant_listbox.set_sort_func ((Gtk.ListBoxSortFunc) CountryRow.compare); + lang_variant_widget.variant_listbox.row_activated.connect (() => { next_button.activate (); }); @@ -130,8 +132,8 @@ public class Installer.LanguageView : AbstractInstallerView { unowned Gtk.ListBoxRow crow = lang_variant_widget.variant_listbox.get_selected_row (); if (crow != null) { - string country = ((CountryRow) crow).country_entry.alpha_2; - configuration.country = country; + LocaleHelper.CountryEntry country = ((CountryRow) crow).country_entry; + configuration.country = country.get_code (); } else if (lang_entry.countries.length == 0) { configuration.country = null; } else { @@ -241,16 +243,25 @@ public class Installer.LanguageView : AbstractInstallerView { return; } + var lang_code = lang_entry.get_code (); + string? main_country = LocaleHelper.get_main_country (lang_code); + lang_variant_widget.variant_listbox.row_selected.disconnect (variant_row_selected); lang_variant_widget.clear_variants (); lang_variant_widget.variant_listbox.row_selected.connect (variant_row_selected); foreach (var country in countries) { - lang_variant_widget.variant_listbox.append (new CountryRow (country)); + var country_row = new CountryRow (country); + lang_variant_widget.variant_listbox.append (country_row); + if (country.get_code () == main_country) { + lang_variant_widget.variant_listbox.select_row (country_row); + } } - lang_variant_widget.variant_listbox.select_row (lang_variant_widget.variant_listbox.get_row_at_index (0)); + if (main_country == null || lang_variant_widget.variant_listbox.get_selected_row () == null) { + lang_variant_widget.variant_listbox.select_row (lang_variant_widget.variant_listbox.get_row_at_index (0)); + } - Environment.set_variable ("LANGUAGE", lang_entry.get_code (), true); + Environment.set_variable ("LANGUAGE", lang_code, true); Intl.textdomain (Build.GETTEXT_PACKAGE); lang_variant_widget.show_variants (_("Languages"), lang_entry.name); } @@ -369,5 +380,9 @@ public class Installer.LanguageView : AbstractInstallerView { child = box; } + + public static int compare (CountryRow countryrow1, CountryRow countryrow2) { + return countryrow1.country_entry.name.collate (countryrow2.country_entry.name); + } } }