Meta:Language select

From Meta, a Wikimedia project coordination wiki
(Redirected from Language select)
This is Template:Stub without language selection.
This is Template:Stub with language selection (English and French).

Language select allows users to hide foreign languages on multilingual pages. This, for example, allows French readers to see only French text on multilingual pages.

Notes :

  • The Language select functionality described in this page should be used only when there are very few translations, and for translating a few sentences. The Language select functionality is only intended for pages (like generated activity reports, or user pages) that will be rarely translated, or for documenting category pages (when the creation of separate subcategories, for storing collections of translated pages per language, or is not desirable, or not possible for describing images).
  • Pages that are designed to be fully translated into multiple single-languages with subpages (See Meta:Translation for details) should preferably not use Language select, but a language bar to allow navigation between these pages.
  • As well, generic message boxes informing about the status of a page should be transcluded from templates that avoid using Language Select, but use Language Switching (see Template:LangSwitch) or the newer Translate extension, in order to display the user language directly.
    At right are two screenshots of Template:Stub (which earlier used the Language Select mechanism) without and with a language selection of English and French using the CSS method (see below) Now this template is autotranslated to the user language and will then no longer display all translations.


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.

Identifying multilingual pages

Pages that implement language selection include a notice linking back to this page using {{multilingual}}. There has been no discussion on the logo to use for this purpose; Localisation2.svg is currently used.

Delimiting languages

Technical details

A multilingual page is contained by the CSS class "multilingual", with text in every language contained within HTML elements tagged with the class="lang-xx" attribute, where xx is a lowercase BCP 47 language code (generally two or three letters from ISO 639, possibly followed by variant sufixes; if there is no two-letter code, the lowercase three-letter code is used.) and the HTML lang attribute. The lang attribute is contextually more correct than the class, but the CSS required to hook into it is not supported by all browsers. If you're translating existing messages and don't know what the language is, use the code "und".

An example page in Old English, English, French, Kiswahili, Latin, Occitan, Romanian, Pali, Arabic, Persian, and Uighur: (sorted per commons:Module:Multilingual description/sort)

<div class="multilingual">
<div class="lang-ang" lang="ang">Þis wordu is Englisc.</div>
<div class="lang-en" lang="en">This text is English.</div>
<div class="lang-fr" lang="fr">Ce texte est Français.</div>
<div class="lang-sw" lang="sw">Maelezo haya ni ya Kiswahili.</div>
<div class="lang-la" lang="la">Haec verba latina sunt.</div>
<div class="lang-oc" lang="oc">Aqueste tèxt es en Occitan.</div>
<div class="lang-ro" lang="ro">Acest text este în română.</div>
<div class="lang-pa" lang="pa">ਇਹ ਟੈਕਸਟ ਪੰਜਾਬੀ ਵਿੱਚ ਹੈ।</div>
<div class="lang-ar" lang="ar">هذا النّص عربي.</div>
<div class="lang-fa" lang="fa">اين نوشته فارسي است.</div>
<div class="lang-ug" lang="ug">بۇ ئۇيغۇرچە</div>

Note that for correct visual vsual ordering of the rendered native language names, the list has to be sorted manually on the page itself (and not sorted by language code), otherwise the relative order is kept and may finally be arbitrary and difficult to scan for readers to find their desired language.


The {{Ls}} template simplifies the implementation of language select. For example, the following two lines are equivalent (however the template also provides some other useful formatting options such as displaying a tooltip showing the language name in the current user language, and the associated language code, or coloring fuzzy translations needing updates):

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

This {{Ls}} template may be used multiple times within the multilingual section, including for the same language. The relative order of inclusion of Ls templates in the section is also kept, but in many cases you'll want to order languages in a consistent order. The {{LangSelect}} will simplify this (but will accept only one occurrence of each language).

