diff --git a/accessibility-rs/src/engine/audit/wcag.rs b/accessibility-rs/src/engine/audit/wcag.rs index 0b4e3dd..4ae3f8e 100644 --- a/accessibility-rs/src/engine/audit/wcag.rs +++ b/accessibility-rs/src/engine/audit/wcag.rs @@ -1,6 +1,6 @@ use crate::engine::issue::Issue; use crate::engine::rules::wcag_rule_map::RULES_A; -use crate::i18n::locales::{get_message, Langs}; +use crate::i18n::locales::{get_message, get_message_i18n, Langs}; use crate::Auditor; /// baseline for all rules @@ -32,9 +32,9 @@ impl WCAG3AA { if !valid { // get locales prior or from document let message = if !message.is_empty() { - message + message.into() } else { - get_message(&rule.rule_id, §ion, &Langs::En.as_str()) + get_message_i18n(&rule, §ion, &Langs::En.as_str()) }; let issue = Issue::new( @@ -52,11 +52,6 @@ impl WCAG3AA { ); issues.push(issue); } - - println!( - "RULE {:?} {:?} {:?} Valid: {:?}", - rule.rule_id, rule.criteria, section, valid - ); } } _ => (), diff --git a/accessibility-rs/src/engine/issue.rs b/accessibility-rs/src/engine/issue.rs index 592f419..8837c50 100644 --- a/accessibility-rs/src/engine/issue.rs +++ b/accessibility-rs/src/engine/issue.rs @@ -38,7 +38,7 @@ pub struct Issue { /// the typecode of the issue 0,1,2 pub type_code: u8, /// the message of the issue - pub message: &'static str, + pub message: String, /// the type of runner pub runner: &'static str, /// extra details for the runner @@ -52,7 +52,7 @@ pub struct Issue { impl Issue { /// create a new issue pub fn new( - message: &'static str, + message: String, context: &str, code: &str, issue_type: &'static str, diff --git a/accessibility-rs/src/engine/rules/rule.rs b/accessibility-rs/src/engine/rules/rule.rs index 4b443ec..0f3f77d 100644 --- a/accessibility-rs/src/engine/rules/rule.rs +++ b/accessibility-rs/src/engine/rules/rule.rs @@ -43,6 +43,7 @@ impl Validation { } /// the rule validation method that should be performed. +#[derive(Debug)] pub struct Rule { /// the message id of the rule to point to the locale pub rule_id: Techniques, diff --git a/accessibility-rs/src/engine/rules/wcag_base.rs b/accessibility-rs/src/engine/rules/wcag_base.rs index 2c7a050..8a7a0cc 100644 --- a/accessibility-rs/src/engine/rules/wcag_base.rs +++ b/accessibility-rs/src/engine/rules/wcag_base.rs @@ -21,6 +21,7 @@ impl Criteria { } /// wcag principle to follow +#[derive(Debug)] pub enum Principle { /// Provide text alternatives for any non-text content so that it can be changed into other forms people need, such as large print, braille, speech, symbols or simpler language. Perceivable, @@ -33,6 +34,7 @@ pub enum Principle { } impl Principle { + /// the principle to string code pub fn as_str(&self) -> &'static str { match self { Principle::Perceivable => "Principle1", @@ -41,9 +43,19 @@ impl Principle { Principle::Robust => "Principle4", } } + /// the principle index + pub fn as_index(&self) -> &'static str { + match self { + Principle::Perceivable => "1", + Principle::Operable => "2", + Principle::Understandable => "3", + Principle::Robust => "4", + } + } } /// wcag principle to follow +#[derive(Debug)] pub enum Guideline { /// Provide ways to help users navigate, find content, and determine where they are. Navigable, @@ -56,6 +68,7 @@ pub enum Guideline { } impl Guideline { + /// the guideline to string code pub fn as_str(&self) -> &'static str { match self { Guideline::EnoughTime => "Guideline2_2", @@ -64,4 +77,13 @@ impl Guideline { Guideline::Predictable => "Guideline3_2", } } + /// the principle index + pub fn as_index(&self) -> &'static str { + match self { + Guideline::EnoughTime => "2_2", + Guideline::Navigable => "2_4", + Guideline::Readable => "3_1", + Guideline::Predictable => "3_2", + } + } } diff --git a/accessibility-rs/src/engine/rules/wcag_rule_map.rs b/accessibility-rs/src/engine/rules/wcag_rule_map.rs index 098e31e..38e417c 100644 --- a/accessibility-rs/src/engine/rules/wcag_rule_map.rs +++ b/accessibility-rs/src/engine/rules/wcag_rule_map.rs @@ -57,7 +57,7 @@ lazy_static! { Rule::new(Techniques::H25, Criteria::Error, Principle::Operable, Guideline::Navigable, |_rule, nodes| { Validation::new_issue(!nodes.is_empty(), "1.NoTitleEl") }), - Rule::new(Techniques::H25, Criteria::Error, Principle::Understandable, Guideline::Predictable, |_rule, nodes| { + Rule::new(Techniques::H25, Criteria::Error, Principle::Operable, Guideline::Navigable, |_rule, nodes| { Validation::new_issue(nodes.is_empty() || nodes[0].0.html().is_empty(), "1.EmptyTitle") }), ])), diff --git a/accessibility-rs/src/i18n/locales.rs b/accessibility-rs/src/i18n/locales.rs index bcefe4c..10f86f8 100644 --- a/accessibility-rs/src/i18n/locales.rs +++ b/accessibility-rs/src/i18n/locales.rs @@ -1,4 +1,4 @@ -use crate::engine::rules::ids::Techniques; +use crate::engine::rules::{ids::Techniques, rule::Rule}; use std::collections::BTreeMap; type M = &'static str; @@ -102,15 +102,20 @@ pub fn get_message(rule_id: &Techniques, section: &str, lang: &str) -> &'static } /// get message config type -pub fn get_message_i18n(rule_id: &Techniques, section: &str, lang: &str) -> String { - let rule_id = rule_id.as_str(); +pub fn get_message_i18n(rule: &Rule, section: &str, lang: &str) -> String { + let base = [rule.guideline.as_index(), rule.principle.as_index()].join("_") + "_"; + let message = if section.is_empty() { + [rule.rule_id.as_str()].join(".").to_string() + } else { + [rule.rule_id.as_str(), section].join(".").to_string() + }; let message = if section.is_empty() { - rule_id.to_string() + [base.as_str(), message.as_str()].join("").to_string() } else { - [rule_id, section].join(".").to_string() + [base.as_str(), message.as_str()].join("").to_string() }; - message + t!(&message, lang = lang) } lazy_static! { diff --git a/accessibility-rs/tests/unit/meta.rs b/accessibility-rs/tests/unit/meta.rs index 6f2a722..335158e 100644 --- a/accessibility-rs/tests/unit/meta.rs +++ b/accessibility-rs/tests/unit/meta.rs @@ -6,12 +6,12 @@ use crate::mocks::mock; #[test] /// missing title element -fn _audit_missing_headers() { +fn _audit_missing_title() { let audit = accessibility_rs::audit(&AuditConfig::basic(mock::MOCK_WEBSITE_HTML)); let mut valid = true; for x in &audit { - if x.code == "WCAGAAA.Principle3.Guideline3_2.H25" { + if x.code == "WCAGAAA.Principle2.Guideline2_4.H25" { valid = false; break; }