feat(egui): add radio buttons to choose language

This commit is contained in:
Mikolaj Wielgus 2024-10-14 02:50:05 +02:00
parent 90afd70f2a
commit 4b66e585c5
4 changed files with 26 additions and 2 deletions

View File

@ -53,6 +53,9 @@ tr-menu-inspect = Inspect
tr-menu-inspect-compare-detours = Compare Detours
tr-menu-inspect-measure-length = Measure Length
tr-menu-properties = Properties
tr-menu-properties-set-language = Set Language
tr-dialog-error-messages = Error Messages
tr-dialog-error-messages-reset = Reset Messages
tr-dialog-error-messages-discard = Discard

View File

@ -129,7 +129,7 @@ impl eframe::App for App {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
self.menu_bar.update(
ctx,
&self.translator,
&mut self.translator,
self.content_channel.0.clone(),
&mut self.viewport,
self.maybe_workspace.as_mut(),

View File

@ -56,7 +56,7 @@ impl MenuBar {
pub fn update(
&mut self,
ctx: &egui::Context,
tr: &Translator,
tr: &mut Translator,
content_sender: Sender<Result<SpecctraDesign, SpecctraLoadingError>>,
viewport: &mut Viewport,
maybe_workspace: Option<&mut Workspace>,
@ -165,6 +165,19 @@ 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()));
}
});
});
ui.menu_button(tr.text("tr-menu-help"), |ui| {
actions.help.online_documentation.hyperlink(
ctx,

View File

@ -22,4 +22,12 @@ impl Translator {
pub fn text(&self, fluent_id: &str) -> String {
LOCALES.lookup(&self.langid, fluent_id)
}
pub fn langid_mut(&mut self) -> &mut LanguageIdentifier {
&mut self.langid
}
pub fn locales() -> Box<dyn Iterator<Item = &'static LanguageIdentifier> + 'static> {
LOCALES.locales()
}
}