Henri Willman
Henri Willman

Reputation: 179

Should aria attributes also be translated if the page is using translations?

What's the best practice regarding aria attribute translations? If a page is available in several languages, should aria attributes be too?

I am using react-i18next useTranslation hook to translate a site to a couple different languages, and I was wondering if I should also use the hook to translate my aria attributes.

Upvotes: 9

Views: 6901

Answers (3)

Andy
Andy

Reputation: 6160

It’s a common misconception that all UI text was visible or in text nodes. Often there are plenty of texts that will only be seen under certain conditions (states), or that will be read by machines, including search engines and assistive technology, before being presented to the user.

ARIA attributes that include human readable text are part of it and need to be translated.

I read articles about always trying to put text in a text node, for example by preferring aria-labelledby over aria-label. In my personal opinion, there are too many use cases where this is simply not possible. So we need a better approach anyway.

In HTML, examples for attributes that need localization, are:

  • Head Metadata including OpenGraph for sharing like <meta property="og:description">
  • alt attributes and title, also for <iframes> or <style> elements
  • label for video tracks
  • placeholder and pattern attributes if the format needs localization
  • value of inputs if not user-defined
  • Human-readable ARIA attributes aria-description, aria-label, aria-placeholder, aria-roledescription, aria-valuetext, aria-braillelabel

And also text

  • visually hidden by CSS, often via .sr-only or .visually-hidden classes
  • added by CSS’s pseudo-elements like ::before

Text parts with the lang attribute should not get translated and keep that attribute.

Relatedly, there is the translate attribute

[…] that is used to specify whether an element's translatable attribute values and its Text node children should be translated when the page is localized, or whether to leave them unchanged.

Upvotes: 6

QuentinC
QuentinC

Reputation: 14697

As all text potentially presented by the user, of course they have to be translated.

All ARIA attributes containing plain text, such as aria-label, have to be translated, with the same care as if they were normally displayed on screen. This is also true for alt attribute of images, sr_only text, etc.

As a screen reader user speaking several languages living in a country with several official languages and so very often face multilingual websites, I can confirm that it's a common annoying oversight.

Of course, all what is purely technical, such as IDs, true/false values, etc. don't need to be translated, as no user will ever see them.

Upvotes: 10

slugolicious
slugolicious

Reputation: 17445

I would limit the question a bit because not all ARIA attributes should be translated. In fact, most of them should not. For example, you don't want "true"/"false" (aria-hidden) translated to another language. You don't want "polite"/"assertive" (aria-live) translated to another language.

So you're really only talking about aria-label and aria-roledescription (the latter is not used very much). In ARIA 1.3, there will also be aria-description so it would be translated too.

But yes, if you translate the whole page (and set the lang attribute appropriately), you should also translate the aria attributes associated with string labels.

That's why I like using aria-labelledby instead of aria-label because the ID associated with the label will be translated (assuming it's a regular text HTML element) so your label gets translated for free.

Upvotes: 6

Related Questions