Skip to content

EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust

i18n: Settings page titles read the menu bar's Settings rows

Davit Matchakhelidzead8db289cfed
diff --git a/crates/ui-egui/src/i18n.rs b/crates/ui-egui/src/i18n.rs
index 702c6ffd1..dde67e225 100644
--- a/crates/ui-egui/src/i18n.rs
+++ b/crates/ui-egui/src/i18n.rs
@@ -173,6 +173,14 @@ pub(crate) fn command_label<'a>(command: &str, source: &'a str) -> &'a str {
row(source).or_else(|| row(dotted.as_deref()?)).unwrap_or_else(|| tr(source))
}
+/// A Settings page's title as the menu bar's Settings submenu draws it, without the ellipsis; the
+/// panel catalog's row for pages that have no menu row. The panel catalog's "Type" is the kind
+/// (Camera Settings, the Project panel's column), while the Type page is about text.
+pub(crate) fn settings_page_title(title: &str) -> &str {
+ let menu = menu_catalog(ui::current()).and_then(|c| c.iter().find(|(id, en, _)| *id == "app.settings" && en.strip_suffix("...") == Some(title)));
+ menu.and_then(|(_, _, translated)| translated.strip_suffix("...")).unwrap_or_else(|| tr(title))
+}
+
/// `source` looked up in `catalog` by (command, English label); the source itself when the pair is
/// absent, so computed labels and user names stay verbatim.
fn lookup<'a>(catalog: &[(&str, &str, &'a str)], command: &str, source: &'a str) -> &'a str {
@@ -6691,6 +6699,16 @@ mod tests {
assert_eq!(command_label("window.panel", "Project"), "Project");
}
+ #[test]
+ fn settings_page_titles_read_the_menu_row() {
+ set_current("zh-hans");
+ assert_eq!(settings_page_title("Type"), "文字");
+ assert_eq!(tr("Type"), "类型");
+ assert_eq!(settings_page_title("Roto Brush"), tr("Roto Brush"));
+ set_current("en");
+ assert_eq!(settings_page_title("Type"), "Type");
+ }
+
#[test]
fn match_system_takes_the_first_browser_language_with_a_catalog() {
let tags = |t: &[&str]| t.iter().map(|s| s.to_string()).collect::<Vec<_>>();
diff --git a/crates/ui-egui/src/panels/settings.rs b/crates/ui-egui/src/panels/settings.rs
index 28a7c0142..6954e1377 100644
--- a/crates/ui-egui/src/panels/settings.rs
+++ b/crates/ui-egui/src/panels/settings.rs
@@ -677,7 +677,7 @@ pub fn show(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
ui.painter().text(
r.left_center() + vec2(10.0, 0.0),
egui::Align2::LEFT_CENTER,
- tr(p.title),
+ crate::i18n::settings_page_title(p.title),
Tokens::ui(12.5),
if sel { Color32::WHITE } else { t.text },
);
@@ -694,7 +694,7 @@ pub fn show(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
// dialog scrolled sideways a little (#284).
ui.set_width(ui.available_width());
let p = &all[idx];
- ui.label(RichText::new(tr(p.title)).font(Tokens::semibold(14.0)).color(t.tab_text_active));
+ ui.label(RichText::new(crate::i18n::settings_page_title(p.title)).font(Tokens::semibold(14.0)).color(t.tab_text_active));
ui.add_space(6.0);
egui::ScrollArea::vertical().max_height((body_h - 30.0).max(0.0)).auto_shrink([false, false]).show(ui, |ui| {
page_ui(app, ui, p, &cur, t, &mut acts);