Manual:Language


 * See also architecture>Manual:MediaWiki architecture#Languages|Manual:MediaWiki architecture#Languages (should be merged here?)

In MediaWiki, there are various kinds of languages:


 * The site content language ($wgContLang, based on lang-code>Special:MyLanguage/Manual:$wgLanguageCode|$wgLanguageCode), which should generally stay the same as long as the wiki exists.


 * The site content language variant (deflangvariant>Special:MyLanguage/Manual:$wgDefaultLanguageVariant|Manual:$wgDefaultLanguageVariant) is the default variant when langconv>Special:MyLanguage/LanguageConverter|LanguageConverter is implemented for that language.


 * The user interface language (req-cont>Special:MyLanguage/Manual:RequestContext|$contextSource->getLanguage formerly lang>Special:MyLanguage/Manual:$wgLang|$wgLang), which can be changed in your preferences or with  in the URL, but also generally remains the same while using the wiki.


 * 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>Special:MyLanguage/Manual:Title.php|Title, representing what language the wikitext source is written in.


 * The page view language aka user language variant which is a language variant of page content language, as preferred by the user. It can also be set through  (or ) in the URL (e.g. by selecting one of the tabs) if it is a variant of the content language of the page being viewed. It's defined in getPageViewLanguage in title>Special:MyLanguage/Manual:Title.php|Title, representing what language the rendered HTML content is written in.

All three of them are lang-obj>Special:MyLanguage/language object|language objects.

Language code

 * Not to be confused with Wikimedia project code; see also Language code and Language codes on Meta

A language code is a valid standard abbreviation for a language supported by MediaWiki, which uses such codes as standard identifiers for languages (mostly in accordance with ISO 639-3, except two-letter codes from ISO 639-1 for "established" locales) and exposes or requires them in many points of the interface and code.

In the example below,,   is the the language code for.

Uniformity with Unicode standard is needed to provide a good language support, in particular in cooperation with CLDR; having an ISO 639-3 code is one requirement for a language to be added to MediaWiki locales.

Fallback languages


Some languages in MediaWiki have what is known as a "fallback sequence". This is where MediaWiki will fall back on a different language if it cannot find what it needs. An example of this is the language code  (Cajun French), which falls back on the language code   (French). The reason for this is that sometimes languages don't have all messages defined in them.

The fallback for a language can be found in its associated  file.

User interface language

 * Default value
 * req-context>Special:MyLanguage/Manual:RequestContext|$contextSource->getLanguage


 * Set via


 * Special:Preferences


 * in the URL (see uselang)


 * (or ) 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.

Page content language

 * 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 hooks-pcl>Special:MyLanguage/Manual:Hooks/PageContentLanguage</>|PageContentLanguage hook. The value for special pages, CSS, JS, and MediaWiki namespace pages cannot be overridden.


 * Examples
 * The ext-translate>Special:MyLanguage/Extension:Translate</>|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"> around the page text. The dir attribute sets the correct direct>Special:MyLanguage/Directionality support</>|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->setTextLanguage( $code ) can be used.


 * Since, it also sets the time and number-formatting help-magic>Special:MyLanguage/Help:magic words</>|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 are 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.


 * Viewing/getting the page language


 * man-interfacejs>Special:MyLanguage/Manual:Interface/JavaScript</>|JavaScript:  - 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".


 * The page content language is mentioned on the page info view (, linked in the toolbox)


 * The page content language can be retrieved in the api>Special:MyLanguage/API</>|API via api-prop>Special:MyLanguage/API:Properties</>|api.php?action=query&prop=info