From 9382667ca5b239c5398e824798f3daefce3eea5e Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Thu, 24 Sep 2026 12:06:25 +0200 Subject: [PATCH] fix(dashboard): the demo targets dialog in German The "Add demo targets" button and its dialog were English-only on the German onboarding and targets pages. Their text now comes from the i18n table (new `demo` module), the kind badges use the shared target type labels, and the result badges follow the language. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p --- .../src/components/demo_targets.rs | 69 +++++----- compliance-dashboard/src/i18n/texts.rs | 120 ++++++++++++++++++ .../src/infrastructure/onboarding.rs | 47 +++++-- .../src/infrastructure/platform.rs | 3 - 4 files changed, 187 insertions(+), 52 deletions(-) diff --git a/compliance-dashboard/src/components/demo_targets.rs b/compliance-dashboard/src/components/demo_targets.rs index fb41774..3924174 100644 --- a/compliance-dashboard/src/components/demo_targets.rs +++ b/compliance-dashboard/src/components/demo_targets.rs @@ -1,4 +1,4 @@ -//! "Add demo targets" — one-click seeding of the versioned demo-target +//! "Add demo targets" („Demo-Prüfobjekte hinzufügen“) — one-click seeding of the versioned demo-target //! manifest (`GET/POST /api/v1/targets/demo-seed`). //! //! Renders a button that opens a confirm panel listing the manifest @@ -9,24 +9,13 @@ use dioxus::prelude::*; use crate::app::Route; +use crate::i18n::texts::{common, demo, kinds, nav, targets}; +use crate::i18n::use_lang; use crate::infrastructure::onboarding::{ demo_seed_default_selection, demo_seed_outcome, fetch_demo_seed_targets, seed_demo_targets, DemoSeedResult, DemoSeedTarget, }; -use crate::infrastructure::platform::{use_source_only, SOURCE_ONLY_NOTE}; - -/// Human label for a manifest target kind. -fn kind_label(kind: &str) -> &str { - match kind { - "plc_sps" => "PLC / SPS", - "backend_service" => "Backend / API", - "web_app" => "Web application", - "firmware_rtos" => "Firmware (RTOS)", - "firmware_bare_metal" => "Firmware (bare metal)", - "embedded_linux_yocto" => "Embedded Linux", - other => other, - } -} +use crate::infrastructure::platform::use_source_only; #[component] pub fn DemoTargetsButton( @@ -37,6 +26,7 @@ pub fn DemoTargetsButton( #[props(default)] secondary: bool, ) -> Element { + let lang = use_lang()(); let source_only = use_source_only(); let mut open = use_signal(|| false); let mut selected = use_signal(Vec::::new); @@ -79,34 +69,34 @@ pub fn DemoTargetsButton( rsx! { button { class: "{btn_class}", - title: "Seed the versioned demo targets and queue their first scan", + title: demo::BUTTON_HINT.get(lang), onclick: move |_| open.set(true), - "Add demo targets" + {demo::BUTTON.get(lang)} } if open() { div { class: "modal-overlay", div { class: "modal-dialog demo-targets-dialog", style: "max-width: 640px;", - h3 { "Add demo targets" } + h3 { {demo::BUTTON.get(lang)} } if let Some(res) = results() { DemoSeedResults { results: res } div { class: "modal-actions", - Link { to: Route::TargetsPage {}, class: "btn btn-secondary", "Targets list" } - Link { to: Route::FindingsPage { target: String::new() }, class: "btn btn-secondary", "Findings" } - button { class: "btn btn-primary", onclick: close, "Done" } + Link { to: Route::TargetsPage {}, class: "btn btn-secondary", {demo::TARGETS_LIST.get(lang)} } + Link { to: Route::FindingsPage { target: String::new() }, class: "btn btn-secondary", {nav::FINDINGS.get(lang)} } + button { class: "btn btn-primary", onclick: close, {demo::CLOSE.get(lang)} } } } else { p { style: "color: var(--text-secondary);", - "Seeds the versioned demo set as targets (named " + {demo::INTRO_START.get(lang)} code { "Demo · " } - ") and queues a first scan of each. Targets that already exist are left untouched." + {demo::INTRO_END.get(lang)} } if source_only { p { style: "color: var(--text-secondary); font-size: 0.9em;", - "This environment runs " - strong { "source-only" } - " — targets that need a live URL or device are not selectable." + {demo::SOURCE_ONLY_START.get(lang)} + strong { {demo::SOURCE_ONLY.get(lang)} } + {demo::SOURCE_ONLY_END.get(lang)} } } match &*manifest.read() { @@ -135,16 +125,16 @@ pub fn DemoTargetsButton( } Some(Some(Err(e))) => rsx! { div { style: "color: var(--danger); font-size: 0.9em; margin: 12px 0;", - "Could not load the demo manifest: {e}" + "{demo::LOAD_FAILED.get(lang)} {e}" } }, - _ => rsx! { div { class: "loading", "Loading manifest..." } }, + _ => rsx! { div { class: "loading", {common::LOADING.get(lang)} } }, } if let Some(err) = error() { div { style: "color: var(--danger); font-size: 0.9em; margin-bottom: 8px;", "{err}" } } div { class: "modal-actions", - button { class: "btn btn-secondary", disabled: submitting(), onclick: close, "Cancel" } + button { class: "btn btn-secondary", disabled: submitting(), onclick: close, {targets::CANCEL.get(lang)} } button { class: "btn btn-primary", disabled: submitting() || selected().is_empty(), @@ -165,7 +155,11 @@ pub fn DemoTargetsButton( submitting.set(false); }); }, - if submitting() { "Adding..." } else { "Add {selected().len()} target(s)" } + if submitting() { + {demo::ADDING.get(lang)} + } else { + {demo::add_count(selected().len(), lang)} + } } } } @@ -182,7 +176,9 @@ fn DemoTargetRow( disabled: bool, on_toggle: EventHandler, ) -> Element { + let lang = use_lang()(); let name = target.name.clone(); + let note = common::NOT_AVAILABLE_HERE.get(lang); let style = if disabled { "display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); opacity: 0.55;" } else { @@ -199,9 +195,11 @@ fn DemoTargetRow( div { style: "flex: 1; min-width: 0;", div { style: "display: flex; gap: 8px; align-items: center; flex-wrap: wrap;", strong { "{target.name}" } - span { class: "badge", "{kind_label(&target.kind)}" } + span { class: "badge", {kinds::target_type(&target.kind, lang)} } if disabled { - span { class: "badge badge-neutral", title: "{SOURCE_ONLY_NOTE}", "needs runtime — {SOURCE_ONLY_NOTE}" } + span { class: "badge badge-neutral", title: note, + "{demo::NEEDS_RUNTIME.get(lang)} — {note}" + } } } if !target.description.is_empty() { @@ -214,20 +212,21 @@ fn DemoTargetRow( #[component] fn DemoSeedResults(results: Vec) -> Element { + let lang = use_lang()(); let queued = results.iter().filter(|r| r.status == "queued").count(); let exists = results.iter().filter(|r| r.status == "exists").count(); let failed = results.iter().filter(|r| r.status == "failed").count(); rsx! { p { style: "color: var(--text-secondary);", - "{queued} added, {exists} already added, {failed} failed." + {demo::summary(queued, exists, failed, lang)} if queued > 0 { - " Scans run in the background — findings appear as they complete." + {demo::RUNS_IN_BACKGROUND.get(lang)} } } div { style: "display: flex; flex-direction: column; gap: 6px; margin: 12px 0;", for r in results { { - let (cls, label) = demo_seed_outcome(&r); + let (cls, label) = demo_seed_outcome(&r, lang); rsx! { div { style: "display: flex; gap: 10px; align-items: center; padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm);", strong { style: "flex: 1;", "{r.name}" } diff --git a/compliance-dashboard/src/i18n/texts.rs b/compliance-dashboard/src/i18n/texts.rs index 74dc263..ff3a0e8 100644 --- a/compliance-dashboard/src/i18n/texts.rs +++ b/compliance-dashboard/src/i18n/texts.rs @@ -1657,3 +1657,123 @@ pub mod compliance { en: "The CRA status could not be loaded.", }; } + +/// The "Add demo targets" button and its dialog. +pub mod demo { + use super::super::Lang; + use super::Text; + + pub const BUTTON: Text = Text { + de: "Demo-Prüfobjekte hinzufügen", + en: "Add demo targets", + }; + pub const BUTTON_HINT: Text = Text { + de: "Legt die versionierten Demo-Prüfobjekte an und plant ihre erste Prüfung ein", + en: "Seed the versioned demo targets and queue their first scan", + }; + /// Before the example name `Demo · `. + pub const INTRO_START: Text = Text { + de: "Legt den versionierten Demo-Satz als Prüfobjekte an (Name ", + en: "Seeds the versioned demo set as targets (named ", + }; + /// After the example name. + pub const INTRO_END: Text = Text { + de: ") und plant für jedes eine erste Prüfung ein. Bereits vorhandene \ + Prüfobjekte bleiben unverändert.", + en: ") and queues a first scan of each. Targets that already exist are left \ + untouched.", + }; + /// Before the highlighted "source-only". + pub const SOURCE_ONLY_START: Text = Text { + de: "Diese Umgebung prüft ", + en: "This environment runs ", + }; + pub const SOURCE_ONLY: Text = Text { + de: "nur Quellcode", + en: "source-only", + }; + /// After the highlighted "source-only". + pub const SOURCE_ONLY_END: Text = Text { + de: " – Prüfobjekte, die eine Live-URL oder ein Gerät brauchen, sind nicht \ + auswählbar.", + en: " — targets that need a live URL or device are not selectable.", + }; + pub const NEEDS_RUNTIME: Text = Text { + de: "braucht Laufzeitumgebung", + en: "needs runtime", + }; + pub const LOAD_FAILED: Text = Text { + de: "Die Demo-Liste konnte nicht geladen werden:", + en: "Could not load the demo manifest:", + }; + pub const ADDING: Text = Text { + de: "Wird hinzugefügt …", + en: "Adding...", + }; + pub const ADDED: Text = Text { + de: "hinzugefügt", + en: "added", + }; + pub const ADDED_SCAN_QUEUED: Text = Text { + de: "hinzugefügt – Prüfung eingeplant", + en: "added — scan queued", + }; + pub const ALREADY_ADDED: Text = Text { + de: "bereits vorhanden", + en: "already added", + }; + pub const FAILED: Text = Text { + de: "fehlgeschlagen", + en: "failed", + }; + pub const RUNS_IN_BACKGROUND: Text = Text { + de: " Die Prüfungen laufen im Hintergrund; Befunde erscheinen, sobald sie \ + fertig sind.", + en: " Scans run in the background — findings appear as they complete.", + }; + pub const TARGETS_LIST: Text = Text { + de: "Zur Prüfobjektliste", + en: "Targets list", + }; + pub const CLOSE: Text = Text { + de: "Fertig", + en: "Done", + }; + + /// The confirm button: "Add 3 target(s)", "3 Prüfobjekt(e) hinzufügen". + pub fn add_count(count: usize, lang: Lang) -> String { + match lang { + Lang::De => format!("{count} Prüfobjekt(e) hinzufügen"), + Lang::En => format!("Add {count} target(s)"), + } + } + + /// The result line: how many were added, already there, or failed. + pub fn summary(added: usize, existing: usize, failed: usize, lang: Lang) -> String { + format!( + "{added} {}, {existing} {}, {failed} {}.", + ADDED.get(lang), + ALREADY_ADDED.get(lang), + FAILED.get(lang) + ) + } + + #[cfg(test)] + mod tests { + use super::*; + + #[test] + fn counts_read_like_the_language() { + assert_eq!(add_count(3, Lang::De), "3 Prüfobjekt(e) hinzufügen"); + assert_eq!(add_count(3, Lang::En), "Add 3 target(s)"); + assert_eq!( + summary(2, 1, 0, Lang::De), + "2 hinzugefügt, 1 bereits vorhanden, 0 fehlgeschlagen." + ); + assert_eq!( + summary(2, 1, 0, Lang::En), + "2 added, 1 already added, 0 failed." + ); + } + } +} diff --git a/compliance-dashboard/src/infrastructure/onboarding.rs b/compliance-dashboard/src/infrastructure/onboarding.rs index a75aa99..70db1fb 100644 --- a/compliance-dashboard/src/infrastructure/onboarding.rs +++ b/compliance-dashboard/src/infrastructure/onboarding.rs @@ -4,6 +4,9 @@ use dioxus::prelude::*; use serde::{Deserialize, Serialize}; +use crate::i18n::texts::demo; +use crate::i18n::Lang; + /// One artifact the wizard collects for a target. #[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)] pub struct ArtifactInputDto { @@ -91,22 +94,26 @@ pub struct DemoSeedResponse { pub seeded: Vec, } -/// Visual outcome of one seeded demo target: (badge class, label). -pub fn demo_seed_outcome(result: &DemoSeedResult) -> (&'static str, String) { +/// Visual outcome of one seeded demo target, in `lang`: (badge class, label). +pub fn demo_seed_outcome(result: &DemoSeedResult, lang: Lang) -> (&'static str, String) { match result.status.as_str() { "queued" => { - if result.scan_id.is_some() { - ("badge badge-success", "added — scan queued".to_string()) + let label = if result.scan_id.is_some() { + demo::ADDED_SCAN_QUEUED } else { - ("badge badge-success", "added".to_string()) - } + demo::ADDED + }; + ("badge badge-success", label.get(lang).to_string()) } - "exists" => ("badge badge-info", "already added".to_string()), + "exists" => ( + "badge badge-info", + demo::ALREADY_ADDED.get(lang).to_string(), + ), "failed" => ( "badge badge-danger", match result.error.as_deref().filter(|e| !e.trim().is_empty()) { - Some(e) => format!("failed: {e}"), - None => "failed".to_string(), + Some(e) => format!("{}: {e}", demo::FAILED.get(lang)), + None => demo::FAILED.get(lang).to_string(), }, ), other => ("badge", other.to_string()), @@ -446,21 +453,33 @@ mod tests { #[test] fn seed_outcome_labels() { - let (cls, label) = demo_seed_outcome(&result("queued", Some("s1"), None)); + let en = Lang::En; + let (cls, label) = demo_seed_outcome(&result("queued", Some("s1"), None), en); assert_eq!(cls, "badge badge-success"); assert_eq!(label, "added — scan queued"); - let (_, label) = demo_seed_outcome(&result("queued", None, None)); + let (_, label) = demo_seed_outcome(&result("queued", None, None), en); assert_eq!(label, "added"); - let (cls, label) = demo_seed_outcome(&result("exists", None, None)); + let (cls, label) = demo_seed_outcome(&result("exists", None, None), en); assert_eq!(cls, "badge badge-info"); assert_eq!(label, "already added"); - let (cls, label) = demo_seed_outcome(&result("failed", None, Some("clone failed"))); + let (cls, label) = demo_seed_outcome(&result("failed", None, Some("clone failed")), en); assert_eq!(cls, "badge badge-danger"); assert_eq!(label, "failed: clone failed"); - let (_, label) = demo_seed_outcome(&result("failed", None, None)); + let (_, label) = demo_seed_outcome(&result("failed", None, None), en); assert_eq!(label, "failed"); } + #[test] + fn seed_outcome_labels_in_german() { + let de = Lang::De; + let (_, label) = demo_seed_outcome(&result("queued", Some("s1"), None), de); + assert_eq!(label, "hinzugefügt – Prüfung eingeplant"); + let (_, label) = demo_seed_outcome(&result("exists", None, None), de); + assert_eq!(label, "bereits vorhanden"); + let (_, label) = demo_seed_outcome(&result("failed", None, Some("clone failed")), de); + assert_eq!(label, "fehlgeschlagen: clone failed"); + } + #[test] fn seed_response_parses_contract_shape() { let body = serde_json::json!({ diff --git a/compliance-dashboard/src/infrastructure/platform.rs b/compliance-dashboard/src/infrastructure/platform.rs index e952b5f..680f2d0 100644 --- a/compliance-dashboard/src/infrastructure/platform.rs +++ b/compliance-dashboard/src/infrastructure/platform.rs @@ -17,9 +17,6 @@ use serde::{Deserialize, Serialize}; /// live-target) capabilities are available. pub const FEATURE_SOURCE_ONLY: &str = "source_only"; -/// Short user-facing note for surfaces that are disabled in source-only mode. -pub const SOURCE_ONLY_NOTE: &str = "Not available in this environment"; - /// How long the server keeps a successful handshake before re-probing. #[cfg(feature = "server")] pub const CACHE_TTL_SECS: u64 = 60;