![]() | This proposal is part of "A Dozen Visions for Wikitext". Shortcuts: Versioning - Grunge - Markdown - HTML-only wikis - Extension tag fragments - Syntax uniformity - Colon replacement - Backticks - Syntax for Discussions - #media - #lang - #balance - Long arguments - Variable-length/structured arguments - Annotations - Visual Templates - Page Description Language - Native Script Editing - One Wiki |
{{#lang}}
{{#lang}}
Current wikitext has a single “target language” per page, but many of our pages contain content in multiple languages. There are ways to manually set language and directionality in the output HTML, but they are cumbersome and often omitted. Language affects internal MediaWiki functions like the {{int}}
function and the operation of the Translate extension, and in non-Latin scripts it often affects font and glyph shaping. Broadly, “the letters don’t look right”” unless the language is correctly set. {{#lang}}
is a technical feature, but one that is very important for many world languages. In addition, we have many wikis which embed “user interface content” inside the content area, which is intended to be rendered in the user language not the page language. We don’t currently have a way of indicating this.
Here’s an example of a multilingual wiki, commons, with embedded content in English, Arabic, and “the user language”.
== {{int:filedesc}} ==
{{Information
|Description =
{{ar|1=صُورة [[:ar:أوروبا|لِأوروپَّا]] و[[:ar:أفريقيا|أفريقيا]] التقطتها كاميرا [[:ar:مرصد مناخ الفضاء العميق|مرصد مناخ الفضاء العميق]] التابع لِوكالة [[:ar:ناسا|ناسا]] يوم 29 تمُّوز (يوليو) 2015م.}}
{{en|1=
Africa and Europe from a Million Miles Away
...}}
{{es|1=Vista [[:es:Satélite artificial|satelital]] de [[:es:África|África]] y [[:es:Europa|Europa]] a una distancia de un millón de [[:es:milla|millas]].}}
}}
We can use {{#lang}}
with the special target x-user
to correctly set the language and directionality for this content in the user’s language:
== {{#lang:x-user|{{MediaWiki:filedesc}}}} ==
The {{ar}}
, {{en}}
, and {{es}}
templates can also use {{#lang}}
internally to ensure the parser’s target language is correctly set when processing its argument.
References blocks for non-European wikis are another extremely common case of multilingual content, since the citations are often to sources in European languages. The directionality can be a mess. Here is an example of using the {{#lang}}
function to correctly reset language and directionality for embedded English-language content inside a reference in a right-to-left language.
Note that we already have a parser function named {{#language}}
(which returns properties of a given language code) so {{#lang}}
may not be the best name for this functionality. It is likely to be wrapped within the preexisting templates named after language codes ({{ar}}
, {{en}}
, {{es}}
, etc) so having a short name may not be critical.
Next section: {{#balance}}