OAA LANG_2: lang attribute on html element must have a valid two-character language code.

Rulesets

WCAG 2.0 Requirement 3.1.1 Language of Page
Status: Accepted
Severity: Violation
Priority: Priority 1
IITAA 1.0 2.3 Identify the language of text.
Type:
Severity: Violation
Priority: Priority 1
Status: Accepted

Markup References

Validation Code

Message

lang attribute on html element must have a valid two-character language code.

Dependencies

  • LANG_1: Each page must have a lang attribute on its html element.

Context

html[@lang]

Parameters

None

Code

function (ruleContext) {

  var langStr = util.getValueFromAttributes(ruleContext,['lang'],"");
  var target;
  
  if (langStr.indexOf('-') == 2) {
    target = langStr.substr(0,2).toLowerCase();
  } else {
    target = langStr.toLowerCase();
  } // endif
  
  var passed = false;
  var oRequest = new XMLHttpRequest();
  oRequest.open("GET","http://www.iana.org/assignments/language-subtag-registry",false);
  oRequest.setRequestHeader("User-Agent",navigator.userAgent); oRequest.send(null);
  
  if (oRequest.status==200) {
    var contents = oRequest.responseText;
    var pos = contents.indexOf('Subtag: ' + target + '\n');
    if (pos > 0) {
      passed = true;
    } // endif  
  } else {
    // accessext_consoleDump(filename + " Error executing XMLHttpRequest call, does the file exist?");
  } // endif
  
  return new ValidationResult(passed, [ruleContext], 'lang', '', []);
  
}  // endfunction