use crate::engine::rules::{rule::Rule, wcag_base::Guideline};
type M = &'static str;
#[derive(std::cmp::Eq, PartialEq, PartialOrd, Ord)]
pub struct Messages {
ar: M,
en: M,
es: M,
de: M,
ja: M,
ko: M,
pt_pt: M,
pt_br: M,
zh_cn: M,
zh_tw: M,
hi: M,
}
pub enum Langs {
En,
Es,
De,
Ja,
PtPt,
PtBr,
ZhCn,
ZhTw,
HI,
}
impl Langs {
pub fn as_str(&self) -> &'static str {
match self {
Langs::En => "en",
Langs::Es => "es",
Langs::De => "de",
Langs::Ja => "ja",
Langs::PtPt => "pt_pt",
Langs::PtBr => "pt_br",
Langs::ZhCn => "zh_cn",
Langs::ZhTw => "zh_tw",
Langs::HI => "hi",
}
}
}
pub fn get_message_i18n_str_raw(
guideline: &Guideline,
rule_id: &str,
success_criteria: &str,
section: &str,
) -> String {
let base = [guideline.as_index(), success_criteria].join("_") + "_";
let message = if section.is_empty() {
[rule_id].join(".").to_string()
} else {
[rule_id, section].join(".").to_string()
};
let mut m = [base.as_str(), message.as_str()].join("").to_string();
if m.ends_with("_") {
m.pop();
m
} else {
m
}
}
pub fn get_message_i18n_str(rule: &Rule, section: &str) -> String {
get_message_i18n_str_raw(
&rule.guideline,
&rule.rule_id.into_str(),
rule.success_criteria,
section,
)
}
pub fn get_message_i18n(rule: &Rule, section: &str, lang: &str) -> String {
let message = get_message_i18n_str(rule, section);
t!(&message, locale = lang)
}