Links in language switcher block do not conform to WCAG language-of-parts

Created on 18 April 2019, about 5 years ago
Updated 13 October 2023, 9 months ago

Problem/Motivation

The language names in the language switcher block do not have a programmatically determinable language. This is needed for WCAG success criterion 3.1.2 Language of Parts.

It is helpful for screen readers to know the language of the link text, so the language name can be announced using the speech rules for that language. The main benefit is that people can recognize the name of their language when it is pronounced correctly.

Note: this is not the same as the existing hreflang attribute on those links (which are implemented correctly, btw). The hreflang indicates the main language of the linked resource. This issue is about indicating the language of the link text itself, where it differs from the main page language.

Proposed resolution

Add lang attribute to each link in the language switcher block.

Remaining tasks

TBD.

User interface changes

Improve machine-readable semantics for assistive technology. Especially helpful to assistive tech which uses a text-to-speech audio engine, such as screen readers.

API changes

TBD.

Data model changes

None.

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
Language systemΒ  β†’

Last updated about 9 hours ago

  • Maintained by
  • πŸ‡©πŸ‡ͺGermany @sun
Created by

πŸ‡¬πŸ‡§United Kingdom andrewmacpherson

Live updates comments and jobs are added and updated live.
  • Accessibility

    It affects the ability of people with disabilities or special needs (such as blindness or color-blindness) to use Drupal.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡©πŸ‡ͺGermany szeidler Berlin

    If I understand it correctly is the language switcher block using the native language names, isn't it? That would mean we could just set it to the language code of the language that is supposed to be rendered as a switcher link? Which essentially also should always be the same as the hreflang attribute value?

    Then we would need to go into all classes implementing LanguageSwitcherInterface and add the attribute there, similar to this.

    foreach ($this->languageManager->getNativeLanguages() as $language) {
      $links[$language->getId()] = [
        // We need to clone the $url object to avoid using the same one for all
        // links. When the links are rendered, options are set on the $url
        // object, so if we use the same one, they would be set for all links.
        'url' => clone $url,
        'title' => $language->getName(),
        'language' => $language,
        'attributes' => ['class' => ['language-link'], 'lang' => $language->getId()],
        'query' => $query,
      ];
    }
    

    Is it easy as that?

Production build 0.69.0 2024