Language Converter/Advanced syntax: Difference between revisions
Update to better character pairs suggested on zhwiki |
Marked this version for translation |
||
| (15 intermediate revisions by 8 users not shown) | |||
| Line 1: | Line 1: | ||
<languages/> |
<languages/> |
||
{{Under construction|2=Do not mark for translation. See [[:zh:Wikipedia:互助客栈/技术#Request for Translation of LanguageConverter documentation]] for discussions.}} |
|||
{{#ifeq:{{PAGELANGUAGE}}|zh |
{{#ifeq:{{PAGELANGUAGE}}|zh |
||
|{{softredirect|zh:Help:高级字词转换语法}} |
|{{softredirect|zh:Help:高级字词转换语法}} |
||
| Line 8: | Line 9: | ||
<translate><!--T:2--> In all examples below, characters in lowercase are used to represent Simplified Chinese, and UPPERCASE ones represent Traditional Chinese.</translate> |
<translate><!--T:2--> In all examples below, characters in lowercase are used to represent Simplified Chinese, and UPPERCASE ones represent Traditional Chinese.</translate> |
||
Some example characters you can use for testing: |
<translate><!--T:90--> Some example characters you can use for testing:</translate> |
||
{| class="wikitable" |
{| class="wikitable" |
||
|+ |
|+ |
||
!TRADITIONAL |
! <translate><!--T:91--> TRADITIONAL</translate> |
||
!simplified |
! <translate><!--T:92--> simplified</translate> |
||
!Transliteration |
! <translate><!--T:93--> Transliteration<br> ([[w:Pinyin|Pinyin]])</translate> |
||
! <translate><!--T:94--> Meaning</translate> |
|||
([[:en:Pinyin|Pinyin]]) |
|||
!Meaning |
|||
|- |
|- |
||
|<span lang="zh-hant">氣</span> |
|||
|氣 |
|||
|<span lang="zh-hans">气</span> |
|||
|气 |
|||
|<span lang="zh">qì</span> |
|||
|qì |
|||
| <translate><!--T:95--> ''air''</translate> |
|||
|''air'' |
|||
|- |
|- |
||
|<span lang="zh-hant">馬</span> |
|||
|馬 |
|||
|<span lang="zh-hans">马</span> |
|||
|马 |
|||
|<span lang="zh">mǎ</span> |
|||
|mǎ |
|||
|''horse'' |
| <translate><!--T:96--> ''horse''</translate> |
||
|- |
|- |
||
|<span lang="zh-hant">電</span> |
|||
|號 |
|||
|<span lang="zh-hans">电</span> |
|||
|号 |
|||
|<span lang="zh">diàn</span> |
|||
|hào |
|||
| <translate><!--T:97--> ''electricity''</translate> |
|||
|''number'' |
|||
|} |
|} |
||
| Line 47: | Line 48: | ||
<!--T:5--> |
<!--T:5--> |
||
Where flags are described below, and variant names are language codes (like <tvar name=1><code>zh-cn</code></tvar> or <tvar name=2><code>zh-tw</code></tvar>). |
Where flags are described below, and variant names are language codes (like <tvar name=1><code>zh-cn</code></tvar> or <tvar name=2><code>zh-tw</code></tvar>). |
||
| ⚫ | |||
== Language codes == |
== Language codes == <!--T:84--> |
||
<!--T:85--> |
|||
The examples below use the following language codes: |
The examples below use the following language codes: |
||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
|- |
|- |
||
! <translate><!--T:86--> [[w:IETF language tag|Code]]</translate> |
|||
![[:en:IETF_language_tag|Code]]!!Language!!Note |
|||
! <translate><!--T:87--> Language</translate> |
|||
! <translate><!--T:88--> Note</translate> |
|||
|- |
|- |
||
|zh || {{#language:zh|{{pagelang2}}}} |
|||
| |
| <translate><!--T:89--> "zh" is the initial consonant of the Mandarin pinyin for the character "中". (China is 中国, ''Zhōngguó''.)</translate> |
||
|- |
|- |
||
|zh-hans || {{#language:zh-hans|{{pagelang2}}}} |
|||
| ⚫ | | |
||
| <code>hans</code> is an [[w:ISO 15924|ISO 15924]] script code, part of the [[w:IETF language tag|BCP 47 language tag]]. "han" is the pinyin for the first character in 汉字 ''Hànzì'' (written in simplified characters) which is the autonym of the Chinese script, and "s" is the first letter of "Simplified Chinese". |
|||
|- |
|- |
||
|zh-hant || {{#language:zh-hant|{{pagelang2}}}} |
|||
| ⚫ | | |
||
| ⚫ | | <code>hant</code> is an [[:en:ISO_15924|ISO 15924]] script code, part of the [[:en:IETF_language_tag|BCP 47 language tag]]. "han" is the pinyin for the first character in 漢字 ''Hànzì'' (written in traditional characters) which is the autonym of the Chinese script, and "t" is the first letter of "Traditional Chinese". |
||
|- |
|- |
||
|zh-cn||Mainland China (Simplified)||<code>cn</code> is the [[:en:ISO_3166-1_alpha-2|ISO 3166-1 alpha-2]] code for mainland China, part of the [[:en:IETF_language_tag|BCP 47 language tag]]. |
|zh-cn||Mainland China (Simplified)||<code>cn</code> is the [[:en:ISO_3166-1_alpha-2|ISO 3166-1 alpha-2]] code for mainland China, part of the [[:en:IETF_language_tag|BCP 47 language tag]]. |
||
| Line 71: | Line 80: | ||
|zh-sg||Singapore (Simplified)||<code>sg</code> is the [[:en:ISO_3166-1_alpha-2|ISO 3166-1 alpha-2]] code for Singapore, part of the [[:en:IETF_language_tag|BCP 47 language tag]]. Malaysia and Singapore were originally covered by a combined variant. |
|zh-sg||Singapore (Simplified)||<code>sg</code> is the [[:en:ISO_3166-1_alpha-2|ISO 3166-1 alpha-2]] code for Singapore, part of the [[:en:IETF_language_tag|BCP 47 language tag]]. Malaysia and Singapore were originally covered by a combined variant. |
||
|- |
|- |
||
|zh-tw||Taiwan (Traditional)||<code> |
|zh-tw||Taiwan (Traditional)||<code>tw</code> is the [[:en:ISO_3166-1_alpha-2|ISO 3166-1 alpha-2]] code for Taiwan, part of the [[:en:IETF_language_tag|BCP 47 language tag]]. |
||
|} |
|} |
||
Each LanguageConverter in MediaWiki has a main language code, which serves as the default value when returning article text unmodified. If a language code does not have a fallback language code set, then the main language code is used as its fallback code. Each language version of Wikipedia defines a default language code; for wikis using language converter that default language code is the main language code of its LanguageConverter. |
Each LanguageConverter in MediaWiki has a main language code, which serves as the default value when returning article text unmodified. If a language code does not have a fallback language code set, then the main language code is used as its fallback code. Each language version of Wikipedia defines a default language code; for wikis using language converter that default language code is the main language code of its LanguageConverter. |
||
| Line 92: | Line 101: | ||
{| class="wikitable" |
{| class="wikitable" |
||
! Language code !! colspan="3" |
! Language code !! colspan="3"| Fallback codes |
||
|- |
|- |
||
| zh-hans || zh-cn || zh-sg || zh-my |
| zh-hans || zh-cn || zh-sg || zh-my |
||
| Line 120: | Line 129: | ||
{|class = "wikitable" |
{|class = "wikitable" |
||
|- |
|- |
||
! |
!rowspan="2"| <translate><!--T:8--> Name</translate> |
||
! |
!rowspan="2" width=20%| <translate><!--T:9--> Description</translate> |
||
! |
!colspan="2"| <translate><!--T:10--> Example</translate> |
||
! |
!rowspan="2" width=15%| <translate><!--T:11--> Note</translate> |
||
|- |
|- |
||
! width |
! width=30%| <translate><!--T:12--> Wikitext</translate> |
||
! <translate><!--T:13--> Output</translate> |
! <translate><!--T:13--> Output</translate> |
||
|- |
|- |
||
| Line 201: | Line 210: | ||
==== Common flags ==== <!--T:19--> |
==== Common flags ==== <!--T:19--> |
||
</translate> |
</translate> |
||
<translate><!--T:98--> Note that the actual effect of the inserted rules only takes place after the point where the rule is defined.</translate> |
|||
<translate><!--T:99--> Therefore it is recommended to place rules (for example, using the [[<tvar name="1">:zh:Template:NoteTA</tvar>|NoteTA template]]) at the beginning of the article and above any preface or infobox.</translate> |
|||
| ⚫ | |||
| ⚫ | |||
{|class = "wikitable" |
{|class = "wikitable" |
||
|- |
|- |
||
! |
!rowspan="2" width=3%| <translate><!--T:20--> Flag</translate> |
||
! |
!rowspan="2" width=15%| <translate><!--T:21--> Description</translate> |
||
! |
!colspan="2"| <translate><!--T:22--> Example</translate> |
||
! |
!rowspan="2" width=15%| <translate><!--T:23--> Note</translate> |
||
|- |
|- |
||
! width |
! width=35%| <translate><!--T:24--> Wikitext</translate> |
||
! <translate><!--T:25--> Output</translate> |
! <translate><!--T:25--> Output</translate> |
||
|- |
|- |
||
| Line 329: | Line 340: | ||
{|class = "wikitable" |
{|class = "wikitable" |
||
|- |
|- |
||
! |
!rowspan="2" width=7%| <translate><!--T:27--> Flag</translate> |
||
! |
!rowspan="2" width=13%| <translate><!--T:28--> Description</translate> |
||
! |
!colspan="2"| <translate><!--T:29--> Example</translate> |
||
! |
!rowspan="2" width=12%| <translate><!--T:30--> Note</translate> |
||
|- |
|- |
||
! width |
! width=37%| <translate><!--T:31--> Wikitext</translate> |
||
! <translate><!--T:32--> Output</translate> |
! <translate><!--T:32--> Output</translate> |
||
|- |
|- |
||
| Line 359: | Line 370: | ||
:TEST 1: BLOG, WEBJOURNAL, WEBLOG |
:TEST 1: BLOG, WEBJOURNAL, WEBLOG |
||
:TEST 2: WEBJOURNAL, WEBJOURNAL, WEBJOURNAL |
:TEST 2: WEBJOURNAL, WEBJOURNAL, WEBJOURNAL |
||
| <translate><!--T:73--> Compare test 1, test 2 and the usage case in H flag above. Used like the example in test 1, this feature can be used in situations where regional terminology conversion should be avoided, but simplified/traditional character conversion is allowed; for example the regional film titles in [[:zh:Template:Infobox Film]]. |
| <translate><!--T:73--> Compare test 1, test 2 and the usage case in H flag above.</translate> Used like the example in test 1, this feature can be used in situations where regional terminology conversion should be avoided, but simplified/traditional character conversion is allowed; for example the regional film titles in [[:zh:Template:Infobox Film]]. |
||
|} |
|} |
||
Latest revision as of 06:06, 5 July 2026
| This page is under construction Do not mark for translation. See zh:Wikipedia:互助客栈/技术#Request for Translation of LanguageConverter documentation for discussions. |
- Translated version of zh:Help:高级字词转换语法
This page describes special markups found in LanguageConverter, a system which converts between language variants via means of character/word replacement. In all examples below, characters in lowercase are used to represent Simplified Chinese, and UPPERCASE ones represent Traditional Chinese.
Some example characters you can use for testing:
| TRADITIONAL | simplified | Transliteration (Pinyin) |
Meaning |
|---|---|---|---|
| 氣 | 气 | qì | air |
| 馬 | 马 | mǎ | horse |
| 電 | 电 | diàn | electricity |
Concept
[edit | edit source]LanguageConverter markups looks like:
-{ text }--{ flag | variant1 : text1 ; variant2 : text2 ; }--{ flag1 ; flag2 | from => variant : to ; }-
Where flags are described below, and variant names are language codes (like zh-cn or zh-tw).
Language codes
[edit | edit source]The examples below use the following language codes:
| Code | Language | Note |
|---|---|---|
| zh | Chinese | "zh" is the initial consonant of the Mandarin pinyin for the character "中". (China is 中国, Zhōngguó.) |
| zh-hans | Simplified Chinese | hans is an ISO 15924 script code, part of the BCP 47 language tag. "han" is the pinyin for the first character in 汉字 Hànzì (written in simplified characters) which is the autonym of the Chinese script, and "s" is the first letter of "Simplified Chinese".
|
| zh-hant | Traditional Chinese | hant is an ISO 15924 script code, part of the BCP 47 language tag. "han" is the pinyin for the first character in 漢字 Hànzì (written in traditional characters) which is the autonym of the Chinese script, and "t" is the first letter of "Traditional Chinese".
|
| zh-cn | Mainland China (Simplified) | cn is the ISO 3166-1 alpha-2 code for mainland China, part of the BCP 47 language tag.
|
| zh-hk | Hong Kong (Traditional) | hk is the ISO 3166-1 alpha-2 code for Hong Kong, part of the BCP 47 language tag.
|
| zh-mo | Macau (Traditional) | mo is the ISO 3166-1 alpha-2 code for Macau, part of the BCP 47 language tag.
|
| zh-my | Malaysia (Simplified) | my is the ISO 3166-1 alpha-2 code for Malaysia, part of the BCP 47 language tag.
|
| zh-sg | Singapore (Simplified) | sg is the ISO 3166-1 alpha-2 code for Singapore, part of the BCP 47 language tag. Malaysia and Singapore were originally covered by a combined variant.
|
| zh-tw | Taiwan (Traditional) | tw is the ISO 3166-1 alpha-2 code for Taiwan, part of the BCP 47 language tag.
|
Each LanguageConverter in MediaWiki has a main language code, which serves as the default value when returning article text unmodified. If a language code does not have a fallback language code set, then the main language code is used as its fallback code. Each language version of Wikipedia defines a default language code; for wikis using language converter that default language code is the main language code of its LanguageConverter.
When the selected language code does not have any available display output, MediaWiki will attempt to fallback to another language code to obtain display output.
Similarly, when word conversion fails to find a full-text conversion for a certain language code, it will consult the rules for the fallback code to attempt to find a matching conversion.
According to ZhConverter::getVariantsFallbacks() the order of fallback variants is as follows:
| Language code | Fallback codes | ||
|---|---|---|---|
| zh-hans | zh-cn | zh-sg | zh-my |
| zh-hant | zh-tw | zh-hk | zh-mo |
| zh-cn | zh-hans | zh-sg | zh-my |
| zh-hk | zh-mo | zh-hant | zh-tw |
| zh-mo | zh-hk | zh-hant | zh-tw |
| zh-my | zh-sg | zh-hans | zh-cn |
| zh-sg | zh-my | zh-hans | zh-cn |
| zh-tw | zh-hant | zh-hk | zh-mo |
The main language code also has fallback codes. The fallback codes for zh are, in order: zh-hans, zh-hant, zh-cn, zh-tw, zh-hk, zh-sg, zh-mo, zh-my.
Syntax
[edit | edit source]Basic syntax
[edit | edit source]| Name | Description | Example | Note | |
|---|---|---|---|---|
| Wikitext | Output | |||
| Bidirectional | Bidirectional conversion with flag support. Most common syntax in manual conversion. |
-{zh-cn:computer; zh-tw:ELECTRONICBRAIN;}-
|
|
|
| Unidirectional | Unidirectional conversion with flag support. Primarily used for adding new conversion rules. Runs faster than bidirectional rules.
Mainly useful for unifying language variance and preventing erratic conversion. |
-{H|HUGEBLOCK=>zh-cn:macro;}-
Test: HUGEBLOCK, macro
|
|
Fallback is not supported in unidirectional conversion. For example, in the above example, zh-hans and zh-sg won't use zh-cn's rules. On the other hand, if the rule was inserted into zh-hans, it would only apply to zh-hans, but not zh-cn.
|
| Disabled | Disable language conversion |
-{SimpTrad}-
(Alternatively, with the "R" flag: |
|
This disables conversion completely. |
| (Semi-)disabled | Disable "word" conversion (breaking words apart, won't affect character transcription) Useful for stopping erratic conversion by splitting words correctly. |
HAN-{}-GUK, cho-{}-sun
(assuming there's a system-wide conversion rule between |
|
There's another way to achieve this, which is more convenient in templates. See "Combined conversion flag" below. For example: -{zh;zh-hans;zh-hant|HANGUK}- -{zh;zh-hans;zh-hant|chosun}-
|
Conversion flags
[edit | edit source]Common flags
[edit | edit source]Note that the actual effect of the inserted rules only takes place after the point where the rule is defined. Therefore it is recommended to place rules (for example, using the NoteTA template) at the beginning of the article and above any preface or infobox. In some cases, however, it is desired to present words in the disambiguation hatnote template from being transformed, in which case the rules should be placed below that.
| Flag | Description | Example | Note | |
|---|---|---|---|---|
| Wikitext | Output | |||
| H | Insert a conversion rule without output |
-{H|zh-cn:blog; zh-hk:WEBJOURNAL; zh-tw:WEBLOG;}-
Test: blog, WEBJOURNAL, WEBLOG
|
|
zh-hans and zh-hant are simply scripts and won't apply bidirectional rules. See also the $manualLevel parameter in LanguageConverter.
|
| A | Insert a conversion rule with a result in the current language |
-{A|zh-cn:blog; zh-hk:WEBJOURNAL; zh-tw:WEBLOG;}-
Test: blog, WEBJOURNAL, WEBLOG
|
|
Compare the first (A) output with the one from H and flag-free operation. |
| - | Remove existing conversion rule |
-{H|zh-cn:blog; zh-hk:WEBJOURNAL; zh-tw:WEBLOG;}- <!-- Add a rule -->
+ blog, WEBJOURNAL, WEBLOG
-{-|zh-cn:blog; zh-hk:WEBJOURNAL; zh-tw:WEBLOG;}- <!-- Remove a rule -->
- blog, WEBJOURNAL, WEBLOG
|
|
Compare test (+), test (-), and basic hans/hant |
| T | Override page title |
-{T|zh-cn:tom hanks; zh-hk:SOUP HANS; zh-tw:TOM HANKS;}-
(assuming the original title is "TomHanks") |
(shown as page title)
|
|
| D | Describe conversion rule |
-{D|zh-cn:tom hanks; zh-hk:SOUP HANS; zh-tw:TOM HANKS}-
|
|
Good for generating overviews in public conversion rule-groups. |
Combined conversion flag
[edit | edit source]| Flag | Description | Example | Note | |
|---|---|---|---|---|
| Wikitext | Output | |||
| variant name | Only consider certain variants for conversion |
-{H|zh-cn:blog; zh-hk:WEBJOURNAL; zh-tw:WEBLOG;}-
Test 1:
-{zh;zh-hans;zh-hant|blog, WEBJOURNAL, WEBLOG}-
Test 2:
-{zh;zh-cn;zh-hk|blog, WEBJOURNAL, WEBLOG}-
(assuming this runs on a Chinese wiki) |
|
Compare test 1, test 2 and the usage case in H flag above. Used like the example in test 1, this feature can be used in situations where regional terminology conversion should be avoided, but simplified/traditional character conversion is allowed; for example the regional film titles in zh:Template:Infobox Film. |
Exceptions
[edit | edit source]Language converter avoids converting anything found in "code" blocks like <pre>...</pre>, <code>...</code>, as well as the <script>...</script> tag used for carrying executable JavaScript.
Putting an empty conversion rule block -{}- inside these tags will function as a "force convert" switch for the converter.
This hack can be useful for code samples nested in these tags.
A caveat, however, is that this switch doesn't seem to work for the extension-provided <syntaxhighlight> tags which eventually generates a <pre>...</pre> nested with elements (T34943).
The switch also won't work with scripts not originally included with the page's HTML source that LC is designed to operate on.
MediaWiki messages are not processed by LC. This inconvenience is tracked in T170916.
See also
[edit | edit source]- Help:Magic words - for switches related to the converter
- Parsoid/Language conversion - which collects additional documentation relating to Language Conversion