Meta:Language select/it
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 (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).
Implementation
editThere 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
editPages 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.
-
Zscout370 proposal
-
Pathoschild proposal
-
"Globe of letters" proposal
Delimiting languages
editTechnical details
editA 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 or three-letterlanguage 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, Arabic, Old English, French, Latin, and Occitan:
<div class="multilingual"> <div class="lang-en" lang="en">This text is English.</div> <div class="lang-ar" lang="ar">هذا النّص عربي.</div> <div class="lang-fa" lang="fa">اين نوشته فارسي است.</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> </div>
Template
editThe 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>
Usage
editNote 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
editAdd 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;}
JavaScript
editThe 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 Commons:MediaWiki:Multilingual description.js.
Changelog
editThe 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 1999 — --DieBuche 10:34, 7 November 2010 (UTC)
- 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.
- If no cookie is present, code will sniff
- 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