accessibility-guidelines

This document is in beta. Help us by reporting issues via Github or email

Back to the overview page

Language of parts

On this page:


Summary

If the page has content in more than one language (for example, if a page in English has a button labelled in Welsh), identify the language of each part in code.

When content is displayed in a language that is different from the primary language of the page, it must be indicated in a way that assistive technologies understand.


Requirements

Content that is written in a different language from the main language of the page, should be identified in code.

For multi-lingual content, the language for anything that varies from the default language of the page or app must be defined in the local code for the correct speech synthesizer to be used. This includes image alternatives, form labels, quotes, objects, media alternatives, and other elements. It will over-ride the specified default language and any language and dialect setting specified on the users device.

Example

The homepage of the website of the Canadian Government is written in English, so it has <html lang="en">. On the homepage, there’s link to access the version written in French. The link text reads “Français”. The link text is written in French, so the language of the link text is identified with <a lang="fr">.

Common mistakes

Why?

This ensures that screen readers switch to the appropriate accent and pronunciation for that language.

When listening, correct pronunciation helps understanding. For users of assistive technologies such as screen readers it is particularly important, as some have different speech synthesizers for different languages. For example, “chat” means something different when using English pronunciation rather than French.

Official wording in the Web Content Accessibility Guidelines

3.1.2 Language of Parts: The human language of each passage or phrase in the content can be programmatically determined except for proper names, technical terms, words of indeterminate language, and words or phrases that have become part of the vernacular of the immediately surrounding text. (Level AA)

See the W3C’s detailed explanation of this guideline with techniques and examples.


Guidance for Design


Guidance for iOS

This section needs more content. Contribute via Github or email.


Guidance for Android

Starting on Android O (API level 26), Text-To-Speech services added support for reading and switching between languages automatically. In order to apply a language to a text, you need to wrap it with a LocaleSpan (min API level 17).

Here’s an example for setting different languages for texts:

// Text is in English
val spannable: SpannableString = SpannableString("This text is in English")
spannable.setSpan(LocaleSpan(Locale.ENGLISH), 0, spannable.length, 0)
return spannable

// Text is in Spanish
val spannable: SpannableString = SpannableString("Este texto está en Español")
spannable.setSpan(LocaleSpan(Locale("es", "ES")), 0, spannable.length, 0)
return spannable

Guidance for Flutter

This section needs more content. Contribute via Github or email.


Guidance for Web

Note: It’s better to only use the two-letter code representing the language (like lang="en"), rather than including the country as well (like lang="en-gb" or lang="en-us"):

Examples

<html lang="en">
  ...
  <body>
    <p>This page is written in English.</p>
    <p lang="fr">Sauf pour ce qui est écrit en français.</p>
  </body>
</html>
<html lang="en">
  ...
    <h2>Upcoming Spanish Holidays</h2>
    <p lang="es">Les Fogueres de Sant Joan.</p>
  ...
</html>  

Failure example

<html>
  ...
    <h2>Upcoming Spanish Holidays</h2>
    <p>Les Fogueres de Sant Joan.</p>
  ...
</html>  

More guidance for Web


More info

Sources

Contribute

This document is in beta. Help us by reporting issues via Github or email