In MediaWiki, there are various kinds of languages:
ContentLanguage
service in MediaWiki\MediaWikiServices::getContentLanguage
, based on $wgLanguageCode
), which should generally stay the same as long as the wiki exists.
$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.&variant
(or $wgVariantArticlePath ) 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, representing what language the rendered HTML content is written in.All three of them are language objects.
Language codeA language code is a valid standard abbreviation for a language supported by MediaWiki,[1] 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.[2]
In the example below, MediaWiki:Message/ar
, ar
is the language code for Arabic.
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.
There are some special language codes for internal or development use: qqq
(for message documentation, does not work with uselang
etc.), qqx
(shows message names for debugging), en-x-rtl
(English, but pretends it is a right-to-left language), en-x-piglatin
(when $wgUsePigLatinVariant
is enabled, for LanguageConverter testing), x-xss
(when $wgUseXssLanguage
is enabled, tests XSS vulnerabilities in messages).
Names.php is the master registry of languages supported by MediaWiki. This is not the same as languages of which MediaWiki will show l10n (JSON files) nor languages of which MediaWiki knows the names (via CLDR ), mind you!
Fallback languages Fallback chains (Some of the lines shown are inaccurate due to double languages in the fallback. Check if the connection actually exists in the text version)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 frc
(Cajun French), which falls back on the language code fr
(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 languages/messages/MessagesXX.php
file. For instance MessagesFrc.php. You can search the code for all uses. There is also a plain list from September 2020 in this Phabricator comment.
Viewing/getting the site content language
mw.config.get( 'wgContentLanguage' );User interface language MediaWiki version:
≥ 1.18
&uselang=zxx
in the URL (see uselang)&variant=xy
(or $wgVariantArticlePath ) in the URL if it is a variant of your user language≥ 1.18
ContentLanguage
.ContentLanguage
by default.≥ 1.24
ContentLanguage
). Language of pages in the MediaWiki namespace can't be changed.
$wgPageLanguageUseDB = true
and the pagelang
permission must be granted to a wiki user rights group (who can then perform page language changes).
<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.
<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.
mw.config.get( '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". 1.19+action=info
, linked in the toolbox) 1.21+First, you have a Language object in Language.php . This object contains all the localisable message strings, as well as other important language-specific settings and custom behavior (uppercasing, lowercasing, printing dates, formatting numbers, direction, custom grammar rules etc.).
The object is constructed from two sources: sub-classed versions of itself (classes) and Message files (messages).
There's also the MessageCache class, which handles input of text via the MediaWiki namespace. Most internationalisation is nowadays done via Manual:Messages API objects and by using the wfMessage()
shortcut function, which is defined in includes/GlobalFunctions.php
. Legacy code might still be using the old wfMsg*()
functions, which are now considered deprecated in favor of the above-mentioned Message objects.
See also Manual:Messages API .
Language objectsThere are two ways to get a language object. You can use the globals $wgLang and ContentLanguage
service (MediaWiki\MediaWikiServices::getContentLanguage
) for user interface and content language respectively. For an arbitrary language you can construct an object by using $languageFactory->getLanguage( 'en' )
by replacing en
with the code of the language. You can get $languageFactory
, an object of the MediaWiki\Languages\LanguageFactory
class, using Dependency Injection . You can also use wfGetLangObj( $code );
if $code
could already be a language object. The list of codes is in includes/languages/data/Names.php
.
Language objects are needed for doing language-specific functions, most often to do number, time and date formatting, but also to construct lists and other things. There are multiple layers of caching and merging with #Fallback languages, but the details are irrelevant in normal use.
Old local translation systemWith MediaWiki 1.3.0, a new system was set up for localising MediaWiki. Instead of editing the language file and asking developers to apply the change, users could edit the interface strings directly from their wikis. This is the system in use as of August 2005. People can find the message they want to translate in Special:AllMessages and then edit the relevant string in the MediaWiki:
namespace. Once edited, these changes are live. There was no more need to request an update, and wait for developers to check and update the file.
The system is great for Wikipedia projects; however a side effect is that the MediaWiki language files shipped with the software are no longer quite up-to-date, and it is harder for developers to keep the files on meta in sync with the real language files.
As the default language files do not provide enough translated material, we face two problems:
This is not such a big issue anymore, because translatewiki.net is advertised prominently and used by almost all translations. Local translations still do happen sometimes but they're strongly discouraged. Local messages mostly have to be deleted, moving the relevant translations to translatewiki.net and leaving on the wiki only the site-specific customisation; there's a huge backlog especially in older projects, this tool helps with cleanup.
Keeping messages centralised and in syncEnglish messages are very rarely out of sync with the code. Experience has shown that it's convenient to have all the English messages in the same place. Revising the English text can be done without reference to the code, just like translation can. Programmers sometimes make very poor choices for the default text.
What can be localisedSo many things are localisable on MediaWiki that not all of them are directly available on translatewiki.net : see translatewiki:Translating:MediaWiki. If something requires a developer intervention on the code, you can request it on Phabricator, or ask at translatewiki:Support if you don't know what to do exactly.
$datePreferences
$dateFormats
$defaultDateFormat
iconv
$linkTrail
. These are letters that can be glued after/before the closing/opening brackets of a wiki link, but appear rendered on the screen as if part of the link (that is, clickable and in the same colour), e.g.: [[foo]]bar
. By default the link trail is "a-z"; you may want to add the accentuated or non-Latin letters used by your language to the list.cite_text-zyx
for language code zyx
.Neat functionality:
sprintfDate
Currently making namespace name translations is disabled on translatewiki.net, so you need to do this yourself in Gerrit, or file a Phabricator task asking for someone else to do it.[4]
To allow custom namespaces introduced by your extension to be translated, create a MyExtension.i18n.namespaces.php
file that looks like this:
<?php /** * Translations of the namespaces introduced by MyExtension. * * @file */ $namespaceNames = []; // For wikis where the MyExtension extension is not installed. if( !defined( 'NS_MYEXTENSION' ) ) { define( 'NS_MYEXTENSION', 2510 ); } if( !defined( 'NS_MYEXTENSION_TALK' ) ) { define( 'NS_MYEXTENSION_TALK', 2511 ); } /** English */ $namespaceNames['en'] = [ NS_MYEXTENSION => 'MyNamespace', NS_MYEXTENSION_TALK => 'MyNamespace_talk', ]; /** Finnish (Suomi) */ $namespaceNames['fi'] = [ NS_MYEXTENSION => 'Nimiavaruuteni', NS_MYEXTENSION_TALK => 'Keskustelu_nimiavaruudestani', ];
Then load it from the extension.json
file using ExtensionMessagesFiles like this:
{ "name": "MyExtension", "version": "0.0.1", "descriptionmsg": "myextension-desc", "ExtensionMessagesFiles": { "MyExtensionNamespaces": "MyExtension.i18n.namespaces.php" } }
Now, when a user installs MyExtension on their Finnish (fi) wiki, the custom namespace will be translated into Finnish magically, and the user doesn't need to do a thing!
Also remember to register your extension's namespace(s) on the Extension default namespaces page.
Special page aliasesSee the manual page for Special pages for up-to-date information. The following does not appear to be valid.
Create a new file for the special page aliases in this format:
<?php /** * Aliases for the MyExtension extension. * * @file * @ingroup Extensions */ $aliases = []; /** English */ $aliases['en'] = [ 'MyExtension' => [ 'MyExtension' ] ]; /** Finnish (Suomi) */ $aliases['fi'] = [ 'MyExtension' => [ 'Lisäosani' ] ];
Then load it from the extension.json
file using ExtensionMessagesFiles like this:
{ "name": "MyExtension", "version": "0.0.1", "descriptionmsg": "myextension-desc", "ExtensionMessagesFiles": { "MyExtensionAlias": "MyExtension.i18n.alias.php" } }
When your special page code uses either SpecialPage::getTitleFor( 'MyExtension' )
or $this->getTitle()
(in the class that provides Special:MyExtension), the localised alias will be used, if it's available.
Namespace name aliases are additional names which can be used to address existing namespaces. They are rarely needed, but not having them when they are, usually creates havoc in existing wikis.
You need namespace name aliases:
The generic English namespace names are always present as namespace name aliases in all localisations, so you need not, and should not, add those.
Aliases can't be translated on Translatewiki.net , but can be requested there or on Bugzilla : see translatewiki:Translating:MediaWiki#Namespace name aliases.
Regional settingsSome linguistic settings vary across geographies; MediaWiki doesn't have a concept of region, it only has languages and language variants.
These settings need to be set once as a language's default, then individual wikis can change them as they wish in their configuration.
Time and date formatsTime and dates are shown on special pages and alike. The default time and date format is used for signatures, so it should be the most used and most widely understood format for users of that language. Also anonymous users see the default format. Registered users can choose other formats in their preferences.
If you are familiar with PHP's time() format, you can try to construct formats yourself. MediaWiki uses a similar format string, with some extra features. If you don't understand the previous sentence, that's OK. You can provide a list of examples for Developers .
See Help:System message#Message sources.
Notes See also{{#language:<code>}}
documented in magic wordsRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4