Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - Localization / l10n #223

Merged
merged 75 commits into from
May 5, 2019
Merged
Show file tree
Hide file tree
Changes from 74 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
5f30135
Axe Core upgrade to 3.2.2, breaking changes, work in progress (end go…
danielweck Apr 11, 2019
82afe82
ARIA DPUB now in Axe Core
danielweck Apr 11, 2019
c92f2f2
Puppeteer utility to inject script content
danielweck Apr 11, 2019
77c5ba4
localized Axe (JSON l10n data passed from NodeJS process into web bro…
danielweck Apr 11, 2019
3c99cb6
further massaging of the Axe JSON report (preservation of info from r…
danielweck Apr 11, 2019
a60f921
minor: debug traces
danielweck Apr 11, 2019
34f7407
i18next to localize like AceGUI, CLI and HTTP configs, incomplete l10…
danielweck Apr 11, 2019
83e68bf
added French translation, tested it with Schema.org metadata failure …
danielweck Apr 11, 2019
7a0b1ce
checker-epub.js localized
danielweck Apr 25, 2019
d6ad7ba
ace-report localized
danielweck Apr 25, 2019
330ea12
ace-report-axe localized (-ish)
danielweck Apr 25, 2019
f0a70f0
removed debug trace
danielweck Apr 25, 2019
c915eab
localized Ace-Axe script (executes in webview / Chromium)
danielweck Apr 25, 2019
b22571d
fixed incorrect require import path
danielweck Apr 25, 2019
b082458
added missing NPM package
danielweck Apr 25, 2019
267a1e0
updated CLI test snapshots and added new lang param to doc too
danielweck Apr 25, 2019
23c7acf
yarn upgrade i18next
danielweck Apr 26, 2019
ddcc3d7
i18next concurrent instances
danielweck Apr 26, 2019
5ed79b9
localize a few more strings (Ace report)
danielweck Apr 26, 2019
07e21fe
fixed i18n typo
danielweck Apr 26, 2019
63734a9
i18next interpolation NOT escapeValue
danielweck Apr 26, 2019
acab658
fixed report language (i18next now concurrent instances instead of si…
danielweck Apr 26, 2019
9de38e8
Handlebar HTML template localization in progress...
danielweck Apr 26, 2019
625a9c9
HTML template l10n ...
danielweck Apr 26, 2019
ba62cbc
severity translated
danielweck Apr 26, 2019
b41e05a
added logger init (optional) in ace() main function, not needed by CL…
danielweck Apr 27, 2019
5dc0860
fixed erroneous dupicate HTML ID in template
danielweck Apr 27, 2019
0061d62
futher HTML report template localization (+ fixed fileTitle typo whi…
danielweck Apr 27, 2019
cc28030
finished HTML report localization (handlebar template), but table con…
danielweck Apr 27, 2019
85d2a4c
jQuery DataTable localization
danielweck Apr 27, 2019
45ccdb3
Merge branch 'master' into feature/l10n
danielweck Apr 30, 2019
3d2071f
centralized localizer package
danielweck Apr 30, 2019
4898c9e
added missing package refs
danielweck Apr 30, 2019
3a4feb6
i18next missingKeyHandler requires saveMissing
danielweck Apr 30, 2019
44a971b
i18next API changes
danielweck Apr 30, 2019
7cd1dc0
typo in lang resource
danielweck Apr 30, 2019
4ffb44f
Merge branch 'master' into feature/l10n
danielweck May 3, 2019
8868c8c
fixed localization typo (code)
danielweck May 3, 2019
c9268f9
fixed test snapshots
danielweck May 3, 2019
ca3da3d
removed unnecessary french param
danielweck May 3, 2019
41c1b84
restored Travis unit tests
danielweck May 3, 2019
cde6d6c
Travis YAML typo
danielweck May 3, 2019
3945978
version bumps in modified packages
danielweck May 3, 2019
78962b6
Merge branch 'master' into feature/l10n
danielweck May 4, 2019
756f3fb
removed comment, see https://github.com/daisy/ace/pull/223#discussion…
danielweck May 5, 2019
aa9fd5d
FR fix, see https://github.com/daisy/ace/pull/223#discussion_r281001739
danielweck May 5, 2019
3bd66d4
FR fix, see https://github.com/daisy/ace/pull/223#discussion_r281001767
danielweck May 5, 2019
7bd1db4
FR fix, see https://github.com/daisy/ace/pull/223#discussion_r281002979
danielweck May 5, 2019
e9dfe2f
FR fix, see https://github.com/daisy/ace/pull/223#discussion_r281001802
danielweck May 5, 2019
6497f0e
FR fix, see https://github.com/daisy/ace/pull/223#discussion_r281001825
danielweck May 5, 2019
a635c4e
FR fix, see https://github.com/daisy/ace/pull/223#discussion_r281001893
danielweck May 5, 2019
6e92917
FR fix, see https://github.com/daisy/ace/pull/223#discussion_r281001914
danielweck May 5, 2019
fa4e2c0
FR fix, see https://github.com/daisy/ace/pull/223#discussion_r281001917
danielweck May 5, 2019
1588a81
FR fix, see https://github.com/daisy/ace/pull/223#discussion_r281001958
danielweck May 5, 2019
e90cf79
FR fix, see https://github.com/daisy/ace/pull/223#discussion_r281001968
danielweck May 5, 2019
5857101
FR fix, see https://github.com/daisy/ace/pull/223#discussion_r281001950
danielweck May 5, 2019
b237c5c
FR fix, see https://github.com/daisy/ace/pull/223#discussion_r281001978
danielweck May 5, 2019
26d03e5
FR fix, see https://github.com/daisy/ace/pull/223#discussion_r281001836
danielweck May 5, 2019
1c1f151
FR fix, see https://github.com/daisy/ace/pull/223#discussion_r281001992
danielweck May 5, 2019
1ca436e
package description, see https://github.com/daisy/ace/pull/223#discus…
danielweck May 5, 2019
d3d0d6d
removed comments see https://github.com/daisy/ace/pull/223#discussion…
danielweck May 5, 2019
7bfd39d
FR fix, see https://github.com/daisy/ace/pull/223#discussion_r281002988
danielweck May 5, 2019
151a3b8
FR fix, see https://github.com/daisy/ace/pull/223#discussion_r281003090
danielweck May 5, 2019
4a092bd
FR fix, see https://github.com/daisy/ace/pull/223#discussion_r281003112
danielweck May 5, 2019
7db0ea2
FR fix, see https://github.com/daisy/ace/pull/223#discussion_r281003055
danielweck May 5, 2019
664b9f5
regexp trim, see https://github.com/daisy/ace/pull/223#discussion_r28…
danielweck May 5, 2019
8d5dc74
FR fix, see https://github.com/daisy/ace/pull/223#discussion_r281002693
danielweck May 5, 2019
cf870ee
FR fix, see https://github.com/daisy/ace/pull/223#discussion_r281002714
danielweck May 5, 2019
efcdef0
FR fix, see https://github.com/daisy/ace/pull/223#discussion_r281002771
danielweck May 5, 2019
8a71a4e
FR fix, see https://github.com/daisy/ace/pull/223#discussion_r281002845
danielweck May 5, 2019
83e3ea9
FR fix, see https://github.com/daisy/ace/pull/223#discussion_r281002878
danielweck May 5, 2019
8cf0ad9
FR fix, see https://github.com/daisy/ace/pull/223#discussion_r281002916
danielweck May 5, 2019
a6bea68
FR fix, https://github.com/daisy/ace/pull/223#discussion_r281002924
danielweck May 5, 2019
0b94c2e
code cleanup for default JSON locale export (module export), see http…
danielweck May 5, 2019
58e7d6c
FR fix https://github.com/daisy/ace/pull/223#discussion_r281033199
danielweck May 5, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/ace-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@daisy/ace-cli",
"version": "1.0.3",
"version": "1.0.4",
"description": "Ace by DAISY, an Accessibility Checker for EPUB",
"author": {
"name": "DAISY developers",
Expand Down
5 changes: 4 additions & 1 deletion packages/ace-cli/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const cli = meow({
-V, --verbose display verbose output
-s, --silent do not display any output

-l, --lang <language> language code for localized messages (e.g. "fr"), default is "en"
Examples
$ ace -o out ~/Documents/book.epub
`,
Expand All @@ -46,9 +47,10 @@ version: pkg.version
t: 'tempdir',
v: 'version',
V: 'verbose',
l: 'lang',
},
boolean: ['force', 'verbose', 'silent', 'subdir'],
string: ['outdir', 'tempdir'],
string: ['outdir', 'tempdir', 'lang'],
});

function sleep(ms) {
Expand Down Expand Up @@ -102,6 +104,7 @@ ${overrides.map(file => ` - ${file}`).join('\n')}
verbose: cli.flags.verbose,
silent: cli.flags.silent,
jobId: '',
lang: cli.flags.lang,
})
.then((jobData) => {
var reportJson = jobData[1];
Expand Down
4 changes: 3 additions & 1 deletion packages/ace-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@daisy/ace-core",
"version": "1.0.3",
"version": "1.0.4",
"description": "Core library for Ace",
"author": {
"name": "DAISY developers",
Expand All @@ -18,6 +18,8 @@
"license": "MIT",
"main": "lib/index.js",
"dependencies": {
"@daisy/ace-localize": "^1.0.0",
"@daisy/ace-logger": "^1.0.1",
"@daisy/ace-meta": "^1.0.3",
"@daisy/ace-report": "^1.0.1",
"@daisy/ace-report-axe": "^1.0.1",
Expand Down
50 changes: 46 additions & 4 deletions packages/ace-core/src/checker/checker-chromium.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const winston = require('winston');
const axe2ace = require('@daisy/ace-report-axe');
const utils = require('@daisy/puppeteer-utils');

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

tmp.setGracefulCleanup();

const scripts = [
Expand All @@ -23,7 +25,7 @@ const scripts = [
require.resolve('../scripts/ace-extraction.js'),
];

async function checkSingle(spineItem, epub, browser) {
async function checkSingle(spineItem, epub, browser, lang) {
winston.verbose(`- Processing ${spineItem.relpath}`);
try {
let url = spineItem.url;
Expand All @@ -42,6 +44,46 @@ async function checkSingle(spineItem, epub, browser) {

const page = await browser.newPage();
await page.goto(url);

let localePath = "";
try {
winston.info(`- Axe locale: [${lang}]`);

// https://github.com/dequelabs/axe-core#localization
// https://github.com/dequelabs/axe-core/tree/develop/locales

if (lang && lang !== "en" && lang.indexOf("en-") !== 0) { // default English built into Axe source code
danielweck marked this conversation as resolved.
Show resolved Hide resolved
localePath = path.resolve(require.resolve('axe-core'), `../locales/${lang}.json`);
if (fs.existsSync(localePath)) {
const localeStr = fs.readFileSync(localePath, { encoding: "utf8" });
const localeScript = `window.__axeLocale__=${localeStr};`;
await utils.addScriptContents([localeScript], page);
} else {
winston.info(`- Axe locale missing? [${lang}] => ${localePath}`);
}
}

let localizedScript = "";
const rawJson = getRawResourcesForCurrentLanguage();

["axecheck", "axerule"].forEach((checkOrRule) => {
const checkOrRuleKeys = Object.keys(rawJson[checkOrRule]);
for (const checkOrRuleKey of checkOrRuleKeys) {
const msgs = Object.keys(rawJson[checkOrRule][checkOrRuleKey]);
for (const msg of msgs) {
const k = `__aceLocalize__${checkOrRule}_${checkOrRuleKey}_${msg}`;
localizedScript += `window['${k}']="${rawJson[checkOrRule][checkOrRuleKey][msg]}";\n`;
}
}
});
await utils.addScriptContents([localizedScript], page);

} catch (err) {
console.log(err);
winston.verbose(err);
winston.info(`- Axe locale problem? [${lang}] => ${localePath}`);
}

await utils.addScripts(scripts, page);

const results = await page.evaluate(() => new Promise((resolve, reject) => {
Expand All @@ -57,7 +99,7 @@ async function checkSingle(spineItem, epub, browser) {
await page.close();

// Post-process results
results.assertions = (results.axe != null) ? axe2ace.axe2ace(spineItem, results.axe) : [];
results.assertions = (results.axe != null) ? axe2ace.axe2ace(spineItem, results.axe, lang) : [];
danielweck marked this conversation as resolved.
Show resolved Hide resolved
delete results.axe;
winston.info(`- ${spineItem.relpath}: ${
(results.assertions && results.assertions.assertions.length > 0)
Expand Down Expand Up @@ -97,14 +139,14 @@ async function checkSingle(spineItem, epub, browser) {
}
}

module.exports.check = async (epub) => {
module.exports.check = async (epub, lang) => {
const args = [];
if (os.platform() !== 'win32' && os.platform() !== 'darwin') {
args.push('--no-sandbox')
}
const browser = await puppeteer.launch({ args });
winston.info('Checking documents...');
return pMap(epub.contentDocs, doc => checkSingle(doc, epub, browser), { concurrency: 4 })
return pMap(epub.contentDocs, doc => checkSingle(doc, epub, browser, lang), { concurrency: 4 })
.then(async (results) => {
await browser.close();
return results;
Expand Down
28 changes: 15 additions & 13 deletions packages/ace-core/src/checker/checker-epub.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
const builders = require('@daisy/ace-report').builders;
const winston = require('winston');

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

const ASSERTED_BY = 'Ace';
const MODE = 'automatic';
const KB_BASE = 'http://kb.daisy.org/publishing/';
Expand Down Expand Up @@ -42,11 +44,11 @@ function newMetadataAssertion(name, impact = 'serious') {
return newViolation({
impact,
title: `metadata-${name.toLowerCase().replace(':', '-')}`,
testDesc: `Ensures a '${name}' metadata is present`,
resDesc: `Add a '${name}' metadata property to the Package Document`,
testDesc: localize("checkepub.metadataviolation.testdesc", { name, interpolation: { escapeValue: false } }),
resDesc: localize("checkepub.metadataviolation.resdesc", { name, interpolation: { escapeValue: false } }),
kbPath: 'docs/metadata/schema-org.html',
kbTitle: 'Schema.org Accessibility Metadata',
ruleDesc: `Publications must declare the '${name}' metadata`
kbTitle: localize("checkepub.metadataviolation.kbtitle"),
ruleDesc: localize("checkepub.metadataviolation.ruledesc", { name, interpolation: { escapeValue: false } })
});
}

Expand All @@ -70,11 +72,11 @@ function checkTitle(assertions, epub) {
if (title === '') {
assertions.withAssertions(newViolation({
title: 'epub-title',
testDesc: 'Ensures the EPUB has a title',
resDesc: 'Add a \'dc:title\' metadata property to the Package Document',
testDesc: localize("checkepub.titleviolation.testdesc"),
resDesc: localize("checkepub.titleviolation.resdesc"),
kbPath: '',
kbTitle: 'EPUB Title',
ruleDesc: 'Publications must have a title',
kbTitle: localize("checkepub.titleviolation.kbtitle"),
ruleDesc: localize("checkepub.titleviolation.ruledesc")
}));
}
}
Expand All @@ -85,11 +87,11 @@ function checkPageSource(assertion, epub) {
|| epub.metadata['dc:source'].toString() === '')) {
assertion.withAssertions(newViolation({
title: 'epub-pagesource',
testDesc: 'Ensures the source of page breaks is identified',
resDesc: 'Add a \'dc:source\' metadata property to the Package Document',
testDesc: localize("checkepub.pagesourceviolation.testdesc"),
resDesc: localize("checkepub.pagesourceviolation.resdesc"),
kbPath: 'docs/navigation/pagelist.html',
kbTitle: 'Page Navigation',
ruleDesc: 'Publications with page breaks must declare the \'dc:source\' metadata',
kbTitle: localize("checkepub.pagesourceviolation.kbtitle"),
ruleDesc: localize("checkepub.pagesourceviolation.ruledesc")
}));
}
}
Expand Down Expand Up @@ -121,7 +123,7 @@ function check(epub, report) {
hasBindings: epub.hasBindings,
hasSVGContentDocuments: epub.hasSVGContentDocuments,
});

winston.info(`- ${epub.packageDoc.src}: ${
(builtAssertions.assertions && builtAssertions.assertions.length > 0)
? builtAssertions.assertions.length
Expand Down
4 changes: 2 additions & 2 deletions packages/ace-core/src/checker/checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ function consolidate(results, report) {
return report;
}

module.exports.check = function check(epub, report) {
module.exports.check = function check(epub, report,lang) {
return epubChecker.check(epub, report)
.then(() => htmlChecker.check(epub))
.then(() => htmlChecker.check(epub, lang))
.then(results => consolidate(results, report));
};
15 changes: 13 additions & 2 deletions packages/ace-core/src/core/ace.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,21 @@ const pkg = require('@daisy/ace-meta/package');
const EPUB = require('@daisy/epub-utils').EPUB;
const Report = require('@daisy/ace-report').Report;
const checker = require('../checker/checker.js');
const { setCurrentLanguage } = require('../l10n/localize').localizer;

const logger = require('@daisy/ace-logger');

tmp.setGracefulCleanup();

module.exports = function ace(epubPath, options) {
if (options.lang) {
setCurrentLanguage(options.lang);
}

if (options.initLogger) {
logger.initLogger({ verbose: options.verbose, silent: options.silent });
}

return new Promise((resolve, reject) => {
// the jobid option just gets returned in the resolve/reject
// so the calling function can track which job finished
Expand Down Expand Up @@ -56,9 +67,9 @@ module.exports = function ace(epubPath, options) {
epub.extract()
.then(() => epub.parse())
// initialize the report
.then(() => new Report(epub, options.outdir))
.then(() => new Report(epub, options.outdir, options.lang))
// Check each Content Doc
.then(report => checker.check(epub, report))
.then(report => checker.check(epub, report, options.lang))
// Process the Results
.then((report) => {
if (options.outdir === undefined) {
Expand Down
37 changes: 37 additions & 0 deletions packages/ace-core/src/l10n/locales/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"checkepub": {
"metadataviolation": {
"testdesc": "Ensures a '{{name}}' metadata is present",
"resdesc": "Add a '{{name}}' metadata property to the Package Document",
"ruledesc": "Publications must declare the '{{name}}' metadata",
"kbtitle": "Schema.org Accessibility Metadata"
},
"titleviolation": {
"testdesc": "Ensures the EPUB has a title",
"resdesc": "Add a 'dc:title' metadata property to the Package Document",
"ruledesc": "Publications must have a title",
"kbtitle": "EPUB Title"
},
"pagesourceviolation": {
"testdesc": "Ensures the source of page breaks is identified",
"resdesc": "Add a 'dc:source' metadata property to the Package Document",
"ruledesc": "Publications with page breaks must declare the 'dc:source' metadata",
"kbtitle": "Page Navigation"
}
},
"axecheck": {
"matching-aria-role": {
"pass": "Element has an ARIA role matching its epub:type",
"fail": "Element has no ARIA role matching its epub:type"
}
},
"axerule": {
"pagebreak-label": {
"desc": "Ensure page markers have an accessible label"
},
"epub-type-has-matching-role": {
"help": "ARIA role should be used in addition to epub:type",
"desc": "Ensure the element has an ARIA role matching its epub:type"
}
}
}
37 changes: 37 additions & 0 deletions packages/ace-core/src/l10n/locales/fr.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"checkepub": {
"metadataviolation": {
"testdesc": "Vérifie que la métadonnée '{{name}}' est présente",
"resdesc": "Ajouter la métadonnée '{{name}}' au Document de Package",
"ruledesc": "Toute publication doit déclarer la métadonnée '{{name}}'",
"kbtitle": "Métadonnées d'accessibilité Schema.org"
},
"titleviolation": {
"testdesc": "Vérifie que le EPUB a un titre",
"resdesc": "Ajouter la métadonnée 'dc:title' au Document de Package",
"ruledesc": "Une publication doit avoir un titre",
"kbtitle": "Titre de l’EPUB"
},
"pagesourceviolation": {
"testdesc": "Vérifie que la source des sauts de page est identifiée",
"resdesc": "Ajouter la métadonnée 'dc:source' au Document de Package",
"ruledesc": "Une publication avec des sauts de page doit déclarer la métadonnée 'dc:source'",
"kbtitle": "Navigation par page"
}
},
"axecheck": {
"matching-aria-role": {
"pass": "L’élément a un rôle ARIA correspondant à son epub:type",
"fail": "L’élément n’a pas de rôle ARIA correspondant à son epub:type"
}
},
"axerule": {
"pagebreak-label": {
"desc": "Vérifie que les sauts de page ont un label accessible"
},
"epub-type-has-matching-role": {
"help": "Un rôle ARIA devrait être spécifié en plus de l’epub:type",
"desc": "Vérifie qu’un élément a un rôle ARIA correspondant à son epub:type"
}
}
}
16 changes: 16 additions & 0 deletions packages/ace-core/src/l10n/localize.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { newLocalizer } = require('@daisy/ace-localize');

const enJson = require("./locales/en.json");
const frJson = require("./locales/fr.json");

export const localizer = newLocalizer({
en: {
name: "English",
danielweck marked this conversation as resolved.
Show resolved Hide resolved
default: true,
translation: enJson,
},
fr: {
name: "Français",
translation: frJson,
},
});
Loading