Jump to content

Directionality support: Difference between revisions

From mediawiki.org
Content deleted Content added
No edit summary
MathXplore (talk | contribs)
m Reverted edits by ~2026-17710-99 (talk) to last version by MathXplore: test edits, please use the sandbox
 
(123 intermediate revisions by 40 users not shown)
Line 1: Line 1:
<languages/>
[[File:LTR content with RTL interface (after).png|thumb|350px|[http://translatewiki.net/wiki/Translating:MediaWiki?uselang=he English (LTR) content with Hebrew (RTL) interface.]]]
{{i18n navigation}}
If you want to make a feature or extension compatible with right-to-left interface and different directionality in general, here are some guidelines:
[[File:LTR content with RTL interface (after).png|thumb|350px|[http://translatewiki.net/wiki/Translating:MediaWiki?uselang=he <translate><!--T:1--> English (LTR) content with Hebrew (RTL) interface.</translate>]]]
<translate><!--T:2--> Support for different {{<tvar name=1>ll|Writing systems</tvar>|writing}} directions (left-to-right, right-to-left) is an important aspect for multilingual software.</translate>
<translate><!--T:3--> Since <tvar name=1>{{ll|MediaWiki 1.18|MediaWiki 1.18}}</tvar>, the support has been considerably improved.</translate>


<translate>
== ResourceLoader ==
<!--T:4-->
Thanks to ResourceLoader including CSSJanus, CSS is automatically flipped to right-to-left when the user language is RTL. This is default since 1.18 (in previous versions it was [[bugzilla:6100|dependent on the wiki content language]]).
This page gives some relevant information, and guidelines for developers and wiki administrators if you want to make a feature or extension compatible with the right-to-left interface and different directionality in general.
* '''Attention:''' when developing with ResourceLoader debug on, the CSS will '''not''' be flipped. So you should test RTL interface with debug off.


== User-level tips == <!--T:5-->
== What kind of languages? ==

* $wgLang - user language (and the respective direction)
<!--T:6-->
* $wgContLang - site content language (and respective direction) -> here LTR
Some general tips for users, before getting to details for developers:

<!--T:7-->
* Most browsers support changing the direction of a plain-text editing area, such as article search boxes, wiki syntax editing, edit summary, etc.</translate> <translate><!--T:8--> Depending on browsers and operating systems, this is done by <tvar name=1>{{Key press|Ctrl|Shift}}</tvar> (Chrome and IE on Windows), <tvar name=2>{{Key press|Ctrl|Shift|X}}</tvar> (Firefox), Option-Click-Change direction (Mac).</translate> <translate><!--T:9--> This should help you typing in a direction that is different from the site's usual direction.</translate>
<translate>
<!--T:10-->
* When typing a section in a language that has a direction that is different from the site's, add a div tag with appropriate lang, dir and class attributes.</translate> <translate><!--T:11--> For example, when typing an English section in the Arabic Wikipedia, type <tvar name=1><syntaxhighlight lang=html inline><div lang="en" dir="ltr" class="mw-content-ltr"></syntaxhighlight></tvar> in the beginning and <tvar name=2>{{tag|div|close}}</tvar> in the end.</translate>
<translate>
<!--T:12-->
* When typing just a few words inside a paragraph, put them inside a <tvar name=1>{{tag|span|open}}</tvar> tag with appropriate lang and dir attributes.</translate> <translate><!--T:13--> (Many wikis have a template for this, such as <tvar name=1><nowiki>{{lang}}</nowiki></tvar>).</translate>
<translate>
<!--T:14-->
* To separate numbers from an adjacent word with different directionality, use RLM or LRM characters.</translate> <translate><!--T:15--> Many wikis have templates for this, for example <tvar name=1><nowiki>{{כ}}</nowiki></tvar> in the Hebrew Wikipedia, <tvar name=2><nowiki>{{RLM}}</nowiki></tvar> in the Arabic Wikipedia, <tvar name=3><nowiki>{{رچ}}</nowiki></tvar> in the Persian Wikipedia, etc.</translate> <translate><!--T:16--> When a template is available, it's usually preferred to using the Unicode character itself.</translate>

<translate>
<!--T:17-->
You can report bugs in RTL handling in Phabricator in any MediaWiki-related project using the RTL tag.

== ResourceLoader == <!--T:23-->
</translate>
<translate><!--T:24--> Thanks to <tvar name=rl>[[ResourceLoader]]</tvar> including <tvar name=url>[https://github.com/cssjanus/cssjanus CSSJanus]</tvar>, CSS is automatically flipped to right-to-left when the user language is RTL.</translate>
<translate><!--T:25--> This is default since <tvar name=version>1.18</tvar> (in previous versions it was [[<tvar name=bug>bugzilla:6100</tvar>|dependent on the wiki content language]]).</translate>
<translate><!--T:26--> There is relatively little CSS that must depend on the content language.</translate>

<translate>
<!--T:27-->
* '''Attention:''' when using ResourceLoader's [[<tvar name=mode>ResourceLoader/Architecture#Debug mode</tvar>|debug mode]], the CSS may be inconsistently rendered compared to the production mode.</translate> <translate><!--T:28--> As a temporary work-around test RTL interface with debug off. (Issue being tracked as <tvar name=task>[[Phabricator:T29025]]</tvar>.)</translate>

<translate>
== What kind of languages? == <!--T:29-->

<!--T:95-->
Main article:
</translate>
{{ll|Manual:Language}}

<translate>
<!--T:31-->
* $wgLang - user language (and the respective direction)</translate>
<translate>
<!--T:32-->
* $wgContLang - site content language (and respective direction) -> here LTR</translate>
<translate>
<!--T:33-->
* Title->getPageLanguage() - page content language (and respective direction) -> by default the same as site content language
* Title->getPageLanguage() - page content language (and respective direction) -> by default the same as site content language
</translate>
** There are some default exceptions: see below
** <translate><!--T:34--> There are some default exceptions: see below</translate>
** It can be set in extensions by the hook [[Manual:Hooks/PageContentLanguage|PageContentLanguage]]
** <translate><!--T:35--> It can be set in extensions by the hook <tvar name=1>{{ll|Manual:Hooks/PageContentLanguage|PageContentLanguage}}</tvar></translate>
** <translate><!--T:36--> This sets the TOC (and stuff like grammar, although not really relevant mostly) to that language. To do that only, use parserOptions->setTargetLanguage()</translate>
<translate>
<!--T:37-->
* In extensions that should remain compatible with 1.17, you can use wfUILang(), however this breaks compatibility with 1.16 and below.</translate> <translate><!--T:38--> This returns $wgLang in 1.18 and higher but $wgContLang in 1.17 (by default).</translate>


<translate>
=== What should follow which kind? ===
* Special pages follow user language by default.
=== What should follow which kind? === <!--T:39-->

* Source code should be English (CSS/JS pages are set to English by default).
<!--T:40-->
* Pages with translated subpages should follow the language of the translation (e.g. "Page" is wgContLang, "Page/he" is "he"). This is by default for the MediaWiki namespace.
* Input boxes and textareas follow content direction by default.
* Special pages follow the user language by default.</translate>
<translate>
<!--T:41-->
* Source code should be English (CSS/JS pages are set to English by default).</translate>
<translate>
<!--T:42-->
* Pages with translation as subpages should follow the language of the translation (e.g. "Page" is wgContLang, "Page/he" is "he"). This is the default for the MediaWiki namespace.</translate>
<translate>
<!--T:43-->
* Input boxes and textareas follow content direction by default.</translate>
<translate>
<!--T:44-->
* When viewing a diff, it follows the user language, but the actual diff text is in the page content language.
* When viewing a diff, it follows the user language, but the actual diff text is in the page content language.
[[<tvar name=file>File:Wait, -tahW- The Twisted Road to Right-to-Left Language Support.webm</tvar>|thumb|Directionality can be confusing, but you can watch [[<tvar name=1>User:Mooeypoo</tvar>|mooeypoo]]'s [[w:Linux.conf.au|linux.conf.au]] talk entitled "<tvar name=title>Wait, ?tahW: The Twisted Road to Right-to-Left Language Support</tvar>" to get a better understanding of the issues and solutions involved.]]


== What should I add in the source code? ==
== What should I add in the source code? == <!--T:45-->
</translate>
* Anything on special pages that is different from the user language should have a <nowiki><div dir="..." lang="..."></nowiki> tag.
* Anything on custom namespaces that contains text different from the default wiki content should also have a div tag.
* <translate><!--T:46--> Anything on special pages that is different from the user language should have a <tvar name=tag><syntaxhighlight lang=html inline><div dir="..." lang="..."></syntaxhighlight></tvar> tag.</translate>
*: <translate><!--T:47--> Example: <tvar name=xmp>SpecialRecentchanges->setTopText()</tvar> which adds the "<tvar name=msg>recentchangestext</tvar>" message in the wiki content language.</translate>
* When the diff text is not the same as the page content language, use <tt>$diff->setDiffLang( 'code' );</tt> where $diff is a DifferenceEngine object.
<translate>
<!--T:48-->
* Anything on custom namespaces that contains text different from the default wiki content should also have a <tvar name=1><code>div</code></tvar> tag.</translate>
<translate>
<!--T:49-->
* When the diff text is not the same as the page content language, use <tvar name=code>{{phpi|$diff->setTextLanguage( 'code' );}}</tvar> where $diff is a DifferenceEngine object.


=== lang/dir attributes ===
=== lang/dir attributes === <!--T:50-->

<!--T:51-->
You should use HTML:
You should use HTML:
</translate>
<source lang="php">

<syntaxhighlight lang="php">
Xml::rawElement( 'div', array( 'lang' => $wgContLang->getCode(), 'dir' => $wgContLang->getDir() );
Xml::rawElement( 'div', array( 'lang' => $wgContLang->getCode(), 'dir' => $wgContLang->getDir() );
</syntaxhighlight>
</source>

but sometimes that is difficult in dynamically generated elements and you can fall back on CSS:
<translate><!--T:62--> but sometimes that is difficult in dynamically generated elements and you can fall back on CSS:</translate>
<source lang="css">

<syntaxhighlight lang="css">
.class { direction: ltr; }
.class { direction: ltr; }
</syntaxhighlight>
</source>


<translate>
=== wiki content ===
=== Wiki content === <!--T:52-->
You can use <tt>.mw-content-ltr</tt> and <tt>.mw-content-rtl</tt> to make use of edit section links and ul/ol elements based on that direction.
</translate>
{{MW 1.18|and after}}
<translate>
<!--T:54-->
You can use <tvar name=ltr><code>mw-content-ltr</code></tvar> and <tvar name=rtl><code>mw-content-rtl</code></tvar> classes to make use of edit section links and ul/ol elements based on that direction.

<!--T:55-->
:E.g.
:E.g.
</translate>
<source lang="php">

Xml::rawElement( 'div', array( 'class' => 'mw-content-' . $wgLang->getDir, 'lang' => $wgLang->getCode(), 'dir' => $wgLang->getDir(), 'Text' );
<syntaxhighlight lang="php">
</source>
Xml::rawElement( 'div', array(
This is of course used for the page content of articles. It is also for example used in the CodeReview extension for the code summary and code comments, which can contain ul/ol elements (* and # wikitext).
'class' => 'mw-content-' . $wgLang->getDir(),
'lang' => $wgLang->getCode(),
'dir' => $wgLang->getDir(),
'Text'
);
</syntaxhighlight>

<translate>
<!--T:56-->
This is of course used for the page content of articles.

<!--T:57-->
* On file pages, it is only added around the actual text while the rest of the file page is custom UI (file history, ...).</translate>
<translate>
<!--T:58-->
* On category pages it is added as on regular pages, but the text in the user language is embedded in a <tvar name=1><code>div</code></tvar> with <tvar name=2><code>lang</code></tvar> and <tvar name=3><code>dir</code></tvar> attributes according to the user language.</translate>
<translate>
<!--T:59-->
* On special pages it is ''not'' added because these are largely in the user language.</translate> <translate><!--T:60--> A piece of text on special pages can be in the content language, which should then be embedded in these classes.</translate> <translate><!--T:61--> It is for example used in the CodeReview extension for the code summary and code comments, which can contain ul/ol elements (* and # wikitext) in the wiki content language and in principle not the user language obviously.</translate>

<translate><!--T:63--> Adding UI stuff within these classes should not be done.</translate>
<translate><!--T:64--> For example, the category links and FlaggedRevs review form are inside <tvar name=in>#bodyContent</tvar> but outside <tvar name=out>.mw-content-ltr/rtl</tvar>.</translate>

<translate>
<!--T:70-->
See also [[<tvar name=1>Special:MyLanguage/Manual:Interface/IDs and classes</tvar>|IDs and classes]].

=== body classes === <!--T:18-->
</translate>
<translate><!--T:71--> The body tag has an <tvar name=1><code>ltr</code></tvar> or <tvar name=2><code>rtl</code></tvar> class by default, which follows the user language.</translate>
<translate><!--T:72--> You shouldn't use that, because CSS is automatically flipped based on the user language.</translate>
<translate><!--T:73--> The body tag also features a new (1.18) <tvar name=1><code>sitedir-ltr</code></tvar> and <tvar name=2><code>sitedir-rtl</code></tvar> class which follows <tvar name=gdir>{{phpi|$wgContLang->getDir()}}</tvar>.</translate>
<translate><!--T:74--> If there is need for it, a "<tvar name=usrl>userlang-ltr/rtl</tvar>" and/or "<tvar name=pagel>pagelang-ltr/rtl</tvar>" could be added as well.</translate>

<translate>
=== float/text-align === <!--T:19-->

<!--T:75-->
You can use <tvar name=1>{{phpi|$wgLang->alignStart()}}, {{phpi|$wgContLang->alignStart()}}, {{phpi|$wgLang->alignEnd()}}, {{phpi|$wgContLang->alignEnd()}}</tvar> which gives the appropriate 'right' or 'left' values.

<!--T:76-->
You can use CSS <tvar name=float><code>float</code></tvar> or <tvar name=txtaln><code>text-align</code></tvar> of which the value (left/right) is flipped for RTL interface languages.

== Examples == <!--T:20-->


<!--T:77-->
Adding UI stuff within these classes should not be done. For example, the category links and FlaggedRevs review form are inside #bodyContent but outside .mw-content-ltr/rtl.
<tvar name=1>Special:AllMessages</tvar> is a special page, which means it follows the user language direction. However, the actual messages should follow the direction of the selected language.
</translate>


* <translate><!--T:78--> <tvar name=1>[[Special:Allmessages]]</tvar> = English, LTR</translate>
A new feature is that these classes can be used within these classes. For example, .mw-content-rtl can be used in an LTR (mw-content-ltr) article. This is useful for multilingual pages. Prior to this, local MediaWiki:Common.css hacks had to be used to make e.g. bullet lists show correctly in <nowiki><div dir="ltr/rtl"></nowiki> text (note that that has not changed; only mw-content-ltr/rtl classes contain these improvements).
* <translate><!--T:79--> <tvar name=1>[[Special:Allmessages/he]]</tvar> = Hebrew, RTL</translate>


<translate>
=== body classes ===
<!--T:80-->
The body tag has an <tt>ltr</tt> or <tt>rtl</tt> class by default, which follows the user language. You shouldn't use that, because CSS is automatically flipped based on the user language. The body tag also features a new <tt>sitedir-ltr</tt> and <tt>sitedir-rtl</tt> class which follows <tt>$wgContLang->getDir()</tt>. If there is need for it, a "userlang-ltr/rtl" and/or "pagelang-ltr/rtl" could be added as well.
The cells in the table containing the content of the messages, have a <tvar name=1><code>lang</code></tvar> & <tvar name=2><code>dir</code></tvar> attribute.


<!--T:81-->
=== float/text-align ===
The <tvar name=1>{{ll|Extension:Translate|Translate}}</tvar> extension, making use of the PageContentLanguage hook, sets the right language (and consequently direction) for translated pages, see e.g. [[meta:Wikimedia_maintenance_notice/ar]] which benefits from the mw-content-rtl class on an LTR wiki.
Shared CSS features the following, which are flipped according to the user language direction (so this is for LTR):
<source lang="css">
.mw-float-start { float: left; }
.mw-float-end { float: right; }
.mw-align-start { text-align: left; }
.mw-align-end { text-align: right; }
</source>
You can use these when useful.


== Local wikis == <!--T:82-->
You can also use <tt>$wgLang->alignStart()</tt>, <tt>$wgContLang->alignStart()</tt>, <tt>$wgLang->alignEnd()</tt>, <tt>$wgContLang->alignEnd()</tt> which gives the appropriate 'right' or 'left' values.
</translate>
<translate><!--T:83--> <tvar name=1>MediaWiki:Common.css</tvar> pages and relatives are also flipped.</translate>
<translate><!--T:97--> This means that you have to add <tvar name=2>@noflip</tvar> where needed.</translate>


<translate>
== Examples ==
<!--T:84-->
Special:AllMessages is a special page, which means it follows the user language direction. However, the actual messages should follow the direction of the selected language.
See [[<tvar name=1>phab:T33923</tvar>|T33923]]: site CSS should not be flipped by default.
* [[translatewiki:Special:Allmessages]] = English, LTR
* [[translatewiki:Special:Allmessages/he]] = Hebrew, RTL
The cells in the table containing the content of the messages, have a lang & dir attribute.


== Local wikis ==
== Issues == <!--T:21-->
</translate>
MediaWiki:Common.css pages and relatives are also flips. This means that you have to add @noflip where needed.
* <translate><!--T:85--> Most major features and extensions have improved support since about 1.19, see <tvar name=1>[[translatewiki:Project:Better directionality and i18n development]]</tvar> for that.</translate>
* <translate><!--T:86--> Known remaining issues:</translate>
** <translate><!--T:87--> External link icons are flipped according to user language direction (minor issue)</translate>
** {{ll|Extension:LiquidThreads|LiquidThreads}} - <translate><!--T:88--> Use <tvar name=1><code>contlang</code></tvar> instead of <tvar name=2><code>pagelang</code></tvar>, otherwise special page returns <tvar name=3><code>userlang</code></tvar></translate>
** {{ll|Extension:WikiLove|WikiLove}} - <translate><!--T:89--> kittens aligned left <tvar name=file>(<code><nowiki>[[File:Blabla.jpg|left]]</nowiki></code>)</tvar> should be aligned right in RTL wikis (minor issue)</translate>
** <translate><!--T:90--> OmegaWiki: needs general overhaul (Expression and DefinedMeaning pages should follow user direction) + [[<tvar name=1>bugzilla:23035</tvar>|23035]]</translate>
* <translate><!--T:91--> Search bugs: <tvar name=bugz>https://bugzilla.wikimedia.org/buglist.cgi?quicksearch=rtl</tvar></translate>


<translate>
== See also ==
== See also == <!--T:22-->
* https://docs.google.com/present/edit?id=0AdI0egeOYDROZGY4emRyZzZfMzc5djQ5bmtmcg&hl=nl&ncl=true
</translate>
* [[Localisation]]
* {{ll|Manual:Interface/IDs and classes}}
* [[translatewiki:Project:Better directionality and i18n development]]
* {{ll|Localisation}}
* [[translatewiki:Project:Better directionality and i18n development]] <translate><!--T:93--> (around 2011) and the much older</translate> [[m:BiDi workgroup]]
* {{ll|Manual:Hooks/PageContentLanguage}}
* {{ll|Visual editor/Bidirectional text requirements}}
* {{ll|Extension:RevisionSlider/Developing a RTL-accessible feature in MediaWiki - what we've learned while creating the RevisionSlider}}
* <translate><!--T:96--> [<tvar name=url>https://www.youtube.com/watch?v=xpumLsaAWGw</tvar> Quick Intro: Unicode Bidirectional Algorithm] by <tvar name=1>[[User:MSchottlender-WMF]]</tvar></translate>
* [http://rtl.wtf/ rtl.wtf] - <translate><!--T:94--> articles and examples about how to support right-to-left online</translate>


[[Category:Localisation]]
[[Category:Localisation{{#translation:}}]]

Latest revision as of 09:26, 21 March 2026

i18n docs
English (LTR) content with Hebrew (RTL) interface.

Support for different writing directions (left-to-right, right-to-left) is an important aspect for multilingual software. Since MediaWiki 1.18 , the support has been considerably improved.

This page gives some relevant information, and guidelines for developers and wiki administrators if you want to make a feature or extension compatible with the right-to-left interface and different directionality in general.

User-level tips

[edit | edit source]

Some general tips for users, before getting to details for developers:

  • Most browsers support changing the direction of a plain-text editing area, such as article search boxes, wiki syntax editing, edit summary, etc. Depending on browsers and operating systems, this is done by Ctrl+⇧ Shift (Chrome and IE on Windows), Ctrl+⇧ Shift+X (Firefox), Option-Click-Change direction (Mac). This should help you typing in a direction that is different from the site's usual direction.
  • When typing a section in a language that has a direction that is different from the site's, add a div tag with appropriate lang, dir and class attributes. For example, when typing an English section in the Arabic Wikipedia, type <div lang="en" dir="ltr" class="mw-content-ltr"> in the beginning and ‎</div> in the end.
  • When typing just a few words inside a paragraph, put them inside a ‎<span> tag with appropriate lang and dir attributes. (Many wikis have a template for this, such as {{lang}}).
  • To separate numbers from an adjacent word with different directionality, use RLM or LRM characters. Many wikis have templates for this, for example {{כ}} in the Hebrew Wikipedia, {{RLM}} in the Arabic Wikipedia, {{رچ}} in the Persian Wikipedia, etc. When a template is available, it's usually preferred to using the Unicode character itself.

You can report bugs in RTL handling in Phabricator in any MediaWiki-related project using the RTL tag.

ResourceLoader

[edit | edit source]

Thanks to ResourceLoader including CSSJanus, CSS is automatically flipped to right-to-left when the user language is RTL. This is default since 1.18 (in previous versions it was dependent on the wiki content language). There is relatively little CSS that must depend on the content language.

  • Attention: when using ResourceLoader's debug mode, the CSS may be inconsistently rendered compared to the production mode. As a temporary work-around test RTL interface with debug off. (Issue being tracked as Phabricator:T29025.)

What kind of languages?

[edit | edit source]

Main article: Manual:Language

  • $wgLang - user language (and the respective direction)
  • $wgContLang - site content language (and respective direction) -> here LTR
  • Title->getPageLanguage() - page content language (and respective direction) -> by default the same as site content language
    • There are some default exceptions: see below
    • It can be set in extensions by the hook PageContentLanguage
    • This sets the TOC (and stuff like grammar, although not really relevant mostly) to that language. To do that only, use parserOptions->setTargetLanguage()
  • In extensions that should remain compatible with 1.17, you can use wfUILang(), however this breaks compatibility with 1.16 and below. This returns $wgLang in 1.18 and higher but $wgContLang in 1.17 (by default).

What should follow which kind?

[edit | edit source]
  • Special pages follow the user language by default.
  • Source code should be English (CSS/JS pages are set to English by default).
  • Pages with translation as subpages should follow the language of the translation (e.g. "Page" is wgContLang, "Page/he" is "he"). This is the default for the MediaWiki namespace.
  • Input boxes and textareas follow content direction by default.
  • When viewing a diff, it follows the user language, but the actual diff text is in the page content language.
Directionality can be confusing, but you can watch mooeypoo's linux.conf.au talk entitled "Wait, ?tahW: The Twisted Road to Right-to-Left Language Support" to get a better understanding of the issues and solutions involved.

What should I add in the source code?

[edit | edit source]
  • Anything on special pages that is different from the user language should have a <div dir="..." lang="..."> tag.
    Example: SpecialRecentchanges->setTopText() which adds the "recentchangestext" message in the wiki content language.
  • Anything on custom namespaces that contains text different from the default wiki content should also have a div tag.
  • When the diff text is not the same as the page content language, use $diff->setTextLanguage( 'code' ); where $diff is a DifferenceEngine object.

lang/dir attributes

[edit | edit source]

You should use HTML:

Xml::rawElement( 'div', array( 'lang' => $wgContLang->getCode(), 'dir' => $wgContLang->getDir() );

but sometimes that is difficult in dynamically generated elements and you can fall back on CSS:

.class { direction: ltr; }

Wiki content

[edit | edit source]
MediaWiki version:
1.18

You can use mw-content-ltr and mw-content-rtl classes to make use of edit section links and ul/ol elements based on that direction.

E.g.
Xml::rawElement( 'div', array(
        'class' => 'mw-content-' . $wgLang->getDir(),
        'lang' => $wgLang->getCode(),
        'dir' => $wgLang->getDir(),
        'Text'
);

This is of course used for the page content of articles.

  • On file pages, it is only added around the actual text while the rest of the file page is custom UI (file history, ...).
  • On category pages it is added as on regular pages, but the text in the user language is embedded in a div with lang and dir attributes according to the user language.
  • On special pages it is not added because these are largely in the user language. A piece of text on special pages can be in the content language, which should then be embedded in these classes. It is for example used in the CodeReview extension for the code summary and code comments, which can contain ul/ol elements (* and # wikitext) in the wiki content language and in principle not the user language obviously.

Adding UI stuff within these classes should not be done. For example, the category links and FlaggedRevs review form are inside #bodyContent but outside .mw-content-ltr/rtl.

See also IDs and classes.

body classes

[edit | edit source]

The body tag has an ltr or rtl class by default, which follows the user language. You shouldn't use that, because CSS is automatically flipped based on the user language. The body tag also features a new (1.18) sitedir-ltr and sitedir-rtl class which follows $wgContLang->getDir(). If there is need for it, a "userlang-ltr/rtl" and/or "pagelang-ltr/rtl" could be added as well.

float/text-align

[edit | edit source]

You can use $wgLang->alignStart(), $wgContLang->alignStart(), $wgLang->alignEnd(), $wgContLang->alignEnd() which gives the appropriate 'right' or 'left' values.

You can use CSS float or text-align of which the value (left/right) is flipped for RTL interface languages.

Examples

[edit | edit source]

Special:AllMessages is a special page, which means it follows the user language direction. However, the actual messages should follow the direction of the selected language.

The cells in the table containing the content of the messages, have a lang & dir attribute.

The Translate extension, making use of the PageContentLanguage hook, sets the right language (and consequently direction) for translated pages, see e.g. meta:Wikimedia_maintenance_notice/ar which benefits from the mw-content-rtl class on an LTR wiki.

Local wikis

[edit | edit source]

MediaWiki:Common.css pages and relatives are also flipped. This means that you have to add @noflip where needed.

See T33923: site CSS should not be flipped by default.

Issues

[edit | edit source]

See also

[edit | edit source]