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

Improve missing lang test case #396

Closed
ffoodd opened this issue Oct 27, 2020 · 2 comments · Fixed by #412
Closed

Improve missing lang test case #396

ffoodd opened this issue Oct 27, 2020 · 2 comments · Fixed by #412

Comments

@ffoodd
Copy link
Owner

ffoodd commented Oct 27, 2020

@matuzo wrote about the lang attribute and how to check it, quoting a11y.css in the way. However his suggestion (on CodePen) is way more efficient than our own by using:

  • :lang() pseudo-class alongside attribute selector: should be a warning only to me since it depends on the page/website;
  • checks for whitespace in lang attribute using [lang*=" "] (which is realy clever and should be used on other selectors too, let me open another issue!).

Defintely need to implement this :)

@ffoodd ffoodd changed the title Imrpove missing lang test case Improve missing lang test case Oct 27, 2020
@Dionakra
Copy link
Contributor

Dionakra commented Jan 8, 2021

I have been researching a bit thanks to the #397 issue and I haven't found any standard regarding whitespaces on the [lang] attribute. The standard says the following:

The lang attribute (in no namespace) specifies the primary language for the element's contents and for any of the element's attributes that contain text. Its value must be a valid BCP 47 language tag, or the empty string. Setting the attribute to the empty string indicates that the primary language is unknown. [BCP47]

If we take a look at the BCP 47 language tags we can see that, in fact, no language tag has any whitespace, but that is an extracted pattern. We can also say that no language tag has a number on it, or a dollar sign ($).

Should we extract some patterns from the list and apply it to the rule?

@ffoodd
Copy link
Owner Author

ffoodd commented Jan 8, 2021

@Dionakra We may try, if that does not represent a too complex pattern to check. CSS is quite bad at regexing :D

As mentionned in #397, as far as I understand there's no room for whitespaces if we consider spec says lang should contain "a single valid BCP 47 language tag" (emphasis mine) and BCP47 RFC explains that a language tag should not contain whitespace (two paragraphs above this anchor).

So after new readings:

  1. do not use :lang() pseudo-class since default language is unknown as per the specs. English is the most used language by both web pages and assistive technologies, however that's not enough to make it a default value. Moreover :lang() only matches [lang] attributes or document language (using <meta> or dedicated HTTP Header, as explained on MDN). If meta is set, there's no way to check if its value matches the lang attribute's one; and content-language HTTP Header is not meant to indicate document language. To sum up: always set lang attribute, no matter what :lang() matches.
  2. MDN lang attribute page is much clearer, mainly by also mentionning related WCAG success criterions (3.1.1 —requiring labng attribute in all cases, matches .1 above— and 3.1.2). Those three links should be added to the references.
  3. We already check for whitespace value, but not containing whitespace value. The current selector should only be improved using the contains flag (*).
  4. Maybe try to create some pattern selector to check the value itself, but that'd be another test (probably a warning) and I think it'd be very complex. Worth a try, but not much time IMHO.

As often, an issue will mostly turn into more docs and references 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants