@@ -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' , _global . translation [ "auditor_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' , _global . translation [ "auditor_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 = ',  <span class="' + _prefix + 'divider"></span>' ;
238238
239239 if ( errors > 0 ) {
240- var typeName = _global . translation [ "auditor_errors" ] ;
240+ var typeName = _global . HTMLCS . getTranslation ( "auditor_errors" ) ;
241241 if ( errors === 1 ) {
242- typeName = _global . translation [ "auditor_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 = _global . translation [ "auditor_warnings" ] ;
248+ var typeName = _global . HTMLCS . getTranslation ( "auditor_warnings" ) ;
249249 if ( warnings === 1 ) {
250- typeName = _global . translation [ "auditor_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 = _global . translation [ "auditor_notices" ] ;
256+ var typeName = _global . HTMLCS . getTranslation ( "auditor_notices" ) ;
257257 if ( notices === 1 ) {
258- typeName = _global . translation [ "auditor_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 = _global . translation [ "auditor_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 = _global . translation [ "auditor_report" ] ;
343- lineageReportLink . setAttribute ( 'title' , _global . translation [ "auditor_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 = _global . translation [ "auditor_issue" ] + ' ' + issue + ' ' + _global . translation [ "auditor_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' , _global . translation [ "auditor_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' , _global . translation [ "auditor_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 = _global . translation [ "auditor_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 = _global . translation [ "auditor_select_types" ] ;
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 = _global . translation [ "auditor_view_report" ] ;
518+ viewReportDiv . innerHTML = _global . HTMLCS . getTranslation ( "auditor_view_report" ) ;
519519
520520 viewReportDiv . onclick = function ( ) {
521521 if ( / d i s a b l e d / . test ( this . className ) === false ) {
@@ -568,23 +568,23 @@ _global.HTMLCSAuditor = new function()
568568 levelCountDiv . className = 'HTMLCS-tile-text' ;
569569
570570 if ( level == "error" ) {
571- levelName = _global . translation [ 'auditor_error' ] ;
571+ levelName = _global . HTMLCS . getTranslation ( 'auditor_error' ) ;
572572 if ( msgCount !== 1 ) {
573- levelName = _global . translation [ 'auditor_errors' ] ;
573+ levelName = _global . HTMLCS . getTranslation ( 'auditor_errors' ) ;
574574 }
575575 }
576576
577577 if ( level == "warning" ) {
578- levelName = _global . translation [ 'auditor_warning' ] ;
578+ levelName = _global . HTMLCS . getTranslation ( 'auditor_warning' ) ;
579579 if ( msgCount !== 1 ) {
580- levelName = _global . translation [ 'auditor_warnings' ] ;
580+ levelName = _global . HTMLCS . getTranslation ( 'auditor_warnings' ) ;
581581 }
582582 }
583583
584584 if ( level == "notice" ) {
585- levelName = _global . translation [ 'auditor_notice' ] ;
585+ levelName = _global . HTMLCS . getTranslation ( 'auditor_notice' ) ;
586586 if ( msgCount !== 1 ) {
587- levelName = _global . translation [ 'auditor_notices' ] ;
587+ levelName = _global . HTMLCS . getTranslation ( 'auditor_notices' ) ;
588588 }
589589 }
590590 var content = '<strong>' + msgCount + '</strong> ' + levelName ;
@@ -814,18 +814,18 @@ _global.HTMLCSAuditor = new function()
814814
815815 var msgElementSourceInner = _doc . createElement ( 'div' ) ;
816816 msgElementSourceInner . className = _prefix + 'issue-source-inner-u2p' ;
817- var msg = _global . translation [ 'auditor_unable_to_point' ] ;
817+ var msg = _global . HTMLCS . getTranslation ( 'auditor_unable_to_point' ) ;
818818
819819 if ( message . element . ownerDocument === null ) {
820- msg = _global . translation [ 'auditor_unable_to_point_removed' ] ;
820+ msg = _global . HTMLCS . getTranslation ( 'auditor_unable_to_point_removed' ) ;
821821 } else {
822822 var body = message . element . ownerDocument . getElementsByTagName ( 'body' ) [ 0 ] ;
823823 if ( HTMLCS . util . isInDocument ( message . element ) === false ) {
824- msg += _global . translation [ 'auditor_unable_to_point_entire' ] ;
824+ msg += _global . HTMLCS . getTranslation ( 'auditor_unable_to_point_entire' ) ;
825825 } else if ( HTMLCS . util . contains ( body , message . element ) === false ) {
826- msg = _global . translation [ 'auditor_unable_to_point_outside' ] ;
826+ msg = _global . HTMLCS . getTranslation ( 'auditor_unable_to_point_outside' ) ;
827827 } else {
828- msg += _global . translation [ 'auditor_unable_to_point_outside' ] ;
828+ msg += _global . HTMLCS . getTranslation ( 'auditor_unable_to_point_outside' ) ;
829829 }
830830 }
831831
@@ -855,9 +855,9 @@ _global.HTMLCSAuditor = new function()
855855 msgElementSourceHeader . className = _prefix + 'issue-source-header' ;
856856
857857 var msgSourceHeaderText = _doc . createElement ( 'strong' ) ;
858- msgSourceHeaderText . innerHTML = _global . translation [ "auditor_code_snippet" ] ;
858+ msgSourceHeaderText . innerHTML = _global . HTMLCS . getTranslation ( "auditor_code_snippet" ) ;
859859
860- var btnPointTo = buildSummaryButton ( _prefix + 'button-point-to-element-' + id , 'pointer' , _global . translation [ "auditor_point_to_element" ] , function ( ) {
860+ var btnPointTo = buildSummaryButton ( _prefix + 'button-point-to-element-' + id , 'pointer' , _global . HTMLCS . getTranslation ( "auditor_point_to_element" ) , function ( ) {
861861 self . pointToElement ( message . element ) ;
862862 } ) ;
863863
@@ -977,7 +977,7 @@ _global.HTMLCSAuditor = new function()
977977 var pageNum = _doc . createElement ( 'span' ) ;
978978 pageNum . className = _prefix + 'page-number' ;
979979 // pageNum.innerHTML = 'Page ' + page + ' of ' + totalPages;
980- pageNum . innerHTML = _global . translation [ "auditor_issue" ] + ' ' + page + ' ' + _global . translation [ "auditor_of" ] + ' ' + totalPages ;
980+ pageNum . innerHTML = _global . HTMLCS . getTranslation ( "auditor_issue" ) + ' ' + page + ' ' + _global . HTMLCS . getTranslation ( "auditor_of" ) + ' ' + totalPages ;
981981 navDiv . appendChild ( pageNum ) ;
982982
983983 var next = _doc . createElement ( 'span' ) ;
@@ -1003,7 +1003,7 @@ _global.HTMLCSAuditor = new function()
10031003 }
10041004
10051005 pageNum . innerHTML = '' ;
1006- pageNum . appendChild ( document . createTextNode ( _global . translation [ "auditor_issue" ] + ' ' + _page + ' ' + _global . translation [ "auditor_of" ] + ' ' + totalPages ) ) ;
1006+ pageNum . appendChild ( document . createTextNode ( _global . HTMLCS . getTranslation ( "auditor_issue" ) + ' ' + _page + ' ' + _global . HTMLCS . getTranslation ( "auditor_of" ) + ' ' + totalPages ) ) ;
10071007
10081008 var issueList = _doc . querySelectorAll ( '.HTMLCS-issue-list' ) [ 0 ] ;
10091009 issueList . style . marginLeft = ( ( _page - 1 ) * - 300 ) + 'px' ;
@@ -1022,7 +1022,7 @@ _global.HTMLCSAuditor = new function()
10221022 }
10231023
10241024 pageNum . innerHTML = '' ;
1025- pageNum . appendChild ( document . createTextNode ( _global . translation [ "auditor_issue" ] + ' ' + _page + ' ' + _global . translation [ "auditor_of" ] + ' ' + totalPages ) ) ;
1025+ pageNum . appendChild ( document . createTextNode ( _global . HTMLCS . getTranslation ( "auditor_issue" ) + ' ' + _page + ' ' + _global . HTMLCS . getTranslation ( "auditor_of" ) + ' ' + totalPages ) ) ;
10261026
10271027 var issueList = _doc . querySelectorAll ( '.HTMLCS-issue-list' ) [ 0 ] ;
10281028 issueList . style . marginLeft = ( ( _page - 1 ) * - 300 ) + 'px' ;
@@ -1373,6 +1373,25 @@ _global.HTMLCSAuditor = new function()
13731373 return _doc ;
13741374 } ;
13751375
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+
13761395 /**
13771396 * Run HTML_CodeSniffer and place the results in the auditor.
13781397 *
@@ -1458,6 +1477,10 @@ _global.HTMLCSAuditor = new function()
14581477 _options . path = './' ;
14591478 }
14601479
1480+ if ( ! options . lang ) {
1481+ _options . lang = this . getDocumentLanguage ( ) ;
1482+ }
1483+
14611484 if ( _options . includeCss === undefined ) {
14621485 _options . includeCss = true ;
14631486 }
@@ -1559,7 +1582,7 @@ _global.HTMLCSAuditor = new function()
15591582 } else {
15601583 _processSource ( standard , sources ) ;
15611584 }
1562- } ) ;
1585+ } , function ( ) { } , options . lang ) ;
15631586 } ;
15641587
15651588 _processSource ( standard , _sources . concat ( [ ] ) ) ;
0 commit comments