fix(egui): show language display names instead of codes

This commit is contained in:
Mikolaj Wielgus 2024-10-14 04:26:12 +02:00
parent 4b66e585c5
commit 941a271339
2 changed files with 29 additions and 8 deletions

View File

@ -25,9 +25,10 @@ egui = [
"dep:env_logger",
"dep:fluent-templates",
"dep:futures-lite",
"dep:icu",
"dep:rfd",
"dep:sys-locale",
"dep:unic-langid"
"dep:unic-langid",
]
disable_contracts = ["contracts-try/disable_contracts"]
@ -74,6 +75,11 @@ features = ["macros", "serde"]
optional = true
version = "0.11"
[dependencies.icu]
optional = true
version = "1.5.0"
features = ["experimental"]
[dependencies.eframe]
optional = true
version = "0.29"

View File

@ -1,4 +1,8 @@
use std::{ops::ControlFlow, path::Path, sync::mpsc::Sender};
use icu::{
experimental::displaynames::LocaleDisplayNamesFormatter,
locid::{locale, LanguageIdentifier, Locale},
};
use std::{borrow::Cow, ops::ControlFlow, path::Path, sync::mpsc::Sender};
use topola::{
autorouter::{
@ -168,12 +172,23 @@ impl MenuBar {
ui.menu_button(tr.text("tr-menu-properties"), |ui| {
ui.menu_button(tr.text("tr-menu-properties-set-language"), |ui| {
for langid in Translator::locales() {
ui.radio_value(
tr.langid_mut(),
langid.clone(),
langid.language.as_str(),
);
//ui.add(egui::RadioButton::new(true, locale.language.as_str()));
if let Ok(locale) =
Locale::try_from_bytes(langid.to_string().as_bytes())
{
if let Ok(formatter) = LocaleDisplayNamesFormatter::try_new(
&locale.clone().into(),
Default::default(),
) {
ui.radio_value(
tr.langid_mut(),
langid.clone(),
formatter.of(&locale),
);
continue;
}
}
ui.radio_value(tr.langid_mut(), langid.clone(), langid.to_string());
}
});
});