Skip to content

Commit b163712

Browse files
committed
Merge branch 'translation'
2 parents 0baaf47 + 500c64b commit b163712

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1180
-248
lines changed

Auditor/HTMLCSAuditor.js

Lines changed: 74 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ _global.HTMLCSAuditor = new function()
151151
var header = _doc.createElement('div');
152152
header.className = _prefix + 'header';
153153
header.innerHTML = 'HTML_CodeSniffer by Squiz';
154-
header.setAttribute('title', 'Using standard ' + standard);
154+
header.setAttribute('title', _global.HTMLCS.getTranslation("auditor_using_standard") + standard);
155155

156156
var dragging = false;
157157
var prevX = 0;
@@ -202,7 +202,7 @@ _global.HTMLCSAuditor = new function()
202202

203203
var closeIcon = _doc.createElement('div');
204204
closeIcon.className = _prefix + 'close';
205-
closeIcon.setAttribute('title', 'Close');
205+
closeIcon.setAttribute('title', _global.HTMLCS.getTranslation("auditor_close"));
206206
closeIcon.onmousedown = function() {
207207
self.close.call(self);
208208
}
@@ -237,25 +237,25 @@ _global.HTMLCSAuditor = new function()
237237
var divider = ', &#160;<span class="' + _prefix + 'divider"></span>';
238238

239239
if (errors > 0) {
240-
var typeName = 'Errors';
240+
var typeName = _global.HTMLCS.getTranslation("auditor_errors");
241241
if (errors === 1) {
242-
typeName = 'Error';
242+
typeName = _global.HTMLCS.getTranslation("auditor_error");
243243
}
244244
leftContents.push('<strong>' + errors + '</strong> ' + typeName);
245245
}
246246

247247
if (warnings > 0) {
248-
var typeName = 'Warnings';
248+
var typeName = _global.HTMLCS.getTranslation("auditor_warnings");
249249
if (warnings === 1) {
250-
typeName = 'Warning';
250+
typeName = _global.HTMLCS.getTranslation("auditor_warning");
251251
}
252252
leftContents.push('<strong>' + warnings + '</strong> ' + typeName);
253253
}
254254

255255
if (notices > 0) {
256-
var typeName = 'Notices';
256+
var typeName = _global.HTMLCS.getTranslation("auditor_notices");
257257
if (notices === 1) {
258-
typeName = 'Notice';
258+
typeName = _global.HTMLCS.getTranslation("auditor_notice");
259259
}
260260
leftContents.push('<strong>' + notices + '</strong> ' + typeName);
261261
}
@@ -325,7 +325,7 @@ _global.HTMLCSAuditor = new function()
325325
lineageHomeLink.href = 'javascript:';
326326

327327
var lineageHomeSpan = _doc.createElement('span');
328-
lineageHomeSpan.innerHTML = 'Home';
328+
lineageHomeSpan.innerHTML = _global.HTMLCS.getTranslation("auditor_home");
329329
lineageHomeLink.appendChild(lineageHomeSpan);
330330

