From 43930e06863aaeaee8d9efcf40452324b6065bb4 Mon Sep 17 00:00:00 2001 From: j-mendez Date: Sat, 14 Oct 2023 19:10:08 -0400 Subject: [PATCH] chore(locales): add locale usage --- accessibility-rs/src/engine/audit/auditor.rs | 4 ++++ accessibility-rs/src/engine/audit/wcag.rs | 15 +++++---------- accessibility-rs/src/lib.rs | 1 + 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/accessibility-rs/src/engine/audit/auditor.rs b/accessibility-rs/src/engine/audit/auditor.rs index c3add47..dad01b5 100644 --- a/accessibility-rs/src/engine/audit/auditor.rs +++ b/accessibility-rs/src/engine/audit/auditor.rs @@ -20,6 +20,8 @@ pub struct Auditor<'a> { selectors::matching::MatchingContext<'a, accessibility_scraper::selector::Simple>, /// layout handling pub taffy: Option, + /// language to get results in + pub locale: &'a str } impl<'a> Auditor<'a> { @@ -32,6 +34,7 @@ impl<'a> Auditor<'a> { accessibility_scraper::selector::Simple, >, bounds: bool, + locale: &'a str ) -> Auditor<'a> { // TODO: make stylesheet building optional and only on first requirement let author = { @@ -67,6 +70,7 @@ impl<'a> Auditor<'a> { author, match_context, taffy, + locale } } } diff --git a/accessibility-rs/src/engine/audit/wcag.rs b/accessibility-rs/src/engine/audit/wcag.rs index b9b0ba0..87abe91 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_i18n, Langs}; +use crate::i18n::locales::get_message_i18n; use crate::Auditor; /// baseline for all rules @@ -11,13 +11,11 @@ pub struct WCAG3AA; impl WCAG3AA { /// init the rules pub fn audit( - // allow tree mutation until threads or setup the tree with initial elements. auditor: &Auditor<'_>, ) -> Vec { - let mut issues: Vec = Vec::new(); // TODO: push rules found to MAP that are different across nodes to combine the selectors + let mut issues: Vec = Vec::new(); - // go through nodes and map to validation rules for node in &auditor.tree { if RULES_A.contains_key(&*node.0) { let rules = RULES_A.get(&*node.0); @@ -28,14 +26,12 @@ impl WCAG3AA { let message = validation.message; if !validation.valid { - // get locales prior or from document let message = if !message.is_empty() { message.into() } else { - get_message_i18n(&rule, &validation.id, &Langs::En.as_str()) + get_message_i18n(&rule, &validation.id, &auditor.locale) }; - - let issue = Issue::new( + issues.push(Issue::new( message, &node.0, &[ @@ -47,8 +43,7 @@ impl WCAG3AA { .join("."), rule.issue_type.as_str(), validation.elements, - ); - issues.push(issue); + )); } } } diff --git a/accessibility-rs/src/lib.rs b/accessibility-rs/src/lib.rs index a5942b3..845ae09 100644 --- a/accessibility-rs/src/lib.rs +++ b/accessibility-rs/src/lib.rs @@ -90,6 +90,7 @@ pub fn audit(config: AuditConfig) -> Vec { &config.css, engine::styles::css_cache::build_matching_context(&mut nth_index_cache), config.bounding_box, + config.locale ); engine::audit::wcag::WCAG3AA::audit(&auditor) }