SFHS Topmenu: Finlander | SFHS | Repository | Talko | DEE |

Meta:Language select


Jump to: navigation, search


File:Unlocalised stub template.gif
This is Template:Stub without language selection.
File:Localised stub template.gif
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 a French reader to see only French text on multilingual pages (though they would still see Spanish on a Spanish-only page).

At right are two screenshots of Template:Stub without and with a language selection of English and French using the CSS method (see below).



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 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-ar" lang="ar">هذا النّص عربي.</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>
<div class="lang-oc" lang="oc">Aqueste tèxt es en Occitan.</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.

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

Personal tools
blog comments powered by Disqus