331331
lineageHomeLink.onmousedown = function() {
@@ -339,8 +339,8 @@ _global.HTMLCSAuditor = new function()
339339
var lineageReportLink = _doc.createElement('a');
340340
lineageReportLink.className = _prefix + 'lineage-link';
341341
lineageReportLink.href = 'javascript:';
342-
lineageReportLink.innerHTML = 'Report';
343-
lineageReportLink.setAttribute('title', 'Back to Report');
342+
lineageReportLink.innerHTML = _global.HTMLCS.getTranslation("auditor_report");
343+
lineageReportLink.setAttribute('title', _global.HTMLCS.getTranslation("auditor_back_to_report"));
344344

345345
lineageReportLink.onmousedown = function() {
346346
var list = _doc.querySelectorAll('.HTMLCS-inner-wrapper')[0];
@@ -355,7 +355,7 @@ _global.HTMLCSAuditor = new function()
355355
// Issue Count item.
356356
var lineageTotalsItem = _doc.createElement('li');
357357
lineageTotalsItem.className = _prefix + 'lineage-item';
358-
lineageTotalsItem.innerHTML = 'Issue ' + issue + ' of ' + totalIssues;
358+
lineageTotalsItem.innerHTML = _global.HTMLCS.getTranslation("auditor_issue") + ' ' + issue + ' ' + _global.HTMLCS.getTranslation("auditor_of") + ' ' + totalIssues;
359359

360360
lineageHomeItem.appendChild(lineageHomeLink);
361361
lineageReportItem.appendChild(lineageReportLink);
@@ -367,7 +367,7 @@ _global.HTMLCSAuditor = new function()
367367
var buttonGroup = _doc.createElement('div');
368368
buttonGroup.className = _prefix + 'button-group';
369369

370-
var prevButton = buildSummaryButton(_prefix + 'button-previous-issue', 'previous', 'Previous Issue', function(target) {
370+
var prevButton = buildSummaryButton(_prefix + 'button-previous-issue', 'previous', _global.HTMLCS.getTranslation("auditor_previous_issue"), function(target) {
371371
var newIssue = Number(issue) - 1;
372372

373373
if (newIssue >= 1) {
@@ -383,7 +383,7 @@ _global.HTMLCSAuditor = new function()
383383
}//end if
384384
});
385385

386-
var nextButton = buildSummaryButton(_prefix + 'button-next-issue', 'next', 'Next Issue', function(target) {
386+
var nextButton = buildSummaryButton(_prefix + 'button-next-issue', 'next', _global.HTMLCS.getTranslation("auditor_next_issue"), function(target) {
387387
var newIssue = Number(issue) + 1;
388388

389389
if (newIssue <= _messages.length) {
@@ -481,7 +481,7 @@ _global.HTMLCSAuditor = new function()
481481
useStandardDiv.id = _prefix + 'settings-use-standard';
482482

483483
var useStandardLabel = _doc.createElement('label');
484-
useStandardLabel.innerHTML = 'Standards:';
484+
useStandardLabel.innerHTML = _global.HTMLCS.getTranslation("auditor_standards") + ':';
485485
useStandardLabel.setAttribute('for', _prefix + 'settings-use-standard-select');
486486

487487
var useStandardSelect = _doc.createElement('select');
@@ -511,11 +511,11 @@ _global.HTMLCSAuditor = new function()
511511

512512
var issueCountHelpDiv = _doc.createElement('div');
513513
issueCountHelpDiv.id = _prefix + 'settings-issue-count-help';
514-
issueCountHelpDiv.innerHTML = 'Select the types of issues to include in the report';
514+
issueCountHelpDiv.innerHTML = _global.HTMLCS.getTranslation("auditor_select_types");
515515

516516
var viewReportDiv = _doc.createElement('div');
517517
viewReportDiv.id = _prefix + 'settings-view-report';
518-
viewReportDiv.innerHTML = 'View Report';
518+
viewReportDiv.innerHTML = _global.HTMLCS.getTranslation("auditor_view_report");
519519

520520
viewReportDiv.onclick = function() {
521521
if (/disabled/.test(this.className) === false) {
@@ -563,15 +563,33 @@ _global.HTMLCSAuditor = new function()
563563
var msgCount = levels[level];
564564
var levelDiv = _doc.createElement('div');
565565
levelDiv.className = _prefix + 'issue-tile ' + _prefix + level.toLowerCase();
566-
566+
var levelName = null;
567567
var levelCountDiv = _doc.createElement('div');
568568
levelCountDiv.className = 'HTMLCS-tile-text';
569569

570-
var content = '<strong>' + msgCount + '</strong> ' + level.substr(0, 1).toUpperCase() + level.substr(1);
571-
if (msgCount !== 1) {
572-
content += 's';
570+
if(level == "error") {
571+
levelName = _global.HTMLCS.getTranslation('auditor_error');
572+
if (msgCount !== 1) {
573+
levelName = _global.HTMLCS.getTranslation('auditor_errors');
574+
}
575+
}
576+
577+
if(level == "warning") {
578+
levelName = _global.HTMLCS.getTranslation('auditor_warning');
579+
if (msgCount !== 1) {
580+
levelName = _global.HTMLCS.getTranslation('auditor_warnings');
581+
}
573582
}
574583

584+
if(level == "notice") {
585+
levelName = _global.HTMLCS.getTranslation('auditor_notice');
586+
if (msgCount !== 1) {
587+
levelName = _global.HTMLCS.getTranslation('auditor_notices');
588+
}
589+
}
590+
var content = '<strong>' + msgCount + '</strong> ' + levelName;
591+
592+
575593
levelCountDiv.innerHTML = content;
576594

577595
if (_options.show === undefined) {
@@ -796,18 +814,18 @@ _global.HTMLCSAuditor = new function()
796814

797815
var msgElementSourceInner = _doc.createElement('div');
798816
msgElementSourceInner.className = _prefix + 'issue-source-inner-u2p';
799-
var msg = 'Unable to point to the element associated with this issue.';
817+
var msg = _global.HTMLCS.getTranslation('auditor_unable_to_point');
800818

801819
if (message.element.ownerDocument === null) {
802-
msg = 'Unable to point to this issue, as it relates to the entire document.';
820+
msg = _global.HTMLCS.getTranslation('auditor_unable_to_point_removed');
803821
} else {
804822
var body = message.element.ownerDocument.getElementsByTagName('body')[0];
805823
if (HTMLCS.util.isInDocument(message.element) === false) {
806-
msg += 'Unable to point to this element as it has been removed from the document since the report was generated.';
824+
msg += _global.HTMLCS.getTranslation('auditor_unable_to_point_entire');
807825
} else if (HTMLCS.util.contains(body, message.element) === false) {
808-
msg = 'Unable to point to this element because it is located outside the document\'s body element.';
826+
msg = _global.HTMLCS.getTranslation('auditor_unable_to_point_outside');
809827
} else {
810-
msg += 'Unable to point to this element because it is hidden from view, or does not have a visual representation.';
828+
msg += _global.HTMLCS.getTranslation('auditor_unable_to_point_outside');
811829
}
812830
}
813831

@@ -837,9 +855,9 @@ _global.HTMLCSAuditor = new function()
837855
msgElementSourceHeader.className = _prefix + 'issue-source-header';
838856

839857
var msgSourceHeaderText = _doc.createElement('strong');
840-
msgSourceHeaderText.innerHTML = 'Code Snippet';
858+
msgSourceHeaderText.innerHTML = _global.HTMLCS.getTranslation("auditor_code_snippet");
841859

842-
var btnPointTo = buildSummaryButton(_prefix + 'button-point-to-element-' + id, 'pointer', 'Point to Element', function() {
860+
var btnPointTo = buildSummaryButton(_prefix + 'button-point-to-element-' + id, 'pointer', _global.HTMLCS.getTranslation("auditor_point_to_element"), function() {
843861
self.pointToElement(message.element);
844862
});
845863

@@ -958,7 +976,8 @@ _global.HTMLCSAuditor = new function()
958976

959977
var pageNum = _doc.createElement('span');
960978
pageNum.className = _prefix + 'page-number';
961-
pageNum.innerHTML = 'Page ' + page + ' of ' + totalPages;
979+
// pageNum.innerHTML = 'Page ' + page + ' of ' + totalPages;
980+
pageNum.innerHTML = _global.HTMLCS.getTranslation("auditor_issue") + ' ' + page + ' ' + _global.HTMLCS.getTranslation("auditor_of") + ' ' + totalPages;
962981
navDiv.appendChild(pageNum);
963982

964983
var next = _doc.createElement('span');
@@ -984,7 +1003,7 @@ _global.HTMLCSAuditor = new function()
9841003
}
9851004

9861005
pageNum.innerHTML = '';
987-
pageNum.appendChild(document.createTextNode('Page ' + _page + ' of ' + totalPages));
1006+
pageNum.appendChild(document.createTextNode(_global.HTMLCS.getTranslation("auditor_issue") + ' ' + _page + ' ' + _global.HTMLCS.getTranslation("auditor_of") + ' ' + totalPages));
9881007

9891008
var issueList = _doc.querySelectorAll('.HTMLCS-issue-list')[0];
9901009
issueList.style.marginLeft = ((_page - 1) * -300) + 'px';
@@ -1003,7 +1022,7 @@ _global.HTMLCSAuditor = new function()
10031022
}
10041023

10051024
pageNum.innerHTML = '';
1006-
pageNum.appendChild(document.createTextNode('Page ' + _page + ' of ' + totalPages));
1025+
pageNum.appendChild(document.createTextNode(_global.HTMLCS.getTranslation("auditor_issue") + ' ' + _page + ' ' + _global.HTMLCS.getTranslation("auditor_of") + ' ' + totalPages));
10071026

10081027
var issueList = _doc.querySelectorAll('.HTMLCS-issue-list')[0];
10091028
issueList.style.marginLeft = ((_page - 1) * -300) + 'px';
@@ -1354,6 +1373,25 @@ _global.HTMLCSAuditor = new function()
13541373
return _doc;
13551374
};
13561375

1376+
/**
1377+
* Get the current document's language.
1378+
*
1379+
* @return string
1380+
*/
1381+
this.getDocumentLanguage = function() {
1382+
var defaultLang = 'en';
1383+
var doc = this.getOwnerDocument();
1384+
var html = doc.getElementsByTagName('html')[0];
1385+
if (html) {
1386+
var lang = html.getAttribute('lang');
1387+
if (lang) {
1388+
return lang;
1389+
}
1390+
}
1391+
1392+
return defaultLang;
1393+
};
1394+
13571395
/**
13581396
* Run HTML_CodeSniffer and place the results in the auditor.
13591397
*
@@ -1439,6 +1477,10 @@ _global.HTMLCSAuditor = new function()
14391477
_options.path = './';
14401478
}
14411479

1480+
if (!options.lang) {
1481+
_options.lang = this.getDocumentLanguage();
1482+
}
1483+
14421484
if (_options.includeCss === undefined) {
14431485
_options.includeCss = true;
14441486
}
@@ -1540,7 +1582,7 @@ _global.HTMLCSAuditor = new function()
15401582
} else {
15411583
_processSource(standard, sources);
15421584
}
1543-
});
1585+
}, function() {}, options.lang);
15441586
};
15451587

15461588
_processSource(standard, _sources.concat([]));

Contrib/Build/header-bookmarklet.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@
1616
root[prop] = exports[prop];
1717
}
1818
}(this, function () {
19-
var _global = {}
19+
var _global = {
20+
translation: {}
21+
};

Contrib/Build/umd-header.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,6 @@
2222
}
2323
}
2424
}(this, function () {
25-
var _global = {}
25+
var _global = {
26+
translation: {}
27+
};

Contrib/PhantomJS/HTMLCS_Run.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ if (system.args.length < 3 || system.args.length > 4) {
9090
}
9191

9292
console.log('');
93-
console.log('Errors: ' + messages['ERROR'].length + ', Warnings: ' + messages['WARNING'].length +
94-
', Notices: ' + messages['NOTICE'].length);
93+
console.log(_global.HTMLCS.getTranslation("auditor_errors") + ': ' + messages['ERROR'].length + ', ' + _global.HTMLCS.getTranslation("auditor_warnings") + ': ' + messages['WARNING'].length +
94+
', ' + _global.HTMLCS.getTranslation("auditor_notices") + ': ' + messages['NOTICE'].length);
9595
cb();
9696
}
9797

Contrib/PhantomJS/runner.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ var HTMLCS_RUNNER = _global.HTMLCS_RUNNER = new function() {
1919
}, function() {
2020
console.log('Something in HTML_CodeSniffer failed to parse. Cannot run.');
2121
console.log('done');
22-
});
22+
}, 'en');
2323
};
2424

2525
this.output = function(msg) {
2626
// Simple output for now.
2727
var typeName = 'UNKNOWN';
2828
switch (msg.type) {
2929
case HTMLCS.ERROR:
30-
typeName = 'ERROR';
30+
typeName = _global.HTMLCS.getTranslation("auditor_error");
3131
break;
3232

3333
case HTMLCS.WARNING:
34-
typeName = 'WARNING';
34+
typeName = _global.HTMLCS.getTranslation("auditor_warning");
3535
break;
3636

3737
case HTMLCS.NOTICE:
38-
typeName = 'NOTICE';
38+
typeName = _global.HTMLCS.getTranslation("auditor_notice");
3939
break;
4040
}//end switch
4141

Contrib/PhantomJS/test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
let data = '';
2+
3+
process.stdin.resume();
4+
process.stdin.setEncoding('utf8');
5+
6+
process.stdin.on('data', function(chunk) {
7+
data += chunk;
8+
});
9+
10+
function toHTML(obj) {
11+
return `<tr>
12+
<td>${obj.code}</td>
13+
<td>${obj.msg}</td>
14+
</tr>`;
15+
}
16+
17+
process.stdin.on('end', function() {
18+
let issues = JSON.parse(data);
19+
let html = `<table>
20+
<thead>
21+
<tr>
22+
<th>Code</th>
23+
<th>Message<th>
24+
</tr>
25+
</thead>
26+
<tbody>
27+
${issues.map(toHTML).join('')}
28+
</tbody>
29+
</table>`;
30+
console.log(html);
31+
});

Contrib/Testing/HTMLCS_Test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ if (system.args.length < 2 || system.args.length > 2) {
9090
assertion = testData.assertions[assert];
9191
for (var i = 0; i < messages.length; i++) {
9292
thisMsg = messages[i];
93-
if (assertion.level === thisMsg[0]) {
93+
if (assertion.level.toLowerCase() === thisMsg[0].toLowerCase()) {
9494
if (assertion.code.test(thisMsg[1]) === true) {
9595
if (assertion.id === thisMsg[3]) {
9696
assertion.triggered = true;

0 commit comments

Comments
 (0)