Skip to content

Commit

Permalink
feat: DAISY Knowledge Base Japanese redirect (translation is available)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielweck committed Dec 2, 2024
1 parent d122dfa commit bfe839b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
4 changes: 2 additions & 2 deletions packages/ace-core/src/checker/checker-epub.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const path = require('path');
const builders = require('@daisy/ace-report').builders;
const winston = require('winston');

const { localize } = require('../l10n/localize').localizer;
const { localize, getCurrentLanguage } = require('../l10n/localize').localizer;

const a11yMetadata = require('../core/a11y-metadata');

Expand All @@ -31,7 +31,7 @@ function newViolation({ impact = 'serious', title, testDesc, resDesc, kbPath, kb
.withTitle(title)
.withDescription(testDesc)
.withHelp(
KB_BASE + kbPath,
KB_BASE + (getCurrentLanguage() === "ja" ? kbPath.replace(/^docs/, "ja") : kbPath),
kbTitle,
resDesc)
.withRulesetTags(['EPUB'])
Expand Down
33 changes: 16 additions & 17 deletions packages/ace-report-axe/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
const builders = require('@daisy/ace-report').builders;
const winston = require('winston');

const { localize, setCurrentLanguage } = require('./l10n/localize').localizer;
const { localize, setCurrentLanguage, getCurrentLanguage } = require('./l10n/localize').localizer;

const axeRulesKbMapping = require('./axe-rules-kb-mapping').kbMap;

Expand All @@ -17,21 +17,20 @@ async function axe2ace(spineItem, axeResults, lang) {
winston.verbose(`Converting aXe results to ace for ${spineItem.relpath}`);

function l10nDoneCallback() {

const kbMap = axeRulesKbMapping;

// the content doc-level assertion
const assertion = new builders.AssertionBuilder()
.withSubAssertions()
.withTestSubject(spineItem.relpath, spineItem.title);
// process axe's individual checks for a single content document
// console.log("axe2ace ------- ", JSON.stringify(axeResults, null, 4));
axeResults.violations.forEach((violation) => {

const kbURL = (kbMap.map.hasOwnProperty(violation.id))
? kbMap.baseUrl + kbMap.map[violation.id].url
: kbMap.baseUrl;
let kbTitle = (kbMap.map.hasOwnProperty(violation.id))
const kbURL = kbMap.map.hasOwnProperty(violation.id)
? (kbMap.baseUrl + (getCurrentLanguage() === "ja" ? kbMap.map[violation.id].url.replace(/^docs/, "ja") : kbMap.map[violation.id].url))
: ((kbMap.baseUrl + (getCurrentLanguage() === "ja" ? "ja" : "")));
let kbTitle = kbMap.map.hasOwnProperty(violation.id)
? kbMap.map[violation.id].title
: '??';
if (kbTitle == '??') {
Expand All @@ -45,11 +44,11 @@ async function axe2ace(spineItem, axeResults, lang) {
.withHelp(kbURL, kbTitle, violation.help)
.withRulesetTags(violation.tags) // .map(t => t.replace("wcag2a", "wcag21a")) TO TEST TAG FILTERING IN HTML REPORT
.build();

violation.nodes.forEach((node) => {

let description = node.failureSummary;

// https://github.com/dequelabs/axe-core/blob/v3.2.2/lib/core/reporters/helpers/failure-summary.js
// // https://github.com/dequelabs/axe-core/blob/v3.2.2/lib/misc/none-failure-summary.json#L4
// Fix all of the following:
Expand All @@ -59,7 +58,7 @@ async function axe2ace(spineItem, axeResults, lang) {
// Fix any of the following:
// // https://github.com/dequelabs/axe-core/blob/v3.2.2/locales/fr.json#L656
// Corriger l’un des éléments suivants :

// TODO: this is a hacky way to fix the Axe bug that forces the wrong language (en) into `failureSummary`.
description = description.replace(/Fix any of the following:/g, "");
description = description.replace(/Fix all of the following:/g, "");
Expand All @@ -68,11 +67,11 @@ async function axe2ace(spineItem, axeResults, lang) {
description = description.replace(/\n/g, " --- ");
description = description.replace(/\s+/g, " ");
description = description.replace(/ --- /g, "\n");

let target = node.target;
let targetCFI = node.targetCFI;
let html = node.html;

const allAnyArrayItems = [];
if (node.any) {
node.any.forEach((anyItem) => {
Expand All @@ -90,14 +89,14 @@ async function axe2ace(spineItem, axeResults, lang) {
if (relatedNode.html && relatedNode.target && relatedNode.target.length && relatedNode.targetCFI && relatedNode.targetCFI.length) {
html += " <!--##--> ";
html += relatedNode.html;

target.push(relatedNode.target[0]);
targetCFI.push(relatedNode.targetCFI[0]);
}
});
}
});

assertion.withAssertions(
new builders.AssertionBuilder()
.withAssertedBy('aXe')
Expand All @@ -112,7 +111,7 @@ async function axe2ace(spineItem, axeResults, lang) {
.build());
});
});

const ass = assertion.build();
resolve(ass);
}
Expand Down

0 comments on commit bfe839b

Please sign in to comment.