diff --git a/assets/locales/pending/dialog-selection-labels.json b/assets/locales/pending/dialog-selection-labels.json new file mode 100644 index 0000000000..b91596eccd --- /dev/null +++ b/assets/locales/pending/dialog-selection-labels.json @@ -0,0 +1,50 @@ +{ + "ar": { + "dialog.selection_constraint": "قيد {id}", + "dialog.selection_external_curve": "{sketch} · منحنى {id}", + "dialog.selection_midpoint": "نقطة المنتصف · {id}", + "dialog.selection_profile": "{sketch} · المقطع {number}" + }, + "de": { + "dialog.selection_constraint": "Bedingung {id}", + "dialog.selection_external_curve": "{sketch} · Kurve {id}", + "dialog.selection_midpoint": "Mittelpunkt · {id}", + "dialog.selection_profile": "{sketch} · Profil {number}" + }, + "en": { + "dialog.selection_constraint": "Constraint {id}", + "dialog.selection_external_curve": "{sketch} · curve {id}", + "dialog.selection_midpoint": "Midpoint · {id}", + "dialog.selection_profile": "{sketch} · profile {number}" + }, + "he": { + "dialog.selection_constraint": "אילוץ {id}", + "dialog.selection_external_curve": "{sketch} · עקומה {id}", + "dialog.selection_midpoint": "נקודת אמצע · {id}", + "dialog.selection_profile": "{sketch} · פרופיל {number}" + }, + "ja": { + "dialog.selection_constraint": "拘束 {id}", + "dialog.selection_external_curve": "{sketch} · 曲線 {id}", + "dialog.selection_midpoint": "中点 · {id}", + "dialog.selection_profile": "{sketch} · プロファイル {number}" + }, + "ko": { + "dialog.selection_constraint": "구속 조건 {id}", + "dialog.selection_external_curve": "{sketch} · 곡선 {id}", + "dialog.selection_midpoint": "중점 · {id}", + "dialog.selection_profile": "{sketch} · 프로파일 {number}" + }, + "vi": { + "dialog.selection_constraint": "Ràng buộc {id}", + "dialog.selection_external_curve": "{sketch} · đường cong {id}", + "dialog.selection_midpoint": "Trung điểm · {id}", + "dialog.selection_profile": "{sketch} · biên dạng {number}" + }, + "zh": { + "dialog.selection_constraint": "约束 {id}", + "dialog.selection_external_curve": "{sketch} · 曲线 {id}", + "dialog.selection_midpoint": "中点 · {id}", + "dialog.selection_profile": "{sketch} · 轮廓 {number}" + } +} diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index c935ad23cd..d85c08138b 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -2635,9 +2635,19 @@ fn occurrence_paths(s: &Session, items: &[Sel]) -> Vec> { /// the name the preferences give it. pub(crate) fn selection_label(s: &Session, names: crate::prefs::OriginPlaneNames, d: &Dialog, inp: &SelInput, item: &Sel) -> String { let axis = inp.accept == selection::AXIS_PICKS && round_axis(s, item).is_some(); + let sketch_name = + |id| s.doc.feature(id).map(|f| f.name.clone()).unwrap_or_else(|| crate::i18n::format("browser.sketch_name", &[("number", &id.to_string())])); match item { Sel::SketchCurve { id, .. } => id.clone(), Sel::SketchPoint { id } => crate::sketch_modify_ui::point_id(s, item).unwrap_or(id).to_string(), + Sel::SketchMidpoint { id } => crate::i18n::format("dialog.selection_midpoint", &[("id", id)]), + Sel::ExternalSketchCurve { sketch, id } => { + crate::i18n::format("dialog.selection_external_curve", &[("sketch", &sketch_name(*sketch)), ("id", id)]) + } + Sel::SketchConstraint { id } => crate::i18n::format("dialog.selection_constraint", &[("id", id)]), + Sel::Profile { sketch, index } => { + crate::i18n::format("dialog.selection_profile", &[("sketch", &sketch_name(*sketch)), ("number", &index.saturating_add(1).to_string())]) + } Sel::Plane { name } => names.label(name).to_string(), Sel::Axis { name } | Sel::ConstructionPoint { name } | Sel::Body { name } => name.clone(), Sel::Face { body, index, .. } if axis => format!("{body} · face {index} axis"), diff --git a/crates/ui-egui/src/dialogs_all_tests.rs b/crates/ui-egui/src/dialogs_all_tests.rs index 5a59b364e3..6e0d5d746c 100644 --- a/crates/ui-egui/src/dialogs_all_tests.rs +++ b/crates/ui-egui/src/dialogs_all_tests.rs @@ -1344,3 +1344,56 @@ fn stored_bare_numbers_edit_with_their_units() { assert_eq!(h.app.session.doc.features.len(), count, "{command}: the feature is redefined in place"); } } + +#[test] +fn dialog_profile_labels_name_the_sketch_in_coil_and_mirror() { + for command in ["solid.coil", "sketch.mirror"] { + let mut h = Harness::new(); + h.app.run("sketch.create", json!({"plane": "XY", "name": "Panel"})).unwrap(); + h.app.run("sketch.rectangle.two_point", json!({"p0": [0, 0], "p1": [40, 30]})).unwrap(); + let sketch = h.app.session.active_sketch.unwrap(); + if command == "solid.coil" { + h.app.run("sketch.finish", json!({})).unwrap(); + } + h.call("ui.view", json!({"view": "top"})); + h.call("ui.camera", json!({"target": [20, 15, 0], "distance": 100})); + h.step(&json!({"click": {"world": [20, 15, 0]}})).unwrap(); + assert_eq!(h.app.session.selection, vec![Sel::Profile { sketch, index: 0 }]); + h.app.start(command); + h.app.dialog.as_mut().unwrap().preview_enabled = false; + h.frames(3); + let d = h.app.dialog.as_ref().unwrap(); + let input = &d.inputs[0]; + assert_eq!(input.items, vec![Sel::Profile { sketch, index: 0 }]); + assert_eq!(selection_label(&h.app.session, h.app.preferences.origin_plane_names, d, input, &input.items[0]), "Panel · profile 1"); + let mut painted = false; + for clipped in &h.shapes { + crate::test_support::each_shape(&clipped.shape, &mut |shape| { + if let egui::Shape::Text(text) = shape { + painted |= text.galley.text() == "Panel · profile 1"; + } + }); + } + assert!(painted, "{command}: the painted selection label"); + } +} + +#[test] +fn dialog_sketch_selection_labels_translate_and_keep_identifiers() { + let mut h = Harness::new(); + let sketch = h.app.run("sketch.create", json!({"plane": "XY", "name": "Panel"})).unwrap()["sketch"].as_u64().unwrap(); + let d = Dialog::for_command(&h.app, "sketch.mirror").unwrap(); + for (sel, english, german) in [ + (Sel::Profile { sketch, index: 1 }, "Panel · profile 2", "Panel · Profil 2"), + (Sel::SketchMidpoint { id: "l7".into() }, "Midpoint · l7", "Mittelpunkt · l7"), + (Sel::ExternalSketchCurve { sketch, id: "l7".into() }, "Panel · curve l7", "Panel · Kurve l7"), + (Sel::SketchConstraint { id: "k3".into() }, "Constraint k3", "Bedingung k3"), + ] { + for (language, expected) in [("en", english), ("de", german)] { + let _language = crate::i18n::scope(language); + assert_eq!(selection_label(&h.app.session, h.app.preferences.origin_plane_names, &d, &d.inputs[0], &sel), expected); + } + } + let missing = Sel::Profile { sketch: 999, index: 0 }; + assert_eq!(selection_label(&h.app.session, h.app.preferences.origin_plane_names, &d, &d.inputs[0], &missing), "Sketch999 · profile 1"); +}