mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-01 18:54:31 +01:00
Command palette: a translated plug-in is still found by its manifest name
A filter or live-effect plug-in whose name the UI language translates shows the translation in the palette, and a search for the manifest's own name finds it too. Export Text's test compares its rows with the names the dialog shows, which for a plug-in with an English translation differ from the manifest text that messages use.
This commit is contained in:
1 parent
ece34c6ba7
commit
8e093c9e14
2 files changed
+64
-7
No files matched your search
@@ -109,6 +109,10 @@ struct Draft {
|
||||
/// Is this a plug-in command, whose label and plug-in name come from the plug-in's own
|
||||
/// translations?
|
||||
plugin_command: bool,
|
||||
/// For a filter or live-effect plug-in item whose path and label give the plug-in's name in the
|
||||
/// UI language from its translations: the path and label with the manifest's own text, which a
|
||||
/// query also matches ([`Draft::plain`]).
|
||||
own: Option<(String, String)>,
|
||||
id: String,
|
||||
shortcut: String,
|
||||
/// Has [`distinct_names`] given the result its [`context`]?
|
||||
@@ -124,6 +128,7 @@ impl Draft {
|
||||
label: label.to_string(),
|
||||
translates: true,
|
||||
plugin_command: false,
|
||||
own: None,
|
||||
id,
|
||||
shortcut: shortcut.to_string(),
|
||||
in_context: false,
|
||||
@@ -157,6 +162,16 @@ impl Draft {
|
||||
let name = if self.path.is_empty() { label.to_string() } else { format!("{} › {label}", shown_label(lang, &self.path)) };
|
||||
if self.keyed { format!("{name} ({})", self.id) } else { name }
|
||||
}
|
||||
|
||||
/// The English name a query matches before [`distinct_names`] runs: a plug-in item that shows
|
||||
/// a translated name by the manifest's own text ([`Draft::own`]).
|
||||
fn plain(&self) -> String {
|
||||
match &self.own {
|
||||
Some((path, label)) if path.is_empty() => label.clone(),
|
||||
Some((path, label)) => format!("{path} › {label}"),
|
||||
None => self.name(crate::i18n::Lang::EN),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The palette's results before their names are made distinct: every listed engine command and
|
||||
@@ -203,9 +218,12 @@ fn drafts() -> Vec<Draft> {
|
||||
}
|
||||
// An Effect menu item runs what its item runs; a live-effect plug-in's name does not translate.
|
||||
for e in crate::shortcut_editor::effect_items().iter() {
|
||||
let plugin = vectorcraft_plugins::effect::plugin_id(&e.effect).is_some();
|
||||
let id = format!("effect:{}", e.effect);
|
||||
out.push(Draft {
|
||||
translates: vectorcraft_plugins::effect::plugin_id(&e.effect).is_none(),
|
||||
..Draft::new(&e.group, &e.label, format!("effect:{}", e.effect), crate::shortcut_editor::effect_shortcut(&e.effect).unwrap_or(""))
|
||||
translates: !plugin,
|
||||
own: if plugin { crate::shortcut_editor::own_plugin_text_of(&id) } else { None },
|
||||
..Draft::new(&e.group, &e.label, id, crate::shortcut_editor::effect_shortcut(&e.effect).unwrap_or(""))
|
||||
});
|
||||
}
|
||||
out
|
||||
@@ -429,11 +447,15 @@ fn build(lang: crate::i18n::Lang) -> Vec<Entry> {
|
||||
fn build_in(lang: crate::i18n::Lang, native: bool) -> Vec<Entry> {
|
||||
let homes = search::menu_homes(native);
|
||||
let mut drafts = drafts();
|
||||
drafts.extend(crate::shortcut_editor::filter_items().iter().map(|f| Draft {
|
||||
translates: false,
|
||||
..Draft::new(&f.group, &f.label, format!("plugin:{}", f.id), crate::shortcut_editor::filter_shortcut(&f.id).unwrap_or(""))
|
||||
drafts.extend(crate::shortcut_editor::filter_items().iter().map(|f| {
|
||||
let id = format!("plugin:{}", f.id);
|
||||
Draft {
|
||||
translates: false,
|
||||
own: crate::shortcut_editor::own_plugin_text_of(&id),
|
||||
..Draft::new(&f.group, &f.label, id, crate::shortcut_editor::filter_shortcut(&f.id).unwrap_or(""))
|
||||
}
|
||||
}));
|
||||
let plain: Vec<String> = drafts.iter().map(|d| d.name(crate::i18n::Lang::EN)).collect();
|
||||
let plain: Vec<String> = drafts.iter().map(Draft::plain).collect();
|
||||
distinct_names(&mut drafts, &[crate::i18n::Lang::EN, lang]);
|
||||
drafts
|
||||
.into_iter()
|
||||
@@ -3306,6 +3328,31 @@ mod tests {
|
||||
assert_eq!(fr, format!("{object} › {plugins} › Tidy › Grow"));
|
||||
}
|
||||
|
||||
/// 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.
|
||||
#[test]
|
||||
fn a_translated_filter_is_found_by_its_manifest_name() {
|
||||
use vectorcraft_plugins::wat as tpl;
|
||||
let id = "test.UI.palette_translated_filter";
|
||||
let manifest = format!(
|
||||
r#"{{"id":"{id}","name":"Polish Edges","version":"1","kind":"filter","translations":{{"de":{{"name":"Kanten polieren"}},"en":{{"name":"Smooth Edges"}}}}}}"#
|
||||
);
|
||||
vectorcraft_plugins::registry::install_bytes(&wat::parse_str(tpl::returning(&manifest, r#"{"objects":[]}"#)).unwrap()).unwrap();
|
||||
let found = |lang: Lang| {
|
||||
crate::i18n::set_current(lang);
|
||||
let found = build(lang).into_iter().find(|e| e.id == format!("plugin:{id}")).map(|e| (e.shown, e.haystack));
|
||||
crate::i18n::set_current(Lang::EN);
|
||||
found
|
||||
};
|
||||
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")] {
|
||||
let (shown, haystack) = found.expect("the filter is a result");
|
||||
assert!(shown.ends_with(name), "{shown}");
|
||||
assert!(haystack.contains("polish edges"), "{haystack}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A plug-in's name in the path of its own item, in the submenu a plug-in with commands gets,
|
||||
/// stays as the plug-in gives it where it matches text the app translates ("Open" in German).
|
||||
#[test]
|
||||
|
||||
@@ -1151,6 +1151,16 @@ pub fn entry(key: &str) -> Option<Entry> {
|
||||
entries().iter().find(|e| e.key == key).cloned()
|
||||
}
|
||||
|
||||
/// The group and label of plug-in item `key` (`plugin:<id>` or `effect:<id>`) with the manifest's
|
||||
/// own text, when the item shows the plug-in's name in the UI language from its translations
|
||||
/// ([`Entry::english`]); `None` for every other entry.
|
||||
pub(crate) fn own_plugin_text_of(key: &str) -> Option<(String, String)> {
|
||||
if !key.starts_with("plugin:") && !key.starts_with("effect:") {
|
||||
return None;
|
||||
}
|
||||
entries().iter().find(|e| e.key == key).and_then(|e| e.english.clone())
|
||||
}
|
||||
|
||||
/// Entries (other than `except`) whose effective shortcut equals `chord`.
|
||||
pub fn conflicts_with(overrides: &Overrides, chord: &str, except: &str) -> Vec<String> {
|
||||
let Some(c) = vc_chord(chord) else { return vec![] };
|
||||
@@ -2788,7 +2798,7 @@ mod tests {
|
||||
let text = export_text("VectorCraft Defaults", &ov);
|
||||
let km = keymap_with(&ov);
|
||||
let names = |tools: bool| -> Vec<String> {
|
||||
entries().iter().filter(|e| e.is_tool == tools && listed(km.overrides(), e)).map(|e| format!("{}\t", english_name(e))).collect()
|
||||
entries().iter().filter(|e| e.is_tool == tools && listed(km.overrides(), e)).map(|e| format!("{}\t", shown_name(e))).collect()
|
||||
};
|
||||
let rows = (names(true), names(false));
|
||||
(text, km, rows.0, rows.1)
|
||||
|
||||
Reference in new issue
Block a user