Page language has no impact on screen reader

Our wiki is set to german [de] and has multi language off.

But we do have some articles in english. So we tried to set the language of those articles to englisch [en].

But testing a screenrader (iOS over voice) shows, that this has no impact on the language the screen readers uses. It is reading these english articles with german voice.

What is working (for testing purpose only) is setting the whole text in a html macro inside a div with lang attribute.

{{html wiki="true"}}
<div lang="en">

== RULES OF EMPLOYMENT ==

=== Chapter I. GENERAL PROVISIONS ===

==== Article 1. Purpose ====

1. These Rules of Employment (these “**Rules**”) contain matters regarding the employment of local employees (“**Employees**”) of xxx (“**Company**”). The purpose of these Rules is to improve working conditions and contribute to the development of Company’s business.
1. Any matters related to Employee’s employment that are not stipulated in these Rules are governed by the Labor Standards Act and other applicable laws and regulations.

</div>
{{/html}}

But this means there is no possibility to edit this article with the wysiwyg editor. So we can’t use this.

I tried to “split” the html macro:

{{html}}
<div lang="en">
{{/html}}

== RULES OF EMPLOYMENT ==

=== Chapter I. GENERAL PROVISIONS ===

==== Article 1. Purpose ====

1. These Rules of Employment (these “**Rules**”) contain matters regarding the employment of local employees (“**Employees**”) of xxx (“**Company**”). The purpose of these Rules is to improve working conditions and contribute to the development of Company’s business.
1. Any matters related to Employee’s employment that are not stipulated in these Rules are governed by the Labor Standards Act and other applicable laws and regulations.

{{html}}
</div>
{{/html}}

But that leads to an empty div (with lang=“en”) on top and another empty div (w/o lang attribute) after the article.

Debugging the html source code I can see no difference regarding language attribute whether the article is set to german, english or with no language.

Someone an idea how to fix this?

I would think, that setting the language of the article should set the language attribute of id=“xwikicontent”.
Regards, Simpel

I made a macro for this problem.
XWiki.WikiMacroClass:

{{velocity}}
  #if($xcontext.macro.params.lang)
    #set($langCode = $xcontext.macro.params.lang)
  #else
    #set($langCode = "de")
  #end
  #if($xcontext.macro.params.elementID)
    #set($elementName = $xcontext.macro.params.elementID)
    #set($editorDescript = "The area with HTML ID '#$elementName' above this macro is provided with the language attribute '$langCode'.")
  #else
    #set($elementName = "xwikicontent")
    #set($editorDescript = "This article is provided with the language attribute '$langCode'.")
  #end

  {{html}}
    <script>
      var element = document.getElementById('$elementName');
      element.setAttribute('lang', '$langCode');
    </script>
    <div id="lang-macro-descript">
      $editorDescript
    <div>
  {{/html}}

{{/velocity}}

With two parameters:

  • lang: Enter the desired language code here (e.g. en for English). (mandatory)
  • elementID: If only a part of the article is to be provided with this language code, this area must be provided with an HTML ID beforehand. This ID must then be entered here.

XWiki.StyleSheetExtension:

/* don't show the message */
#lang-macro-descript {
  display: none;
}

/* but show the message if in editor mode */
.macro > #lang-macro-descript {
  display: block;
  background-color: #fcf8e3;
  border: 1px solid #e8e8e8;
  width: fit-content;
  padding: 8px 15px;
  margin-top: 20px;
  margin-bottom: 20px;
  border-radius: 4px;
}

/* remove nasty new line under the message if in editor mode */
#lang-macro-descript > div {
  display: none;
}

I hope it’s helpful for others.
Simpel

1 Like

Following the addition of a new test in the continuous integration build, we had an accessibility check that triggered a similar error. I think the cause might have been the same as the one for the issue you described here. I proposed a fix in XWIKI-21579: Invalid lang HTML Tag when "German (Germany)" locale is set by Sereza7 · Pull Request #2627 · xwiki/xwiki-platform · GitHub . This proposal will probably be merged by the next LTS and stable (after 15.10) versions.

The cause, AFAIK, is that we didn’t use the correct format for the lang attribute, which was fine when there was just a language but bugged when adding a region.