Directionality support/fr

La prise en charge des différentes directions d' (de gauche à droite, de droite à gauche) est un aspect important pour les logiciels multilingues. Depuis, la prise en charge a été considérablement améliorée.

Cette page donne quelques informations importantes, et des règles pour les développeurs et les administrateurs de wiki pour rendre une fonctionalité ou une extension compatible avec l'interface de droite à gauche et les différentes directionalités en général.

Conseils aux utilisateurs
Voici quelques indications générales pour les utilisateurs avant d'aller plus en détails pour les developpeurs :


 * La plupart des navigateurs prennent en charge le changement de direction des zones d'édition de texte brut, comme les boîtes de recherche d'articles, la modification de la syntaxe wiki, le résumé des modifications, etc... En fonction des navigateurs et des systèmes d'exploitation, vous pouvez utiliser Ctrl-Shift (Chrome et Internet Explorer sous Windows), Ctrl-Shift-X (Firefox), Option-Click-Changer la direction (Mac). Ceci doit vous permettre de saisir dans une direction différente de celle habituellement utilisée par le site.
 * Lorsque vous saisissez une section dans une langue qui a une direction différente de celle du site, ajoutez une balise  avec la langue concernée et les attributs   et  . Par exemple, lorsque vous saisissez une section en anglais dans la wikipedia arabe, entrez  au début et  à la fin.
 * Si vous ne saisissez que quelques mots dans un paragraphe, incluez-les dans une balise avec les attributs lang et dir correspondants. (Beaucoup de wikis possèdent un modèle pour cela, tel que  ).
 * Pour séparer les nombres accolés à un mot pour des directionalités différentes, utilisez la chaîne RLM ou LRM. Beaucoup de wikis possèdent des modèles pour cela, par exemple dans la Wikipedia en hébreu,  dans la Wikipedia arabe,  dans la Wikipedia en persan, etc... Quand un modèle est disponible, il est généralement préférable de l'appeler plutôt que d'utiliser le caractère Unicode lui-même.

Vous pouvez rapporter dans Phabricator, les bogues concernant la gestion du RTL pour n'importe quel projet lié à MediaWiki en utilisant la balise RTL.

ResourceLoader
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 T29025.)

What kind of languages?

 * $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?

 * Special pages follow the user language by default.
 * Source code should be English (CSS/JS pages are set to English by default).
 * Pages with translated 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.

What should I add in the source code?

 * Anything on special pages that is different from the user language should have a 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
You should use HTML: but sometimes that is difficult in dynamically generated elements and you can fall back on CSS:

Wiki content
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.

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 & 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.

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  text. You should therefore use  instead of  when editing wiki pages.

See also Manual:Interface/IDs and classes.

Classes du corps
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</tt> class which follows $wgContLang->getDir</tt>. If there is need for it, a "userlang-ltr/rtl" and/or "pagelang-ltr/rtl" could be added as well.

alignement float/text
You can use $wgLang->alignStart</tt>, $wgContLang->alignStart</tt>, $wgLang->alignEnd</tt>, $wgContLang->alignEnd</tt> which gives the appropriate 'right' or 'left' values.

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

Exemples
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.
 * Special:Allmessages = English, LTR
 * Special:Allmessages/he = Hebrew, RTL

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

Local wikis
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

Problèmes

 * Most major features and extensions have improved support since about 1.19, see translatewiki:Project:Better directionality and i18n development for that.
 * Known remaining issues:
 * External link icons are flipped according to user language direction (minor issue)
 * LiquidThreads: Use contlang instead of pagelang, otherwise special page returns userlang
 * WikiLove: kittens aligned left ( Blabla.jpg ) should be aligned right in RTL wikis (minor issue)
 * OmegaWiki: needs general overhaul (Expression and DefinedMeaning pages should follow user direction) + 23035
 * Search bugs: https://bugzilla.wikimedia.org/buglist.cgi?quicksearch=rtl

Voir aussi

 * Better directionality support (2011 presentation slides)
 * Manual:Interface/IDs and classes
 * Localisation
 * translatewiki:Project:Better directionality and i18n development (around 2011) and the much older BiDi workgroup
 * Manual:Hooks/PageContentLanguage
 * Manual:$wgBetterDirectionality
 * Visual editor/Bidirectional text requirements
 * Extension:RevisionSlider/Developing a RTL-accessible feature in MediaWiki - what we've learned while creating the RevisionSlider
 * rtl.wtf, articles and examples about how to support right-to-left online