Incubator:Language select

This page, or parts of it, comes from Meta. It is updated July 12, 2007. For the page at Meta, see Meta:Language select.
Please do not make any changes or additions to this page.

Language select allows users to hide foreign languages on multilingual pages. This, for example, allows a French reader to see only French text on multilingual pages (though they would still see Spanish on a Spanish-only page).


There are two working implementations of language select. The preparation of a page for language selection is the same for both methods. The older CSS method allows multiple languages to be selected, most useful for multilingual users. However, it cannot recognize when no selected language is present, which results in no content being displayed. The newer JavaScript method detects the language of your browser automatically (you can configure it to ignore the browser setting), and does nothing if no selected language is present. However, it can only display one language at a time.

Delimiting languages

Technical details

A multilingual page is contained by the CSS class "multilingual", with text in every language contained within the class "lang-xx", where xx is a lowercase ISO 639 two-letter language code and the lang attribute. The lang attribute is contextually more correct, but the CSS required to hook into it is not supported by all browsers. If there is no two-letter code, the lowercase three-letter code is used. If you're translating existing messages and don't know what the language is, use the code "und".

An example page in English, Old English, French and Latin:

<div class="multilingual">
<div class="lang-en" lang="en">This text is English.</div>
<div class="lang-ang" lang="ang">Þis wordu is Englisc.</div>
<div class="lang-fr" lang="fr">Ce texte est Français.</div>
<div class="lang-la" lang="la">Haec verba latina sunt.</div>


The template {{ls}} simplifies the implementation of language select. For example, the following two lines are equivalent:

{{ls|en|This text is English.}}
<div class="lang-en" lang="en">'''English:''' This text is English.</div>


Note that the two implementations conflict with each other, so only one should be used at a time.

The description below assumes you use the Monobook skin.

Cascading StyleSheets

Add the following lines to your stylesheet, editing as appropriate for the languages you wish to view.

/* hide all languages */
.multilingual { display:none; }
/* unhide selected languages */
.multilingual .lang-en, .multilingual .lang-fr { display:block; }

If you are using a browser with good support for CSS (such as Mozilla Firefox or Opera) you should use this more contextually correct CSS.

.multilingual *[lang] {display:none;}
.multilingual *[lang|=en], .multilingual *[lang|=fr] {display:block;}


The JavaScript method is activated by default on the Wikimedia MetaWiki. You can disable it by adding the following line to your script file.

ls_enable = false;

You can see an example of the JavaScript in action below. If language selection is disabled, all of the text will be displayed.

brezhoneg: Brezhoneg eo an destenn-mañ.
català: Aquest text és en català.
dansk: Denne tekst er på dansk.
Deutsch: Dieser Text ist Deutsch.
Ελληνικά: Αυτό το κείμενο είναι Ελληνικό.
English: This text is English.
العربية: هذا النّص عربي.
suomi: Tämä teksti on suomeksi.
français: Ce texte est Français.
italiano: Questo testo è in Italiano.
Latina: Haec nota Latine scriptus est.
Nederlands: Deze tekst is in het Nederlands.
norsk: Denne teksten er på norsk.
occitan: Aqueste tèxt es en Occitan.
polski: Ten tekst jest po polsku.
Ποντιακά: Άτο το κείμενον εν σα Ποντιακά.
português: Este texto está em Português.
русский: Это текст на русском.
sardu: Custu testu est in Sardu.
Türkçe: Bu tekst Türkçe'dir.
中文: 这些文字是中文。
گیلکی: ای بنويشته، گيلکی ايسسه

When specifying a language, use the code, not the full name.

You can view the JavaScript code at MediaWiki:Monobook.js.


The code is maintained in a private Subversion repository. I still have been unable to contact an MediaWiki developers on getting this code into Wikimedia's Subversion repository.

  • Revision 1358 — Edward Z. Yang(Talk) 15:36, 19 February 2007 (UTC)
    • If no cookie is present, code will sniff wgUserLanguage global variable
    • If language is set to blank, delete the cookie and switch to auto-detection.
  • Revision 1133 — Edward Z. Yang(Talk) 22:33, 2 September 2006 (UTC)
    • Tweaked Show all behavior to be more user-friendly: instead of overwriting your cookie, it only temporarily shows all the language strings. You can switch back by pressing Select
    • Renamed Save to Select
    • Styled the Select button to be bold.
    • Factored out language strings

See also