#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Locale {
#[default]
En,
Fr,
De,
Es,
}
impl Locale {
pub fn from_lang_code(code: &str) -> Self {
let lower = code.to_ascii_lowercase();
if lower.starts_with("fr") || lower.starts_with("french") {
Self::Fr
} else if lower.starts_with("de") || lower.starts_with("german") {
Self::De
} else if lower.starts_with("es") || lower.starts_with("spanish") {
Self::Es
} else {
Self::En
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum Key {
StatusOnline,
StatusDegraded,
StatusOffline,
StatusIdle,
ConfirmDefault,
CancelDefault,
}
pub(crate) fn tr(locale: Locale, key: Key) -> &'static str {
use Key::*;
use Locale::*;
match (locale, key) {
(En, StatusOnline) => "Online",
(En, StatusDegraded) => "Degraded",
(En, StatusOffline) => "Offline",
(En, StatusIdle) => "Idle",
(En, ConfirmDefault) => "Confirm",
(En, CancelDefault) => "Cancel",
(Fr, StatusOnline) => "En ligne",
(Fr, StatusDegraded) => "Dégradé",
(Fr, StatusOffline) => "Hors ligne",
(Fr, StatusIdle) => "Inactif",
(Fr, ConfirmDefault) => "Confirmer",
(Fr, CancelDefault) => "Annuler",
(De, StatusOnline) => "Online",
(De, StatusDegraded) => "Beeinträchtigt",
(De, StatusOffline) => "Offline",
(De, StatusIdle) => "Inaktiv",
(De, ConfirmDefault) => "Bestätigen",
(De, CancelDefault) => "Abbrechen",
(Es, StatusOnline) => "En línea",
(Es, StatusDegraded) => "Degradado",
(Es, StatusOffline) => "Desconectado",
(Es, StatusIdle) => "Inactivo",
(Es, ConfirmDefault) => "Confirmar",
(Es, CancelDefault) => "Cancelar",
}
}