Language in MediaWiki

From MediaWiki.org
Jump to: navigation, search

In MediaWiki, there are various kinds of languages:

  • The site content language ($wgContLang, based on $wgLanguageCode), which should generally stay the same as long as the wiki exists.
  • The user interface language ($wgLang), which can be changed in your preferences or with &uselang=xyz in the URL, but also generally remains the same while using the wiki.
    • The user language variant which is the variant of the site content language variant, as preferred by the user. It can also be set through &variant in the URL (e.g. by selecting one of the tabs) if it is a variant of your user language.
  • The page content language. This can be different for each page, even if the site and user language is the same. It is defined in getPageLanguage() in Title.

All three of them are a Language object.

[edit] User interface language

MediaWiki version: 1.18
Default value
Set via
  • Special:Preferences
  • &uselang=zxx in the URL
  • &variant=xy in the URL if it is a variant of your user language
Problems
Since interface messages can come from fallback languages but the language is not returned, the actual language of each message is not known.

[edit] Page content language

MediaWiki version: 1.18
Default value
  • $wgLang on special pages.
  • English for CSS and JS pages.
  • For MediaWiki namespace pages, the language depends on the subpage. For example, MediaWiki:Message/ar will be set to Arabic (ar), and MediaWiki:Message will be $wgContLang.
  • All other pages are $wgContLang by default.
Configuration
Extensions can change all other pages through the PageContentLanguage hook. The value for special pages, CSS, JS, and MediaWiki namespace pages cannot be overridden.
Examples
The Translate extension uses it for the page translation feature. See translatewiki:Project list/ar as a translation of translatewiki:Project list. The directionality of the page is thus correctly set to right-to-left for Arabic.
What does it define?
  • In SkinTemplate, it adds a <div lang="xyz" dir="ltr/rtl" class="mw-content-ltr/rtl"></div> around the page text. The dir attribute sets the correct writing direction. The lang attribute will always be the root code, e.g. "de" even when "de-formal" is given.
    For file pages, it is set in ImagePage.php, because there is a lot of HTML that is in the user language.
  • In Parser.php, it sets the table of contents (TOC) numberings, and stuff like grammar, although not really relevant mostly. To do that only, use parserOptions->setTargetLanguage().
  • The direction of the diff text (DifferenceEngine) is set to the page content language. In some cases this is not identical, in which case $diffEngineObject->setDiffLang( $code ) can be used.
  • Since 1.19, it also sets the time and number-formatting magic words, including DIRECTIONMARK, but not NAMESPACE(E), as that really depends on the site language. Note that including a template marked as language A onto a page with language B, will be parsed with language B on that page.
Multiple languages on a single page
Multiple languages on a single page is in theory not supported, but simple <div lang="xyz" dir="ltr/rtl" class="mw-content-ltr/rtl"> tags can be used to mark text as being written in a different language. If the CSS class is used, the ul/ol lists and editsection will display nicely when the dir tag is opposite to the value of that of the page content language. Things defined in the parser, like TOC and magic words, however, will not change.
MediaWiki version: 1.19
Javascript
wgPageContentLanguage - note that when e.g. viewing the page history, it will return the page language of the page it is the history of, whereas the history page doesn't have an mw-content-ltr/rtl class. I.e. both "/wiki/Page" and "/w/index.php?title=Page&action=history" will return the language of "Page".

[edit] See also

Personal tools
Namespaces

Variants
Actions
Navigation
Support
Download
Development
Communication
Print/export
Toolbox