Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LanguageView: Respect "main country" for locale selection #835

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Helpers/LocaleHelper.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, LangEntry?> lang_entries;
Expand Down
25 changes: 20 additions & 5 deletions src/Views/LanguageView.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
});
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
}
}