Note that, currently, the language selection form with buttons is generated by Javascript below multilingual sections below each multilingual section in the current page, and an additional language selection box is also displayed at top of page (it displays a list of all language codes used in multilingual sections any where on the page, still without sorting them for easier selection). This can be customized with CSS (see below).

Compare how translations are mixed and difficult to find (notably when script directions are alternating) when they are initially sorted by language code (for easier editing and maintenance) when using multiple inclusions of {{Ls}}, and how {{LangSelect}} orders them visually by script (scripts being ordered by direction and type) and then alphabetically by language name, grouping all right-to-left languages separately from left-ro-right languages:

Wiki code Rendering
<div class="multilingual">
{{Ls|ar|هذا النص باللغة العربية.}}
{{Ls|da|Denne tekst er på dansk.}}
{{Ls|en|This text is English.}}
{{Ls|fa|این متن به زبان فارسی است.}}
{{Ls|fi|Tämä teksti on suomeksi.}}
{{Ls|fr|Ce texte est en français.}}
{{Ls|frc|update=en|Ce texte devrait être en français cajun.}}
{{Ls|he|טקסט כתוב בעברית.}}
{{Ls|hi|यह पाठ हिन्दी में है।}}
{{Ls|pa|ਇਹ ਟੈਕਸਟ ਪੰਜਾਬੀ ਵਿੱਚ ਹੈ।}}
{{Ls|ru|Этот текст на русском языке.}}
{{Ls|sv|Denna text är på svenska.}}
{{Ls|ur|یہ متن اردو ہے.}}
{{Ls|zu|Lo mbhalo Zulu.}}
العربية: هذا النص باللغة العربية.
Dansk: Denne tekst er på dansk.
English: This text is English.
فارسی: این متن به زبان فارسی است.
Suomi: Tämä teksti on suomeksi.
Français : Ce texte est en français.
Français cadien: Ce texte devrait être en français cajun. [update needed: en]
עברית: טקסט כתוב בעברית.
हिन्दी: यह पाठ हिन्दी में है।
मराठी: हा मजकूर मराठीत आहे.
ਪੰਜਾਬੀ: ਇਹ ਟੈਕਸਟ ਪੰਜਾਬੀ ਵਿੱਚ ਹੈ।
Русский: Этот текст на русском языке.
Svenska: Denna text är på svenska.
ไทย: ข้อความนี้อยู่ในไทย.
اردو: یہ متن اردو ہے.
中文: 这是中文。
IsiZulu: Lo mbhalo Zulu.
{{LangSelect | update = en
 | ar = هذا النص باللغة العربية.
 | da = Denne tekst er på dansk.
 | en = This text is English.
 | fa = این متن به زبان فارسی است.
 | fi = Tämä teksti on suomeksi.
 | fr = Ce texte est en français.
 | frc:FUZZY = Ce texte devrait être en français cajun.
 | he = טקסט כתוב בעברית.
 | hi = यह पाठ हिन्दी में है।
 | mr = हा मजकूर मराठीत आहे.
 | pa = ਇਹ ਟੈਕਸਟ ਪੰਜਾਬੀ ਵਿੱਚ ਹੈ।
 | ru = Этот текст на русском языке.
 | sv = Denna text är på svenska.
 | th = ข้อความนี้อยู่ในไทย.
 | ur = یہ متن اردو ہے.
 | zh = 这是中文。
 | zu = Lo mbhalo Zulu.
Dansk: Denne tekst er på dansk.
English: This text is English.
Français : Ce texte est en français.
Français cadien: Ce texte devrait être en français cajun. [update needed: en]
IsiZulu: Lo mbhalo Zulu.
Suomi: Tämä teksti on suomeksi.
Svenska: Denna text är på svenska.
Русский: Этот текст на русском языке.
हिन्दी: यह पाठ हिन्दी में है।
ਪੰਜਾਬੀ: ਇਹ ਟੈਕਸਟ ਪੰਜਾਬੀ ਵਿੱਚ ਹੈ।
ไทย: ข้อความนี้อยู่ในไทย.
中文: 这是中文。
עברית: טקסט כתוב בעברית.
اردو: یہ متن اردو ہے.
العربية: هذا النص باللغة العربية.
فارسی: این متن به زبان فارسی است.

The template {{LangSwitch}} is similar to {{LangSelect}}, except that it will display only one language (a specified language, or the language of the content of the current page).


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 translations (avoid this, it may hide as well the original source language) */
.multilingual { display:none; }
/* unhide only the selected languages */
.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|=fr] { display:block; }

If you want to hide only the language selection forms below multilingual sections (and use only the selector box added at top of pages), you may also use this CSS code:

/* hide the language selection form below multilingual sections */
.multilingual>form.lang_info { display:none; }

If instead you want to hide only the language selector box at top of pages (and keep the language selection forms below multilingual sections), you may also use this CSS code:

/* hide the language selector box at top of multilingual pages */
.langselectorcontainer { display:none; }


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.

Afrikaans: Hierdie teks is in Afrikaans.
Bahasa Indonesia: Ini adalah teks dalam bahasa Indonesia.
Bahasa Melayu: Teks ini ditulis dalam Bahasa Melayu.
Boarisch: Des is a boarischa Text.
Brezhoneg : Brezhoneg eo an destenn-mañ.
Català : Aquest text és en català.
Dansk: Denne tekst er på dansk.
Deutsch: Dieser Text ist Deutsch.
Eesti: See tekst on eesti keeles.
English: This text is English.
Español : Ese texto está en español.
Esperanto: Ĉi tiu teksto estas en Esperanto.
Français : Ce texte est en français.
Frysk: Dizze tekst is yn it Frysk.
Galego: Este texto está en galego.
Hrvatski: Ovaj tekst je na hrvatskom jeziku.
Interlingua: Iste texto es in interlingua.
Italiano: Questo testo è in Italiano.
Kiswahili: Haya ni maelezo ya Kiswahili.
Kurdî: Ev nivîs bi kurdî ye.
Latina: Haec nota latine scriptus est.
Lëtzebuergesch: Dësen Text ass op lëtzebuergesch
Lietuvių: Šis tekstas yra lietuviškas
Magyar: Ez a szöveg magyarul van
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.
Suomi: Tämä teksti on suomeksi.
Svenska: Denna text är på svenska.
Türkçe: Bu tekst Türkçe'dir.
Ελληνικά: Αυτό το κείμενο είναι στα Ελληνικά
Беларуская: Гэты тэкст — на беларускай мове.
Беларуская (тарашкевіца): Гэты тэкст — на беларускай мове.
Български: Този текст е на български език.
Македонски: Ова е текст на македонски јазик.
Русский: Этот текст — на русском языке.
Українська: Цей текст написано українською мовою.
ქართული: ეს ტექსტი ქართულ ენაზეა.
हिन्दी: यह पाठ हिन्दी में है।
বাংলা: এই বার্তাটি বাংলায়।
ਪੰਜਾਬੀ: ਇਹ ਟੈਕਸਟ ਪੰਜਾਬੀ ਵਿੱਚ ਹੈ।
ଓଡ଼ିଆ: ଏହି ଲେଖାଟି ଓଡ଼ିଆ ଭାଷାରେ ଲେଖାଯାଇଛି ।
தமிழ்: இது தமிழ் மொழி
ភាសាខ្មែរ៖ ឃ្លានេះជាភាសាខ្មែរ។
한국어: 이 글은 한국어입니다.
中文: 这些文字是中文。 / 這些文字是中文。
日本語: この文章は日本語です。
עברית: הטקסט הזה בעברית.
العربية: هذا النّص عربي.
فارسی: این متن فارسی است.
ئۇيغۇرچە / Uyghurche: بۇلار ئۇيغۇرچە

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

You can view the JavaScript code at Commons:MediaWiki:Multilingual description.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.

See also

External links