Difference between revisions of "Template:Lang/doc"

From Department of Theoretical and Applied Mechanics
Jump to: navigation, search
(Created page with "{{documentation subpage}} The purpose of this template is to indicate that a given span of text belongs to a particular language (see language code). It often makes no visib...")
 
(Replaced content with "Hello!")
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
{{documentation subpage}}
+
Hello!
 
 
The purpose of this template is to indicate that a given span of text belongs to a particular language (see [[language code]]). It often makes no visible changes to the text, but can help web browsers choose the right font, screen readers use the right pronunciation and more, [[Template:Lang/doc#Rationale|as explained hereafter]].
 
 
 
<nowiki>{{</nowiki>lang|''Language tag''|''Text''}}
 
 
 
Use [[List of ISO 639 codes|ISO 639 language codes]]. Example (where <tt>fr</tt> is the code for [[French language|French]]):
 
 
 
<pre>
 
* She said: "''{{lang|fr|Je suis française.}}''"
 
</pre>
 
 
 
Results in your browser:
 
* She said: "''{{lang|fr|Je suis française.}}''"
 
 
 
By default, this template will place articles into the relevant subcategory of {{cl|Articles containing non-English-language text}}. To suppress this, for example when using the template inside a wikilink or the "title" parameter of a citation, add the parameter {{para|nocat|true}}. To reset the direction of text immediately following a string of right-to-left text, the {{tl|rtl-lang}} template may be used, which also supports the {{para|nocat}} parameter.
 
 
 
If appropriate, the entire wikilink may be fed to the template instead:
 
 
 
;Good
 
:<code><nowiki>{{lang|ar|[[Arabic language|العربية]]}}</nowiki></code>
 
;Bad
 
:<code><nowiki>[[Arabic language|{{lang|ar|العربية}}]]</nowiki></code>
 
 
 
There are also versions of this template for specific languages that also print the language's name, intended to be used the first time that language is used in the article. For example, {{j|"{{tlx|lang-es|español}}"}} and {{j|"{{tlx|lang-ru|русский язык}}"}} give "{{lang-es|español}}" and "{{lang-ru|русский язык}}".
 
 
 
Language subtags can also be used to indicate the writing script or regional variant of a language. According to the [[World Wide Web Consortium|W3C]], "the golden rule when creating language tags is to keep the tag as short as possible", [http://www.w3.org/International/articles/language-tags/Overview.en.php] so such subtags should only be added if there is an important reason to use them. [[ISO 639‑1]] is preferred over [[ISO 639‑2]] and [[ISO 639‑3]].
 
 
 
==Italics==
 
{{tlx|lang|xx}} outputs plain text by default. In {{tlx|lang-xx}}, the foreign-language text is italicised by default. If plain text is required, e.g. for proper names, {{tlx|noitalics}} may be used:
 
 
 
<pre>
 
* ... the border town of Ventimiglia ({{lang-fr|{{noitalics|Vintimille}}}})
 
</pre>
 
 
 
Gives:
 
* ... the border town of Ventimiglia ({{lang-fr|{{noitalics|Vintimille}}}})
 
 
 
== Indicating writing script ==
 
 
 
If necessary, add the [[List of ISO 15924 codes|ISO 15924]] code to indicate the script.
 
 
 
For example, [[Russian language|Russian]] is usually written in the [[Cyrillic script]], therefore the '<tt>Cyrl</tt>' script code is superfluous and the language code will be <tt>ru</tt> instead of <tt>ru-Cyrl</tt>. However, when that text is [[transliteration|transliterated]] the <tt>transl</tt> code (transliteration) should be used because it isn't the default script for Russian: <tt>ru-Latn</tt>.  Example:
 
 
 
<pre>
 
* Moscow ([[Russian language|Russian]]: {{lang|ru|Москва́}}, {{transl|ru|''Moskva''}})
 
</pre>
 
which is the same as
 
<pre>
 
* Moscow ({{lang-ru|Москва́}}, {{transl|ru|''Moskva''}})
 
</pre>
 
 
 
Results in your browser:
 
* Moscow ({{lang-ru|Москва́}}, {{transl|ru|''Moskva''}})
 
 
 
Instead of using <code><nowiki>{{transl|ru|''Moskva''}}</nowiki></code> the <code><nowiki>{{lang|ru-Latn|''Moskva''}}</nowiki></code> can be used, but if you specified a font and a size for the target language in your [[Special:Mypage/vector.css|custom CSS]] (see [[Help:User style]]), the transliteration will appear in that specified style. To specify a transliteration scheme, for example, you are using the [[ISO 9]] transliteration of Cyrillic, use <code><nowiki>{{transl|ru|ISO|''Moskva''}}</nowiki></code>:
 
* Moscow ({{lang-ru|Москва́}}; [[ISO 9]]: {{transl|ru|ISO|''Moskva''}})
 
 
 
The [[Internet Assigned Numbers Authority|IANA]] maintains a list specifying when the script tag should be suppressed [http://www.iana.org/assignments/language-subtag-registry]. In some cases, the script must be always specified, like [[Tajik language|Tajik]] which can be equally written in [[Arabic script|Arabic]], [[Latin script|Latin]] or [[Cyrillic script|Cyrillic]] alphabets:
 
<pre>
 
* Tajik ({{rtl-lang|tg-Arab|تاجیکی}}, {{transl|tg|''tojikī''}}, {{lang|tg-Cyrl|тоҷикӣ}})
 
</pre>
 
Which results in your browser:
 
* Tajik ({{rtl-lang|tg-Arab|تاجیکی}}, {{transl|tg|''tojikī''}}, {{lang|tg-Cyrl|тоҷикӣ}})
 
Note the use of {{tl|rtl-lang}} instead of {{tl|lang}} when using the Arabic script (see hereafter section [[#Writing direction|writing direction]]).
 
 
 
=== Undetermined language ===
 
 
 
The <nowiki>{{</nowiki>lang}} template is not only used to specify the language of foreign words, but also to specify a single symbol or character in a specific script, for example when discussing about a specific writing system. Many times the character / symbol is used in several languages, but when the article refers to the [[grapheme]] itself the [[ISO 639‑2]] and [[ISO 639‑3]] language code <tt>und</tt> for Undetermined language should be used. For example:
 
 
 
<pre>
 
The {{lang|und-Hani|字}} Han character has 6 strokes.
 
</pre>
 
:The {{lang|und-Hani|字}} Han character has 6 strokes.
 
 
 
 
 
Han characters are used in Chinese, Japanese, sometimes Korean, and formerly Vietnamese, and in this case the character is not used for any specific language. Note that the script code used is <tt>Hani</tt>, which specifies generic Han characters (Hanzi, Kanji, Hanja).
 
 
 
Compare {{tl|script}}
 
<pre>
 
The {{script|Hani|字}} Han character has 6 strokes.
 
</pre>
 
:The {{script|Hani|字}} Han character has 6 strokes.
 
 
 
== Indicating regional variant ==
 
 
 
In some cases, maybe it will be needed to add [[ISO 3166-1 alpha-2]] country codes (specific usage of that country). Of course the three codes can appear in the same tag, for example the code <tt>zh-Hant-TW</tt> will be used for [[Chinese language|Chinese]] text written with [[Traditional Chinese characters|Traditional Han characters]], containing words or expressions specific to [[Taiwan]]. <tt>zh-Hans</tt> is for simplified. Examples:
 
 
 
<pre>
 
* {{lang|zh-Hant-TW|臺灣}}
 
</pre>
 
 
 
Results in your browser:
 
* {{lang|zh-Hant-TW|臺灣}}
 
 
 
== Writing direction ==
 
 
 
{{tl|rtl-lang}} is used to wrap strings of right-to-left text (from languages like [[Arabic language|Arabic]] or [[Hebrew language|Hebrew]]) embedded in left-to-right text, and resets text direction to left-to-right at its conclusion. For whole paragraphs of right-to-left text, use {{tl|rtl-para}}.
 
 
 
== Rationale ==
 
 
 
* Web browsers can use the information in such [[:Category:multilingual support templates|multilingual support templates]] to choose an appropriate font.
 
** This is great for [[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 [[Han Unification#Examples of language dependent characters]] and [[User:Wikipeditor/CJK|this comparison table and screen photo]].
 
* For [[web accessibility|accessibility]] – [[screen reader]]s need language info to speak text in the correct language – and to satisfy [[Wikipedia:Accessibility#Text|Wikipedia accessibility guidelines]].
 
* For [[spell checker]]s and grammar checkers.
 
* To help browsers choosing appropriate [[quotation mark]]s, and making decisions about [[Hyphen|hyphenation]], [[Typographic ligature|ligature]]s, and spacing.
 
* Users can apply styles to languages in their [[Style sheet (web development)|style sheet]]s (useful for editors).
 
* [[Web search engine|Search engine]]s can use this information when [[index (search engine)|indexing]] text.
 
* Facilitates better data-scraping, parsing and re-use.
 
* Useful for application developers who re-publish Wikipedia (also see [[Wikipedia:Manual of Style/Accessibility#Other languages]]).
 
* Useful for research or compiling statistics about language use in Wikipedia.
 
 
 
== Applying styles ==
 
 
 
You can apply [[Cascading Style Sheets|CSS]] styles in your user style sheet. Registered users can put styles into User:XXX/monobook.css, where ''XXX'' is the user name. 
 
 
 
These examples may work in [[Internet Explorer 8]]; prior versions do not support attribute selectors. Alternatively, try [[List of web browsers|another browser]] such as [[Firefox]].
 
 
 
Example: to apply a font to Russian-language text:
 
 
 
  span[lang|=ru] { font-family: fonteskaya; }
 
 
 
Example: to apply a colour to text marked with any language:
 
 
 
  span[lang] { color: green; }
 
 
 
''Do not'' use quotation marks in your user style sheet; wikitext will screw them up. They are recommended in CSS, but not required other than for font families containing generic-family keywords ('inherit', 'serif', 'sans-serif', 'monospace', 'fantasy', and 'cursive'). See http://www.w3.org/TR/CSS21/fonts.html#font-family-prop for details.
 
 
 
==TemplateData==
 
{{TemplateDataHeader}}
 
<templatedata>{
 
"description": "Indicate that a given span of text belongs to a particular language. Use by browsers which use different styles for different languages.",
 
"params": {
 
  "1": {
 
    "label": "Language code",
 
    "description": "A language tag or an ISO 639 language code, e.g. fr (the code for French).",
 
    "type": "string",
 
    "required": true
 
  },
 
  "2": {
 
    "label": "Text",
 
    "description": "The text e.g. Je suis française.",
 
    "type": "string",
 
    "required": true
 
  }
 
}}</templatedata>
 
 
 
== See also ==
 
* [[:Category:Multilingual support templates]]
 
* [[List of ISO 639 codes]] (language codes)
 
* [[List of ISO 15924 codes]] (script codes)
 
* [[List of ISO romanizations|List of ISO transliterations]] (transliteration codes)
 
* {{Tl|Cleanup-lang}} – For articles which should use this template; but do not yet
 
* {{tl|transl}} for romanisation of languages not natively written in the Latin alphabet
 
* {{tl|Unicode}}, {{tl|script}} for specific characters
 
* [[:Category:Language icon templates]], for visually marking external links to foreign-language content
 
 
 
== References ==
 
* [[World Wide Web Consortium|W3C]]
 
** [http://www.w3.org/International/articles/language-tags/Overview.en.php Language tags in HTML and XML] – Overview
 
** [http://www.w3.org/TR/i18n-html-tech-lang/ Internationalization Best Practices: Specifying Language in XHTML & HTML Content] – W3C Working Draft 21 July 2006
 
** [http://www.w3.org/International/articles/bcp47/ Understanding the New Language Tags]
 
** [http://www.w3.org/International/questions/qa-css-lang FAQ: Styling using the lang attribute]
 
* [[Internet Assigned Numbers Authority|IANA]]
 
** [http://www.iana.org/assignments/language-subtag-registry IANA Language Subtag Registry]
 
** [http://www.rfc-editor.org/rfc/rfc4646.txt Tags for Identifying Languages] (RFC 4646)
 
** [http://www.rfc-editor.org/rfc/rfc4647.txt Matching of Language Tags] (RFC 4647)
 
** [http://www.iana.org/assignments/language-tags Language tags] (obsolete per RFC 4646)
 
* [[Mozilla Firefox]]
 
** [https://bugzilla.mozilla.org/show_bug.cgi?id=192636 Bug with script selection]
 
<includeonly>
 
<!-- ADD CATEGORIES AFTER THIS LINE -->
 
[[Category:Multilingual support templates|{{PAGENAME}}]]
 
</includeonly>
 

Latest revision as of 07:19, 13 May 2017

Hello!