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

//! Navigation chrome translations: primary nav, header control cluster
//! (theme / language / Info) and the Info dropdown's own item labels.
//!
//! The Info dropdown's *destination pages* (About, License, ...) own their
//! body-content translations in [`super::info`]; this module only owns the
//! nav-menu label text that names them, since that text is rendered by
//! `routes::layout::wrap_page`, not by `routes::info`.

use super::Entry;

/// Look up a `nav.*` translation key.
pub(super) fn tr(key: &str) -> Option<Entry> {
    Some(match key {
        "nav.dashboard" => (
            "Dashboard",
            "Dashboard",
            "Dashboard",
            "Dashboard",
            "Dashboard",
        ),
        "nav.csaf" => ("CSAF", "CSAF", "CSAF", "CSAF", "CSAF"),
        "nav.import" => ("Import", "Import", "Import", "Importación", "Importazione"),
        "nav.export" => ("Export", "Export", "Export", "Exportación", "Esportazione"),
        "nav.settings" => (
            "Settings",
            "Einstellungen",
            "Paramètres",
            "Configuración",
            "Impostazioni",
        ),
        "nav.info" => ("Info", "Info", "Info", "Info", "Info"),
        "nav.language" => ("Language", "Sprache", "Langue", "Idioma", "Lingua"),
        "nav.theme_light" => ("Light", "Hell", "Clair", "Claro", "Chiaro"),
        "nav.theme_dark" => ("Dark", "Dunkel", "Sombre", "Oscuro", "Scuro"),
        "nav.theme_toggle" => (
            "Toggle theme",
            "Design umschalten",
            "Basculer le thème",
            "Cambiar tema",
            "Cambia tema",
        ),
        "nav.skip_main" => (
            "Skip to main content",
            "Zum Hauptinhalt springen",
            "Aller au contenu principal",
            "Saltar al contenido principal",
            "Vai al contenuto principale",
        ),
        "nav.brand_label" => (
            "ndaal CSAF home",
            "ndaal CSAF Startseite",
            "Accueil ndaal CSAF",
            "Inicio ndaal CSAF",
            "Home ndaal CSAF",
        ),
        "nav.logo_alt" => (
            "ndaal — information security & compliance",
            "ndaal — Informationssicherheit & Compliance",
            "ndaal — sécurité de l'information et conformité",
            "ndaal — seguridad de la información y cumplimiento",
            "ndaal — sicurezza delle informazioni e conformità",
        ),
        "nav.info_about" => ("About", "Über", "À propos", "Acerca de", "Informazioni su"),
        "nav.info_license" => ("License", "Lizenz", "Licence", "Licencia", "Licenza"),
        "nav.info_system" => (
            "System Info",
            "Systeminfo",
            "Infos système",
            "Info del sistema",
            "Info di sistema",
        ),
        "nav.info_privacy" => (
            "Privacy",
            "Datenschutz",
            "Confidentialité",
            "Privacidad",
            "Privacy",
        ),
        "nav.info_security" => (
            "Security",
            "Sicherheit",
            "Sécurité",
            "Seguridad",
            "Sicurezza",
        ),
        "nav.info_changelog" => (
            "Changelog",
            "Changelog",
            "Changelog",
            "Changelog",
            "Changelog",
        ),
        "nav.info_readme" => ("README", "LIESMICH", "LISEZMOI", "LEEME", "LEGGIMI"),
        "nav.info_administrator" => (
            "Administrator Guide",
            "Administratorhandbuch",
            "Guide d'administration",
            "Guía del administrador",
            "Guida dell'amministratore",
        ),
        "nav.info_user" => (
            "User Guide",
            "Benutzerhandbuch",
            "Guide utilisateur",
            "Guía del usuario",
            "Guida utente",
        ),
        _ => return None,
    })
}

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

    #[test]
    fn every_nav_key_has_five_nonempty_translations() {
        for key in [
            "nav.dashboard",
            "nav.csaf",
            "nav.import",
            "nav.export",
            "nav.settings",
            "nav.info",
            "nav.language",
            "nav.theme_light",
            "nav.theme_dark",
            "nav.theme_toggle",
            "nav.skip_main",
            "nav.brand_label",
            "nav.logo_alt",
            "nav.info_about",
            "nav.info_license",
            "nav.info_system",
            "nav.info_privacy",
            "nav.info_security",
            "nav.info_changelog",
            "nav.info_readme",
            "nav.info_administrator",
            "nav.info_user",
        ] {
            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("nav.does_not_exist"), None);
    }

    #[test]
    fn t_dispatches_nav_keys_through_the_shared_lookup() {
        assert_eq!(t(Lang::De, "nav.settings"), "Einstellungen");
        assert_eq!(t(Lang::Fr, "nav.language"), "Langue");
        assert_eq!(t(Lang::It, "nav.info_readme"), "LEGGIMI");
    }
}