Skip to content

Commit

Permalink
chore(locales): add locale usage
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Oct 14, 2023
1 parent 447b0db commit 43930e0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 4 additions & 0 deletions accessibility-rs/src/engine/audit/auditor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub struct Auditor<'a> {
selectors::matching::MatchingContext<'a, accessibility_scraper::selector::Simple>,
/// layout handling
pub taffy: Option<Taffy>,
/// language to get results in
pub locale: &'a str
}

impl<'a> Auditor<'a> {
Expand All @@ -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 = {
Expand Down Expand Up @@ -67,6 +70,7 @@ impl<'a> Auditor<'a> {
author,
match_context,
taffy,
locale
}
}
}
15 changes: 5 additions & 10 deletions accessibility-rs/src/engine/audit/wcag.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<Issue> {
let mut issues: Vec<Issue> = Vec::new();
// TODO: push rules found to MAP that are different across nodes to combine the selectors
let mut issues: Vec<Issue> = 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);
Expand All @@ -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,
&[
Expand All @@ -47,8 +43,7 @@ impl WCAG3AA {
.join("."),
rule.issue_type.as_str(),
validation.elements,
);
issues.push(issue);
));
}
}
}
Expand Down
1 change: 1 addition & 0 deletions accessibility-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ pub fn audit(config: AuditConfig) -> Vec<Issue> {
&config.css,
engine::styles::css_cache::build_matching_context(&mut nth_index_cache),
config.bounding_box,
config.locale
);
engine::audit::wcag::WCAG3AA::audit(&auditor)
}

0 comments on commit 43930e0

Please sign in to comment.