From bf1b09698c7f6ee3cf0e227db5337d9e825e33ad Mon Sep 17 00:00:00 2001 From: semmelrinde <124386289+semmelrinde@users.noreply.github.com> Date: Wed, 28 Oct 2026 12:15:15 +0000 Subject: [PATCH] Insert Part: the part families and the Name hint in the user's language (#8018) * Insert Part: name the part families in the user's language The Type list of Insert Part and the Change Part Size dialog showed the library's English family names (Socket head cap screw, Hex nut, ...) in every language. Each family now has a message under its library id, and a family the catalogs don't know keeps the library's name. Co-Authored-By: Claude Opus 5.5 * Insert Part: the Name field's automatic hint in the user's language The hint was the English word "automatic"; it now takes the catalogs' parts.automatic_name, which every language already translates. Co-Authored-By: Claude Opus 5.5 * Move the family-name helper and its test away from where #8005 adds its own Co-Authored-By: Claude Opus 5.5 --------- Co-authored-by: Claude Opus 5.5 --- .../locales/pending/parts-family-names.json | 110 ++++++++++++++++++ crates/ui-egui/src/dialogs_part_size.rs | 2 +- crates/ui-egui/src/dialogs_parts.rs | 28 ++++- 3 files changed, 137 insertions(+), 3 deletions(-) create mode 100644 assets/locales/pending/parts-family-names.json diff --git a/assets/locales/pending/parts-family-names.json b/assets/locales/pending/parts-family-names.json new file mode 100644 index 000000000..d57ce938a --- /dev/null +++ b/assets/locales/pending/parts-family-names.json @@ -0,0 +1,110 @@ +{ + "en": { + "parts.family.bearing": "Deep groove ball bearing (envelope)", + "parts.family.dowel_pin": "Parallel pin (dowel)", + "parts.family.hex_bolt": "Hex head bolt / screw", + "parts.family.hex_nut": "Hex nut", + "parts.family.set_screw": "Hex socket set screw, flat point", + "parts.family.socket_head_cap_screw": "Socket head cap screw", + "parts.family.washer": "Plain washer" + }, + "ar": { + "parts.family.bearing": "محمل كريات أخدودي عميق (الغلاف)", + "parts.family.dowel_pin": "مسمار توجيه أسطواني", + "parts.family.hex_bolt": "برغي سداسي الرأس", + "parts.family.hex_nut": "صامولة سداسية", + "parts.family.set_screw": "برغي تثبيت بتجويف سداسي، طرف مسطح", + "parts.family.socket_head_cap_screw": "برغي برأس أسطواني بتجويف سداسي", + "parts.family.washer": "حلقة مسطحة" + }, + "de": { + "parts.family.bearing": "Rillenkugellager (Hüllform)", + "parts.family.dowel_pin": "Zylinderstift", + "parts.family.hex_bolt": "Sechskantschraube", + "parts.family.hex_nut": "Sechskantmutter", + "parts.family.set_screw": "Gewindestift mit Innensechskant und Kegelstumpf", + "parts.family.socket_head_cap_screw": "Zylinderschraube mit Innensechskant", + "parts.family.washer": "Unterlegscheibe" + }, + "es": { + "parts.family.bearing": "Rodamiento rígido de bolas (envolvente)", + "parts.family.dowel_pin": "Pasador cilíndrico", + "parts.family.hex_bolt": "Tornillo de cabeza hexagonal", + "parts.family.hex_nut": "Tuerca hexagonal", + "parts.family.set_screw": "Prisionero con hexágono interior, punta plana", + "parts.family.socket_head_cap_screw": "Tornillo cilíndrico con hexágono interior", + "parts.family.washer": "Arandela plana" + }, + "fr": { + "parts.family.bearing": "Roulement à billes à gorge profonde (enveloppe)", + "parts.family.dowel_pin": "Goupille cylindrique", + "parts.family.hex_bolt": "Vis à tête hexagonale", + "parts.family.hex_nut": "Écrou hexagonal", + "parts.family.set_screw": "Vis sans tête à six pans creux, bout plat", + "parts.family.socket_head_cap_screw": "Vis à tête cylindrique à six pans creux", + "parts.family.washer": "Rondelle plate" + }, + "he": { + "parts.family.bearing": "מסב כדורי חריץ עמוק (מעטפת)", + "parts.family.dowel_pin": "פין גלילי", + "parts.family.hex_bolt": "בורג ראש משושה", + "parts.family.hex_nut": "אום משושה", + "parts.family.set_screw": "בורג אלן ללא ראש, קצה שטוח", + "parts.family.socket_head_cap_screw": "בורג ראש גלילי עם משושה פנימי", + "parts.family.washer": "דסקית שטוחה" + }, + "it": { + "parts.family.bearing": "Cuscinetto radiale a sfere (ingombro)", + "parts.family.dowel_pin": "Spina cilindrica", + "parts.family.hex_bolt": "Vite a testa esagonale", + "parts.family.hex_nut": "Dado esagonale", + "parts.family.set_screw": "Grano a esagono incassato, punta piana", + "parts.family.socket_head_cap_screw": "Vite a testa cilindrica con esagono incassato", + "parts.family.washer": "Rondella piana" + }, + "ja": { + "parts.family.bearing": "深溝玉軸受(外形)", + "parts.family.dowel_pin": "平行ピン", + "parts.family.hex_bolt": "六角ボルト", + "parts.family.hex_nut": "六角ナット", + "parts.family.set_screw": "六角穴付き止めねじ 平先", + "parts.family.socket_head_cap_screw": "六角穴付きボルト", + "parts.family.washer": "平座金" + }, + "ko": { + "parts.family.bearing": "깊은 홈 볼 베어링 (외형)", + "parts.family.dowel_pin": "평행 핀", + "parts.family.hex_bolt": "육각 볼트", + "parts.family.hex_nut": "육각 너트", + "parts.family.set_screw": "육각 구멍붙이 멈춤나사, 평형 끝", + "parts.family.socket_head_cap_screw": "육각 구멍붙이 볼트", + "parts.family.washer": "평와셔" + }, + "vi": { + "parts.family.bearing": "Ổ bi cầu rãnh sâu (bao ngoài)", + "parts.family.dowel_pin": "Chốt trụ", + "parts.family.hex_bolt": "Bu lông đầu lục giác", + "parts.family.hex_nut": "Đai ốc lục giác", + "parts.family.set_screw": "Vít trí lục giác chìm, đầu bằng", + "parts.family.socket_head_cap_screw": "Bu lông lục giác chìm đầu trụ", + "parts.family.washer": "Vòng đệm phẳng" + }, + "zh": { + "parts.family.bearing": "深沟球轴承(外形)", + "parts.family.dowel_pin": "圆柱销", + "parts.family.hex_bolt": "六角头螺栓", + "parts.family.hex_nut": "六角螺母", + "parts.family.set_screw": "内六角平端紧定螺钉", + "parts.family.socket_head_cap_screw": "内六角圆柱头螺钉", + "parts.family.washer": "平垫圈" + }, + "zh-TW": { + "parts.family.bearing": "深溝滾珠軸承(外形)", + "parts.family.dowel_pin": "圓柱銷", + "parts.family.hex_bolt": "六角頭螺栓", + "parts.family.hex_nut": "六角螺帽", + "parts.family.set_screw": "內六角平端止付螺絲", + "parts.family.socket_head_cap_screw": "內六角圓柱頭螺絲", + "parts.family.washer": "平墊圈" + } +} diff --git a/crates/ui-egui/src/dialogs_part_size.rs b/crates/ui-egui/src/dialogs_part_size.rs index 4f252d66c..bad1eb8d7 100644 --- a/crates/ui-egui/src/dialogs_part_size.rs +++ b/crates/ui-egui/src/dialogs_part_size.rs @@ -170,7 +170,7 @@ pub fn open(app: &mut SolveApp, component: u64) { pub fn rows(app: &SolveApp, ui: &mut egui::Ui, k: &mut Resize) -> bool { row(ui, "Type", |ui| { - ui.add(egui::Label::new(format!("{} ({})", k.family.name, k.family.standard)).wrap()); + ui.add(egui::Label::new(format!("{} ({})", crate::dialogs_parts::family_name(&k.family), k.family.standard)).wrap()); }); let sizes: Vec<&str> = k.family.sizes.iter().map(|s| s.0.as_str()).collect(); choice_row(ui, "Size", "part_resize_size", &mut k.size, &sizes); diff --git a/crates/ui-egui/src/dialogs_parts.rs b/crates/ui-egui/src/dialogs_parts.rs index cd4720f4d..cec10bce2 100644 --- a/crates/ui-egui/src/dialogs_parts.rs +++ b/crates/ui-egui/src/dialogs_parts.rs @@ -50,6 +50,16 @@ pub fn families(v: &Value) -> Vec { .collect() } +/// A family's name in the user's language, by its id in the library: the library's own (English) +/// name for a family the catalogs don't know. +pub(crate) fn family_name(f: &Family) -> String { + let id = format!("parts.family.{}", f.id); + match crate::i18n::tr(&id) { + shown if shown == id => f.name.clone(), + shown => shown.to_string(), + } +} + #[derive(Clone, Debug)] pub struct Pt { pub family: usize, @@ -129,7 +139,7 @@ pub fn rows(app: &mut SolveApp, ui: &mut egui::Ui, k: &mut Pt, inputs: &[SelInpu return false; } let names: Vec = - lib.iter().map(|f| if f.standard.is_empty() { f.name.clone() } else { format!("{} ({})", f.name, f.standard) }).collect(); + lib.iter().map(|f| if f.standard.is_empty() { family_name(f) } else { format!("{} ({})", family_name(f), f.standard) }).collect(); let refs: Vec<&str> = names.iter().map(String::as_str).collect(); let before = k.family; choice_row(ui, "Type", "pt_family", &mut k.family, &refs); @@ -150,7 +160,7 @@ pub fn rows(app: &mut SolveApp, ui: &mut egui::Ui, k: &mut Pt, inputs: &[SelInpu k.length = i.checked_sub(1); }); } - text_row(ui, "Name", &mut k.name, "automatic"); + text_row(ui, "Name", &mut k.name, crate::i18n::tr("parts.automatic_name")); // The part, and its table values. let key = (k.family, k.size, k.length); let tex_id = egui::Id::new("sc_part_picture"); @@ -234,6 +244,20 @@ mod tests { assert!(l[1].lengths.is_none()); } + /// The library's families are named in the user's language, and a family the catalogs + /// don't know keeps the library's name. + #[test] + fn family_names_follow_the_language() { + let l = families(&solidcraft_engine::Session::default().execute("parts.library", &json!({})).unwrap()); + assert!(l.len() >= 7, "{}", l.len()); + let _german = crate::i18n::scope("de"); + for f in &l { + assert_ne!(family_name(f), f.name, "{}", f.id); + } + let unknown = Family { id: "spring".into(), name: "Spring".into(), standard: String::new(), sizes: vec![], lengths: None }; + assert_eq!(family_name(&unknown), "Spring"); + } + /// A hole pick seats the part (`at`); without one it goes to the origin along Z. #[test] fn insert_params_for_picks() {