Plug-ins: the effect editor and palette search use translated names

A plug-in effect's editor in the Appearance panel is named by the
plug-in's name in the UI language, as its row is. The command palette
also finds a filter or live-effect plug-in by its English translation
when the UI shows another language.
This commit is contained in:
dotCooCoo committed 2026-11-25 16:50:18 -08:00
1 parent 643639db21
commit 08ff70c863
5 files changed
+85 -9

No files matched your search

+32
View File
@@ -94,6 +94,38 @@ pub(crate) fn effect_item_label(e: &vectorcraft_effects::EffectInfo) -> &'static
}
}
/// The menu label of plug-in item `key` (`plugin:<filter id>` or `effect:<effect id>`) in language
/// `code`, as [`object_menu`] and [`effect_menu`] show it in that language; `None` for any other key
/// or a plug-in that is not installed.
pub(crate) fn item_label_in(key: &str, code: &str) -> Option<&'static str> {
let m = item_plugin(key)?;
let m = m.manifest();
Some(label(&m.shown_name(code), !m.params.is_empty()))
}
/// Menu path `group` of plug-in item `key` ([`item_label_in`]) with its plug-in's submenu, the
/// segment after Object › Plug-ins or Effect › Plug-ins, named in language `code`; `group` as it
/// is for an item without a submenu.
pub(crate) fn item_group_in(key: &str, group: &str, code: &str) -> String {
let mut parts: Vec<String> = group.split(" › ").map(str::to_string).collect();
if parts.get(1).is_some_and(|p| p == "Plug-ins")
&& let (Some(plugin), Some(submenu)) = (item_plugin(key), parts.get_mut(2))
{
*submenu = plugin.manifest().shown_name(code);
}
parts.join(" › ")
}
/// The plug-in of item `key` (`plugin:<filter id>` or `effect:<effect id>`), if it is installed.
fn item_plugin(key: &str) -> Option<Arc<Plugin>> {
let id = match (key.strip_prefix("plugin:"), key.strip_prefix("effect:")) {
(Some(id), _) => id,
(_, Some(effect)) => vectorcraft_plugins::effect::plugin_id(effect)?,
_ => return None,
};
registry::get(id)
}
/// A menu label for plug-in `name`: with an ellipsis when it opens a dialog.
fn label(name: &str, has_params: bool) -> &'static str {
let dots = if has_params && !name.ends_with('…') { "…" } else { "" };
+16 -8
View File
@@ -159,13 +159,18 @@ impl Draft {
let name = format!("{path} › {label}");
return if self.keyed { format!("{name} ({})", self.id) } else { name };
}
// A built-in effect's label translates by its effect id first, as the Effect menu's does.
// A built-in effect's label translates by its effect id first, as the Effect menu's does. A
// filter or live-effect plug-in's name and submenu are the ones its translations give in `lang`.
let label = match self.id.strip_prefix("effect:") {
_ if !self.translates => self.label.as_str(),
_ if !self.translates => crate::dialogs::plugin::item_label_in(&self.id, lang.code()).unwrap_or(self.label.as_str()),
Some(effect) => crate::i18n::tr_id(lang, effect, &self.label),
None => crate::i18n::tr(lang, &self.label),
};
let name = if self.path.is_empty() { label.to_string() } else { format!("{} › {label}", shown_label(lang, &self.path)) };
let path = match self.translates {
true => std::borrow::Cow::Borrowed(self.path.as_str()),
false => std::borrow::Cow::Owned(crate::dialogs::plugin::item_group_in(&self.id, &self.path, lang.code())),
};
let name = if path.is_empty() { label.to_string() } else { format!("{} › {label}", shown_label(lang, &path)) };
if self.keyed { format!("{name} ({})", self.id) } else { name }
}
@@ -1968,7 +1973,8 @@ mod tests {
}
/// A filter whose name the UI language translates shows the translation, English included, and
/// a search for the manifest's own name still finds it.
/// a search for the manifest's own name still finds it; in German, so does a search for its
/// English translation.
#[test]
fn a_translated_filter_is_found_by_its_manifest_name() {
use vectorcraft_plugins::wat as tpl;
@@ -1979,19 +1985,21 @@ mod tests {
);
vectorcraft_plugins::registry::install_bytes(&wat::parse_str(tpl::returning(&manifest, r#"{"objects":[]}"#)).unwrap()).unwrap();
let app = app_on(Session::new());
let key = format!("plugin:{id}");
let found = |lang: Lang| {
crate::i18n::set_current(lang);
let found =
entries(&app, lang).iter().find(|e| id_of(e) == format!("plugin:{id}")).map(|e| (e.label().as_str().to_string(), haystack(e)));
let found = entries(&app, lang).iter().find(|e| id_of(e) == key).map(|e| (e.label().as_str().to_string(), haystack(e)));
let by_english = ranked(&built_for(&app), "smooth edges").contains(&key);
crate::i18n::set_current(Lang::EN);
found
(found, by_english)
};
let (de, en) = (found(Lang::from_code("de").unwrap()), found(Lang::EN));
vectorcraft_plugins::registry::remove(id);
for (found, name) in [(de, "Kanten polieren"), (en, "Smooth Edges")] {
for ((found, by_english), name) in [(de, "Kanten polieren"), (en, "Smooth Edges")] {
let (shown, haystack) = found.expect("the filter is a result");
assert!(shown.ends_with(name), "{shown}");
assert!(haystack.contains("polish edges"), "{haystack}");
assert!(by_english, "a search for the English translation finds {name}");
}
}
+3 -1
View File
@@ -949,7 +949,9 @@ fn effect_editor<'r>(app: &VectorcraftApp, pass: &'r RefCell<Pass>, item: Option
if rows.is_empty() { stored_params(&effect, &values) } else { rows }
};
let fields = fields_of(&params, &values);
let (name, id) = (effect_label(&e.id), e.id.clone());
// A plug-in effect's editor is named as its row is, by the plug-in's name in the UI language.
let name = crate::dialogs::plugin::effect_name(&e.id).unwrap_or_else(|| effect_label(&e.id));
let id = e.id.clone();
move |ui| {
if free_distort {
// The button keeps its own name: the label says what it edits.
@@ -214,6 +214,34 @@ fn a_plug_in_effect_s_editor_follows_its_manifest() {
panel.app().run("plugin.remove", json!({"id": "test.ui.inlinekeys"})).unwrap();
}
/// A plug-in effect's editor is named by the plug-in's name in the UI language, as its row is.
#[test]
fn a_plug_in_effect_s_editor_is_named_in_the_ui_language() {
use vectorcraft_plugins::wat as tpl;
let id = "test.ui.inlinename";
let manifest = format!(
r#"{{"id":"{id}","name":"Hatch","version":"1","kind":"effect","params":{{"width":{{"type":"number","min":0,"max":10,"default":1,"label":"Width"}}}},
"translations":{{"de":{{"name":"Schraffur"}}}}}}"#
);
let src = tpl::module(&manifest, tpl::ECHO, "", 1);
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
app.run("plugin.install", json!({"dataBase64": vectorcraft_format::base64_encode(&wat::parse_str(src).unwrap())})).unwrap();
app.run("file.new", json!({"width": 100, "height": 100})).unwrap();
app.run("shape.rectangle", json!({"x": 0, "y": 0, "width": 20, "height": 20})).unwrap();
app.run("effect.apply", json!({"effect": format!("plugin.{id}")})).unwrap();
app.ui.appearance_panel.open.insert(RowKey::Effect(0));
let mut panel = Panel::new(app, show);
let group = craft::ui::contract::Role::GROUP;
let en = panel.shows_role("Hatch", group);
crate::i18n::set_current(crate::i18n::Lang::from_code("de").unwrap());
panel.frame();
let de = (panel.shows_role("Schraffur", group), panel.shows_role("Hatch", group));
crate::i18n::set_current(crate::i18n::Lang::EN);
panel.app().run("plugin.remove", json!({"id": id})).unwrap();
assert!(en, "the editor in English");
assert_eq!(de, (true, false), "the editor in German");
}
/// Glass with a loaded texture lists Loaded Texture in its Texture menu, as its dialog does.
#[test]
fn the_effect_editor_lists_a_loaded_glass_texture() {
@@ -276,6 +276,12 @@ impl Panel {
self.fixture.by_label(name).is_some()
}
/// Whether the latest frame shows a node of `role` named `name`, where nodes of other roles share the name.
pub(crate) fn shows_role(&self, name: &str, role: craft::ui::contract::Role) -> bool {
let tree = self.fixture.tree();
self.fixture.by_role(role).into_iter().any(|t| tree.name_of(t.node) == Some(name))
}
/// Whether some of the control named `name` can be seen in the latest frame.
pub(crate) fn in_view(&self, name: &str) -> bool {
self.fixture.visible(&self.look(name)).is_some()