Template:Lang/doc: Difference between revisions

[checked revision][checked revision]
Content deleted Content added
m Text replacement - "[[HTML" to "[[Wikipedia:HTML"
No edit summary
 
(12 intermediate revisions by the same user not shown)
Line 5:
{{Commons Import}}
 
The purpose of this template is to indicate that a span of text belongs to a particular language. It often makes no visible changes to the text but can prompt [[Wikipedia:web browsers|web browsers]] to use a more appropriate font or screen readers to use a particular kind of pronunciation and so on. See {{section link||Rationale}} for more information.
 
== Syntax and usage ==
Line 11:
{{in5}}{{tlx|lang|{{var|language tag}}|{{var|text}}}}
 
The {{var|language tag}} should consist of an [[Wikipedia:Lists of ISO 639 codes|ISO 639]] language code. The template supports properly formatted [[Wikipedia:IETF language tag|IETF language tag]]s using subtags that identify the language's script, region, and/or variant. The ISO 639 language code is a two- or three-letter abbreviation, in lowercase, of the language's name. French, for example, has the code <code>fr</code>:
 
* <code><nowiki>She said: "{{lang|fr|Je suis française.}}"</nowiki></code> → She said: "{{lang|fr|Je suis française.}}"
 
Because all languages represented by two-letter codes in [[Wikipedia:ISO 639-1|ISO 639-1]] can also be represented by their three-letter equivalents in [[Wikipedia:ISO 639-2|ISO 639-2]] and above, it is recommended to use the shortest language tag possible that sufficiently describes the target language.<ref>[https://www.w3.org/International/articles/language-tags/index.en "Language tags in HTML and XML"] at [[Wikipedia:World Wide Web Consortium|]]</ref> So while French could be represented by 639‑2's <code>fra</code> code, use the 639‑1 code <code>fr</code> instead. Likewise, script, region, and variant information should be included only when they provide a necessary distinction. For an up-to-date list of available language, script, region, and variant codes, please refer to the [[Wikipedia:Internet Assigned Numbers Authority|IANA]]'s [http://www.iana.org/assignments/language-subtag-registry/language-subtag-registry language subtag registry].
 
By default, this template will place articles into the relevant subcategory of {{category link|Articles containing non-English-language text}}. To suppress this – e.g. when using {{tlf|lang}} within a [[Wikipedia:Help:Link#Wikilinks|wikilink]] or the ''title'' parameter of a citation – add the parameter {{para|nocat|true}}.
 
=== Formatting ===
Line 42:
=== Right-to-left languages ===
 
To embed a string of right-to-left text (such as [[Wikipedia:Arabic|Arabic]] or [[Wikipedia:Hebrew language|Hebrew]]) within the usual left-to-right context, {{para|rtl|yes}} should be added to correctly communicate writing direction. For convenience, the {{tl|rtl-lang}} template accomplishes the same result by automatically including {{para|rtl|yes}}. To markup a whole paragraph of right-to-left text, {{tl|rtl-para}} should be used instead.
 
Any of these approaches will wrap the text in a container with the <code>dir="rtl"</code> attribute. In order to ensure correct rendering in browsers that do not fully support [[Wikipedia:HTML5]] [[Wikipedia:bidirectional text|bidirectional isolation]], a [[Wikipedia:left-to-right mark|left-to-right mark]] is also added to the end of the text (see the [http://www.w3.org/International/articles/inline-bidi-markup W3C] for details).
 
Note that text direction does not need to be specified when using the {{tnull|lang-{{var|xx}}}} templates, as this is implied by the template's language. Therefore there is no {{tlf|rtl-lang-ar}}, only {{tl|lang-ar}}.
Line 52:
===the function selector parameter===
{{tlx|lang}} uses the Lua function <code>lang()</code> [[Module:Lang]]. That module also supports all of the {{tnull|lang-??}} templates using the Lua functions <code>lang_xx_inherit()</code> and <code>lang_xx_italic()</code>. The module has other functions that may be useful. The function selector parameter {{para|fn}} tells module:lang which function to execute. The available functions are:
*<code>is_ietf_tag</code> – returns <code>true</code> if the provided [[Wikipedia:IETF language tag|IETF language tag]] is valid; nil else
**<code><nowiki>{{lang|fn=is_ietf_tag|nv}}</nowiki></code> →{{lang|fn=is_ietf_tag|nv}}←
**<code><nowiki>{{lang|fn=is_ietf_tag|xx}}</nowiki></code> →{{lang|fn=is_ietf_tag|xx}}←
Line 72:
== Indicating writing script ==
 
If necessary, an [[Wikipedia:List of ISO 15924 codes|ISO 15924]] script code can be appended to a language code to indicate the use of a specific script. For instance, [[Wikipedia:Tajik language|Tajik]] (<code>tg</code>) is a language which can be found written in [[Wikipedia:Arabic script|Arabic]] (<code>Arab</code>), [[Wikipedia:Latin script|Latin]] (<code>Latn</code>), and [[Wikipedia:Cyrillic script|Cyrillic]] (<code>Cyrl</code>) scripts, making it necessary to always specify which script is in use. In such a case, taking care to preserve the script code's capitalization, we could end up with the following code (language tags in bold):
 
* <code><nowiki>Tajik ({{rtl-lang|</nowiki>'''tg-Arab'''<nowiki>|تاجیکی}}, ''{{lang|</nowiki>'''tg-Latn'''<nowiki>|toçikī}}'', {{lang|</nowiki>'''tg-Cyrl'''<nowiki>|тоҷикӣ}})</nowiki></code>
Line 81:
=== Transliteration ===
 
To mark a language which has been [[Wikipedia:transliteration|transliterated]] from one script into another, append the new script's code to the code of the original language. So if transliterating from Russian Cyrillic to a Latin script, the language tag on the transliteration would be <code>ru-Latn</code>. If the transliteration scheme is known, and listed as a "variant" in the [http://www.iana.org/assignments/language-subtag-registry/language-subtag-registry subtag registry], it can be appended after any script and region codes. For example, Chinese transliterated into a Latin script using the [[Wikipedia:pinyin|pinyin]] system would be <code>zh-Latn-pinyin</code>. As a convenience for transliterating to Latin scripts, and to work around browser styling issues with some language and script combinations, {{tl|transl}} may be used in place of {{tlf|lang}}:
 
* <code><nowiki>Moscow ({{lang|ru|Москва́}}, {{transl|ru|Moskva}})</nowiki></code>
: Moscow ({{lang|ru|Москва́}}, {{transl|ru|Moskva}})
 
To specify a transliteration scheme, such as the [[Wikipedia:ISO 9|ISO transliteration standard for Cyrillic]], use {{tlc|transl|ru|ISO|Moskva}}.
 
=== Undetermined language ===
 
The {{tlf|lang}} template is not only used to specify the language of foreign words, but can also be used to specify a single symbol or character in a script, unrelated to any specific language. Many times the character or symbol is used in several languages, but when the article refers to the [[wikipedia:grapheme|grapheme]] itself, the [[wikipedia:ISO 639‑2|ISO 639‑2]] language code <code>und</code>, for Undetermined language, should be used:
 
* <code><nowiki>The {{lang|und-Hani|字}} Han character has 6 strokes.</nowiki></code>
Line 104:
== Indicating regional variant ==
 
When it is necessary to indicate region-specific language, an [[wikipedia:ISO 3166-1 alpha-2|ISO 3166-1 alpha-2]] country code, or [[wikipedia:UN M49|UN M49]] region code, should be added to the language tag, taking care to preserve capitalization. For example, Portuguese (<code>pt</code>) as used in Brazil (<code>BR</code>) could be represented as <code>pt-BR</code>, and Spanish as used in Latin America as <code>es-419</code>.
 
Additionally, language, script, and region codes can all appear in the same tag. For instance, the code <code>zh-Hant-TW</code> should be used for Chinese text written with [[wikipedia:Traditional Chinese characters|Traditional Han characters]], containing words or expressions specific to [[wikipedia:Taiwan|Taiwan]]:
 
* <code><nowiki>Taiwan ({{lang|zh-Hant-TW|臺灣}}, {{transl|zh|Táiwān}})</nowiki></code>
Line 115:
{{section link|Wikipedia:Manual of Style/Text formatting|Foreign terms}} requires the use of {{tl|lang}} instead of manual <nowiki>''italics''</nowiki>. This is preferred for the following reasons:
 
* [[wikipedia:WWW|Web]] [[wikipedia:Web browser|browsers]] can use the information in such [[wikipedia:Category:Wikipedia multilingual support templates|multilingual support templates]] to choose an appropriate font.
** This is great for [[wikipedia:CJK characters|CJK]] where a character can be given its language-specific shape but will fall back to another form if no appropriate font is found or if the preferred font lacks that character, for example because the language does not make use of that character: see {{section link|wikipedia:Han unification|Examples of language-dependent glyphs}} and [[wikipedia:User:Wikipeditor/CJK|these comparison tables with a screenshot]].
* For [[wikipedia:web accessibility|accessibility]] – [[wikipedia:screen reader|screen reader]]s need language info to speak text in the correct language – and to satisfy [[Wikipedia:Accessibility#Text|Wikipedia accessibility guidelines]].<ref>{{cite web|url=https://developer.yahoo.com/blogs/ydn/yahoo-search-results-now-natural-language-support-7318.html|title=Yahoo! search results now with natural language support|date=13 Mar 2008|first= Chris |last= Heilmann|work=[[wikipedia:Yahoo! Developer Network|]] Blog|accessdate=28 Feb 2015|archiveurl=https://web.archive.org/web/20090125024422/http://developer.yahoo.net/blog/archives/2008/03/yahoo_search_re.html|archivedate=25 Jan 2009|url-status=dead}}</ref>
* For [[wikipedia:spell checker|spell checker]]s and grammar checkers, to match the text to the dictionary and syntax of the correct language.
* To help browsers choose appropriate [[wikipedia:quotation mark|quotation mark]]s,<ref name="qa-lang-why">{{cite web|url=http://www.w3.org/International/questions/qa-lang-why|title=Why use the language attribute?|date=18 November 2014|first= Richard |last= Ishida | publisher=World Wide Web Consortium | issue=Previously by Deborah Cawkwell, BBC World Service|accessdate=1 Mar 2015}}</ref> and make decisions about [[wikipedia:Hyphen|hyphenation]],<ref name="qa-lang-why"/> [[wikipedia:orthographic ligature|ligature]]s,<ref>{{cite web|url=http://www.w3.org/TR/css3-fonts/#font-variant-ligatures-prop|title=6.4 Ligatures: the font-variant-ligatures property|work=CSS Fonts Module Level 3 W3C Candidate Recommendation 3 October 2013}}</ref> and spacing.<ref name="qa-lang-why"/>
* Users can apply styles to languages in their [[wikipedia:style sheet (web development)|style sheet]]s (useful for editors).
* [[wikipedia:Web search engine|Search engine]]s can use this information when [[wikipedia:search engine indexing|indexing]] text.
* Facilitates better data-scraping, parsing and re-use.
* Useful for application developers who re-publish Wikipedia (also see {{section link|Wikipedia:Manual of Style/Accessibility|Other languages}}).
Line 128:
== Applying styles ==
 
Registered users can apply custom [[Wikipedia:Cascading Style Sheets|CSS]] styles to articles by placing style declarations in their user style sheet. The user style sheet can be created at [[Special:Mypage/common.css]]. For more information, see [[wikipedia:Help:User style|Help:User style]]. The following examples should work in most [[wikipedia:List of web browsers|modern browsers]], but not in [[wikipedia:Internet Explorer 8|Internet Explorer 8]] or earlier, which lack support for attribute selectors.
 
To apply a specific font to all text marked as Russian of any script or region:
Line 152:
If a font name contains characters besides basic Latin letters or hyphens, it is a good idea to enclose it in quotation marks because some such characters have special meanings (the most common case needing quotation marks is a multi-word font name with space characters). Quotation marks are also required for font families containing generic-family keywords ('inherit', 'serif', 'sans-serif', 'monospace', 'fantasy', and 'cursive'). See the [http://www.w3.org/TR/CSS21/fonts.html#font-family-prop W3C] for more details.
 
You can combine this with font imports in your user stylesheet, for example, to show all German text in [[wikipedia:Fraktur|Fraktur]] and all Urdu in [[wikipedia:Noto fonts|Noto]] [[wikipedia:Nastaʿlīq script|Nastaliq]] Urdu Regular:
 
<syntaxhighlight lang="css">
Line 181:
{{lang|ur|ٹھنڈ میں، ایک قحط زدہ گاؤں سے گزرتے وقت ایک چڑچڑے، بااثر و فارغ شخص کو بعض جل پری نما اژدہے نظر آئے۔}}
</pre>
 
{{Wide image|Pangrams in DE and UR in Arial, UnifrakturMaguntia and Noto Nastaliq Urdu.png|1000px}}
 
== Tracking categories ==
* {{Category link with count|Lang and lang-xx template errors}}
* {{Category link with count|Lang and lang-xx code promoted to ISO 639-1}}
 
== TemplateData ==