csaf-crud 1.4.15

CSAF 2.0 / 2.1 advisory CRUD server with HATEOAS JSON API and HTML UI (TLS 1.3, HTTP/1.1 + HTTP/2 + HTTP/3)
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2026 Pierre Gronau, ndaal in Cologne

//! Dashboard (`routes::home`) page translations.
//!
//! The `<h1>` title reuses `nav.dashboard` (owned by [`super::nav`]) rather
//! than duplicating it here, since the same label already names the nav
//! link that points at this page.

use super::Entry;

/// Look up a `home.*` translation key.
pub(super) fn tr(key: &str) -> Option<Entry> {
    Some(match key {
        "home.stat_documents" => (
            "Total Documents",
            "Dokumente insgesamt",
            "Total des documents",
            "Total de documentos",
            "Totale documenti",
        ),
        "home.stat_advisories" => (
            "Security Advisories",
            "Sicherheitshinweise",
            "Avis de sécurité",
            "Avisos de seguridad",
            "Avvisi di sicurezza",
        ),
        "home.stat_vex" => (
            "VEX Documents",
            "VEX-Dokumente",
            "Documents VEX",
            "Documentos VEX",
            "Documenti VEX",
        ),
        "home.stat_informational" => (
            "Informational",
            "Informativ",
            "Informatif",
            "Informativo",
            "Informativo",
        ),
        "home.config_title" => (
            "Configuration",
            "Konfiguration",
            "Configuration",
            "Configuración",
            "Configurazione",
        ),
        "home.config_csaf_mode" => (
            "CSAF Mode",
            "CSAF-Modus",
            "Mode CSAF",
            "Modo CSAF",
            "Modalità CSAF",
        ),
        "home.config_theme" => ("Theme", "Design", "Thème", "Tema", "Tema"),
        "home.config_naming" => (
            "Naming",
            "Benennung",
            "Nommage",
            "Nomenclatura",
            "Denominazione",
        ),
        "home.activity_title" => (
            "Recent Activity",
            "Letzte Aktivität",
            "Activité récente",
            "Actividad reciente",
            "Attività recente",
        ),
        "home.col_timestamp" => (
            "Timestamp",
            "Zeitstempel",
            "Horodatage",
            "Marca de tiempo",
            "Data e ora",
        ),
        "home.col_action" => ("Action", "Aktion", "Action", "Acción", "Azione"),
        "home.col_tracking_id" => (
            "Tracking ID",
            "Tracking-ID",
            "ID de suivi",
            "ID de seguimiento",
            "ID di tracciamento",
        ),
        "home.col_details" => ("Details", "Details", "Détails", "Detalles", "Dettagli"),
        "home.no_activity" => (
            "No activity recorded yet.",
            "Noch keine Aktivität aufgezeichnet.",
            "Aucune activité enregistrée pour le moment.",
            "Aún no se ha registrado ninguna actividad.",
            "Nessuna attività registrata finora.",
        ),
        "home.action_create" => ("create", "erstellen", "créer", "crear", "creare"),
        "home.action_update" => (
            "update",
            "aktualisieren",
            "mettre à jour",
            "actualizar",
            "aggiornare",
        ),
        "home.action_delete" => ("delete", "löschen", "supprimer", "eliminar", "eliminare"),
        "home.action_import" => ("import", "importieren", "importer", "importar", "importare"),
        "home.action_export" => ("export", "exportieren", "exporter", "exportar", "esportare"),
        _ => return None,
    })
}

#[cfg(test)]
mod tests {
    use super::super::{Lang, t};
    use super::*;

    #[test]
    fn every_home_key_has_five_nonempty_translations() {
        for key in [
            "home.stat_documents",
            "home.stat_advisories",
            "home.stat_vex",
            "home.stat_informational",
            "home.config_title",
            "home.config_csaf_mode",
            "home.config_theme",
            "home.config_naming",
            "home.activity_title",
            "home.col_timestamp",
            "home.col_action",
            "home.col_tracking_id",
            "home.col_details",
            "home.no_activity",
            "home.action_create",
            "home.action_update",
            "home.action_delete",
            "home.action_import",
            "home.action_export",
        ] {
            let (en, de, fr, es, it) = tr(key).unwrap_or_else(|| panic!("{key} resolves"));
            assert!(
                !en.is_empty()
                    && !de.is_empty()
                    && !fr.is_empty()
                    && !es.is_empty()
                    && !it.is_empty(),
                "{key}"
            );
        }
    }

    #[test]
    fn unknown_key_is_not_claimed_by_this_table() {
        assert_eq!(tr("home.does_not_exist"), None);
    }

    #[test]
    fn t_dispatches_home_keys_through_the_shared_lookup() {
        assert_eq!(t(Lang::De, "home.config_theme"), "Design");
        assert_eq!(t(Lang::Fr, "home.col_action"), "Action");
        assert_eq!(t(Lang::It, "home.action_export"), "esportare");
    }
}