Jump to content

Language Converter/Advanced syntax: Difference between revisions

From mediawiki.org
Content deleted Content added
m Reverted edits by 151.132.2.57 (talk) to last version by Shirayuki
Tag: Rollback
Marked this version for translation
 
(36 intermediate revisions by 16 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 7: Line 8:
<translate><!--T:49--> This page describes special markups found in [[<tvar name=1>Special:MyLanguage/Writing systems#LanguageConverter</tvar>|LanguageConverter]], a system which converts between language variants via means of character/word replacement.</translate>
<translate><!--T:49--> This page describes special markups found in [[<tvar name=1>Special:MyLanguage/Writing systems#LanguageConverter</tvar>|LanguageConverter]], a system which converts between language variants via means of character/word replacement.</translate>
<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>

<translate><!--T:90--> Some example characters you can use for testing:</translate>

{| class="wikitable"
|+
! <translate><!--T:91--> TRADITIONAL</translate>
! <translate><!--T:92--> simplified</translate>
! <translate><!--T:93--> Transliteration<br> ([[w:Pinyin|Pinyin]])</translate>
! <translate><!--T:94--> Meaning</translate>
|-
|<span lang="zh-hant">氣</span>
|<span lang="zh-hans">气</span>
|<span lang="zh">qì</span>
| <translate><!--T:95--> ''air''</translate>
|-
|<span lang="zh-hant">馬</span>
|<span lang="zh-hans">马</span>
|<span lang="zh">mǎ</span>
| <translate><!--T:96--> ''horse''</translate>
|-
|<span lang="zh-hant">電</span>
|<span lang="zh-hans">电</span>
|<span lang="zh">diàn</span>
| <translate><!--T:97--> ''electricity''</translate>
|}


<translate>
<translate>
Line 12: Line 38:


<!--T:4-->
<!--T:4-->
LanguageConverter markups looks like:
<tvar name=1>LanguageConverter</tvar> markups looks like:
</translate>
</translate>


Line 22: 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 == <!--T:84-->

<!--T:85-->
The examples below use the following language codes:
</translate>
</translate>


{| class = "wikitable"
<translate><!--T:47--> Fallback among variants is available.</translate>
|-
<translate><!--T:76--> In the following examples designed for Chinese, <tvar name=1><code>zh-cn</code></tvar> and <tvar name=2><code>zh-sg</code></tvar> are variants written in the <tvar name=3><code>zh-hans</code></tvar> script, while <tvar name=4><code>zh-hk</code></tvar>, <tvar name=5><code>zh-mo</code></tvar> are variants written in the <tvar name=6><code>zh-hant</code></tvar> script.</translate>
! <translate><!--T:86--> [[w:IETF language tag|Code]]</translate>
<translate><!--T:77--> For example, according to the <tvar name=1><code>$variantfallbacks</code></tvar> definition in <tvar name=2><code>[https://doc.wikimedia.org/mediawiki-core/master/php/LanguageZh_8php_source.html LanguageZh.php]</code></tvar>, if no rules for <tvar name=3><code>zh-hk</code></tvar> were found, the converter would try using definitions for <tvar name=4><code>zh-hant</code></tvar>, <tvar name=5><code>zh-mo</code></tvar>, and <tvar name=6><code>zh-tw</code></tvar>.</translate>
! <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-hk||Hong Kong (Traditional)||<code>hk</code> is the [[:en:ISO_3166-1_alpha-2|ISO 3166-1 alpha-2]] code for Hong Kong, part of the [[:en:IETF_language_tag|BCP 47 language tag]].
|-
|zh-mo||Macau (Traditional)||<code>mo</code> is the [[:en:ISO_3166-1_alpha-2|ISO 3166-1 alpha-2]] code for Macau, part of the [[:en:IETF_language_tag|BCP 47 language tag]].
|-
|zh-my||Malaysia (Simplified)||<code>my</code> is the [[:en:ISO_3166-1_alpha-2|ISO 3166-1 alpha-2]] code for Malaysia, part of the [[:en:IETF_language_tag|BCP 47 language tag]].
|-
|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>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.

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.
{{CSS image crop
|Image = MediaWiki fallback chains.svg
|bSize = 1000
|cWidth = 400
|cHeight = 380
|oTop = 0
|oLeft = 550
|Location = right
|Description = Backup chain for MediaWiki language codes
|Alt = Backup chain for MediaWiki language codes
}}
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 [[wmdoc:mediawiki-core/master/php/ZhConverter_8php_source.html|<code>ZhConverter</code>]]<code>::getVariantsFallbacks()</code> the order of fallback variants is as follows:

{| class="wikitable"
! Language code !! colspan="3"| 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 <code>zh</code> are, in order: zh-hans, zh-hant, zh-cn, zh-tw, zh-hk, zh-sg, zh-mo, zh-my.
<translate><!--T:56--> In this example you may notice that <tvar name=1><code>zh-mo</code></tvar> and <tvar name=2><code>zh-sg</code></tvar> are absent from most examples.</translate>
<translate><!--T:78--> This is due to their high similarity to other variants, <tvar name=1><code>zh-hk</code></tvar> and <tvar name=2><code>zh-cn</code></tvar> respectively.</translate>


<translate>
<translate>
Line 38: Line 129:
{|class = "wikitable"
{|class = "wikitable"
|-
|-
! rowspan = 2 | <translate><!--T:8--> Name</translate>
!rowspan="2"| <translate><!--T:8--> Name</translate>
! rowspan = 2 width = 20% | <translate><!--T:9--> Description</translate>
!rowspan="2" width=20%| <translate><!--T:9--> Description</translate>
! colspan = 2 | <translate><!--T:10--> Example</translate>
!colspan="2"| <translate><!--T:10--> Example</translate>
! rowspan = 2 width = 15% | <translate><!--T:11--> Note</translate>
!rowspan="2" width=15%| <translate><!--T:11--> Note</translate>
|-
|-
! width = 30% | <translate><!--T:12--> Wikitext</translate>
! width=30%| <translate><!--T:12--> Wikitext</translate>
! <translate><!--T:13--> Output</translate>
! <translate><!--T:13--> Output</translate>
|-
|-
Line 49: Line 140:
| <translate><!--T:33--> Bidirectional conversion with [[<tvar name=1>#Conversion flags</tvar>|flag]] support.</translate> <translate><!--T:34--> Most common syntax in manual conversion.</translate>
| <translate><!--T:33--> Bidirectional conversion with [[<tvar name=1>#Conversion flags</tvar>|flag]] support.</translate> <translate><!--T:34--> Most common syntax in manual conversion.</translate>
|
|
<syntaxhighlight lang="wikitext">
-{{(}}zh-hans:computer; zh-hant:ELECTRONICBRAIN;{{)}}-
-{zh-cn:computer; zh-tw:ELECTRONICBRAIN;}-
</syntaxhighlight>
|
|
;zh, zh-hans, zh-cn, zh-sg
;zh, zh-hans, zh-cn, zh-my, zh-sg
:computer
:computer
;zh-hant, zh-tw, zh-hk, zh-mo
;zh-hant, zh-hk, zh-mo, zh-tw
:ELECTRONICBRAIN
:ELECTRONICBRAIN
|
|
Line 65: Line 158:
</translate>
</translate>
|
|
<syntaxhighlight lang="wikitext">
-{{(}}H|HUGEBLOCK=>zh-cn:macro;{{)}}-
Test: HUGEBLOCK, macro
-{H|HUGEBLOCK=>zh-cn:macro;}-
Test: HUGEBLOCK, macro
</syntaxhighlight>
|
|
;zh
;zh
:Test: HUGEBLOCK, Macro
:Test: HUGEBLOCK, Macro
;zh-hans, zh-sg
;zh-hans, zh-my, zh-sg
:test: hugeblock, macro
:test: hugeblock, macro
;zh-hant, zh-hk, zh-tw
;zh-hant, zh-hk, zh-mo, zh-tw
:TEST: HUGEBLOCK, MACRO
:TEST: HUGEBLOCK, MACRO
;zh-cn
;zh-cn
Line 81: Line 176:
| <translate><!--T:40--> Disable language conversion</translate>
| <translate><!--T:40--> Disable language conversion</translate>
|
|
<syntaxhighlight lang="wikitext">
-{{(}}SimpTrad{{)}}-
-{SimpTrad}-
&lt;!--<translate><!--T:58--> Alternatively, with the "R" flag: <tvar name=1>-{{(}}R|SimpTrad{{)}}</tvar>-</translate>--&gt;
</syntaxhighlight>
(<translate><!--T:58--> Alternatively, with the "R" flag: <tvar name=1><code>-{R|SimpTrad}-</code></tvar></translate>)
|
|
;(<translate><!--T:79--> all variants</translate>)
;(<translate><!--T:79--> all variants</translate>)
Line 93: Line 190:
<translate><!--T:59--> Useful for stopping erratic conversion by splitting words correctly.</translate>
<translate><!--T:59--> Useful for stopping erratic conversion by splitting words correctly.</translate>
|
|
<syntaxhighlight lang="wikitext">
HAN-{{(}}{{)}}-GUK, cho-{{(}}{{)}}-sun
HAN-{}-GUK, cho-{}-sun
</syntaxhighlight>


<translate><!--T:60--> (assuming there's a system-wide conversion rule between <tvar name=1><code>HANGUK</code></tvar> and <tvar name=2><code>chosun</code></tvar>)</translate>
<translate><!--T:60--> (assuming there's a system-wide conversion rule between <tvar name=1><code>HANGUK</code></tvar> and <tvar name=2><code>chosun</code></tvar>)</translate>
Line 99: Line 198:
;zh
;zh
:HANGUK, chosun
:HANGUK, chosun
;zh-hans, zh-cn, zh-sg
;zh-hans, zh-cn, zh-my, zh-sg
hanguk, chosun
:hanguk, chosun
;zh-hant, zh-hk, zh-tw
;zh-hant, zh-hk, zh-mo, zh-tw
:HANGUK, CHOSUN
:HANGUK, CHOSUN
| <translate><!--T:42--> There's another way to achieve this, which is more convenient in templates.</translate> <translate><!--T:43--> See "Combined conversion flag" below.</translate><br /><translate><!--T:44--> For example:</translate> <code>-{{(}}zh;zh-hans;zh-hant{{!}}HANGUK{{)}}- -{{(}}zh;zh-hans;zh-hant{{!}}chosun{{)}}-</code>
| <translate><!--T:42--> There's another way to achieve this, which is more convenient in templates.</translate> <translate><!--T:43--> See "Combined conversion flag" below.</translate><br /><translate><!--T:44--> For example:</translate> <code>-{{(}}zh;zh-hans;zh-hant{{!}}HANGUK}- -{zh;zh-hans;zh-hant{{!}}chosun}-</code>
|}
|}


{{anchor|Conversion flags}}
<translate>
<translate>
=== Conversion flags === <!--T:18-->
=== Conversion flags === <!--T:18-->
Line 112: 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>
<translate><!--T:100--> In some cases, however, it is desired to present words in the disambiguation [[w:Wikipedia:Hatnote|hatnote template]] from being transformed, in which case the rules should be placed below that.</translate>

{|class = "wikitable"
{|class = "wikitable"
|-
|-
! rowspan = 2 width = 3% | <translate><!--T:20--> Flag</translate>
!rowspan="2" width=3%| <translate><!--T:20--> Flag</translate>
! rowspan = 2 width = 15% | <translate><!--T:21--> Description</translate>
!rowspan="2" width=15%| <translate><!--T:21--> Description</translate>
! colspan = 2 | <translate><!--T:22--> Example</translate>
!colspan="2"| <translate><!--T:22--> Example</translate>
! rowspan = 2 width = 15% | <translate><!--T:23--> Note</translate>
!rowspan="2" width=15%| <translate><!--T:23--> Note</translate>
|-
|-
! width = 35% | <translate><!--T:24--> Wikitext</translate>
! width=35%| <translate><!--T:24--> Wikitext</translate>
! <translate><!--T:25--> Output</translate>
! <translate><!--T:25--> Output</translate>
|-
|-
Line 125: Line 227:
| <translate><!--T:61--> Insert a conversion rule without output</translate>
| <translate><!--T:61--> Insert a conversion rule without output</translate>
|
|
<syntaxhighlight lang="wikitext">
-{{(}}H|zh-cn:blog; zh-hk:WEBJOURNAL; zh-tw:WEBLOG;{{)}}-
Test: blog, WEBJOURNAL, WEBLOG
-{H|zh-cn:blog; zh-hk:WEBJOURNAL; zh-tw:WEBLOG;}-
Test: blog, WEBJOURNAL, WEBLOG
</syntaxhighlight>
|
|
;zh
;zh
Line 134: Line 238:
;zh-hant:
;zh-hant:
:TEST: BLOG, WEBJOURNAL, WEBLOG
:TEST: BLOG, WEBJOURNAL, WEBLOG
;zh-cn, zh-sg
;zh-cn, zh-my, zh-sg
:test: blog, blog, blog
:test: blog, blog, blog
;zh-hk:
;zh-hk, zh-mo:
:TEST: WEBJOURNAL, WEBJOURNAL, WEBJOURNAL
:TEST: WEBJOURNAL, WEBJOURNAL, WEBJOURNAL
;zh-tw
;zh-tw
:TEST: WEBLOG, WEBLOG, WEBLOG
:TEST: WEBLOG, WEBLOG, WEBLOG
| <translate><!--T:62--> zh-hans and zh-hant are simply scripts and won't apply bidirectional rules. See also the <tvar name=1><code>$manualLevel</code></tvar> parameter in LanguageConverter.</translate>
| <translate><!--T:62--> zh-hans and zh-hant are simply scripts and won't apply bidirectional rules. See also the <tvar name=1><code>$manualLevel</code></tvar> parameter in <tvar name=2>LanguageConverter</tvar>.</translate>
|-
|-
! A
! A
| <translate><!--T:45--> Insert a conversion rule with a result in the current language</translate>
| <translate><!--T:45--> Insert a conversion rule with a result in the current language</translate>
|
|
<syntaxhighlight lang="wikitext">
-{{(}}A|zh-cn:blog; zh-hk:WEBJOURNAL; zh-tw:WEBLOG;{{)}}-
-{{(}}zh-hans:&rarr;; zh-hant:&rArr;{{)}}-
-{A|zh-cn:blog; zh-hk:WEBJOURNAL; zh-tw:WEBLOG;}-
blog, WEBJOURNAL, WEBLOG
Test: blog, WEBJOURNAL, WEBLOG
</syntaxhighlight>
|
|
;zh
;zh
:blog &rarr; blog, WEBJOURNAL, WEBLOG
:blog
:Test: blog, WEBJOURNAL, WEBLOG
;zh-hans
;zh-hans
:blog &rarr; blog, webjournal, weblog
:blog
:test: blog, webjournal, weblog
;zh-hant
;zh-hant
:WEBLOG &rArr; BLOG, WEBJOURNAL, WEBLOG
:WEBLOG
:TEST: BLOG, WEBJOURNAL, WEBLOG
;zh-cn, zh-sg
;zh-cn, zh-my, zh-sg
:blog &rarr; blog, blog, blog
:blog
:test: blog, blog, blog
;zh-hk
;zh-hk, zh-mo
:WEBJOURNAL &rArr; WEBJOURNAL, WEBJOURNAL, WEBJOURNAL
:WEBJOURNAL
:TEST: WEBJOURNAL, WEBJOURNAL, WEBJOURNAL
;zh-tw
;zh-tw
:WEBLOG &rArr; WEBLOG, WEBLOG, WEBLOG
:WEBLOG
:TEST: WEBLOG, WEBLOG, WEBLOG
| <translate><!--T:63--> Compare the first (A) output with the one from H and flag-free operation.</translate>
| <translate><!--T:63--> Compare the first (A) output with the one from H and flag-free operation.</translate>
|-
|-
Line 166: Line 277:
| <translate><!--T:46--> Remove existing conversion rule</translate>
| <translate><!--T:46--> Remove existing conversion rule</translate>
|
|
<syntaxhighlight lang="wikitext">
-{{(}}H|zh-cn:blog; zh-hk:WEBJOURNAL; zh-tw:WEBLOG;{{)}}- &lt;!-- Add rule --&gt;
+ blog, WEBJOURNAL, WEBLOG
-{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;{{)}}- &lt;!-- Remove rule --&gt;
- blog, WEBJOURNAL, WEBLOG
-{-|zh-cn:blog; zh-hk:WEBJOURNAL; zh-tw:WEBLOG;}- <!-- Remove a rule -->
- blog, WEBJOURNAL, WEBLOG
</syntaxhighlight>
|
|
;zh
;zh
Line 181: Line 294:
:+ BLOG, WEBJOURNAL, WEBLOG
:+ BLOG, WEBJOURNAL, WEBLOG
:- BLOG, WEBJOURNAL, WEBLOG
:- BLOG, WEBJOURNAL, WEBLOG
;zh-cn, zh-sg
;zh-cn, zh-my, zh-sg
:+ blog, blog, blog
:+ blog, blog, blog
:- blog, webjournal, weblog
:- blog, webjournal, weblog
;zh-hk
;zh-hk, zh-mo
:+ WEBJOURNAL, WEBJOURNAL, WEBJOURNAL
:+ WEBJOURNAL, WEBJOURNAL, WEBJOURNAL
:- BLOG, WEBJOURNAL, WEBLOG
:- BLOG, WEBJOURNAL, WEBLOG
Line 195: Line 308:
| <translate><!--T:65--> Override page title</translate>
| <translate><!--T:65--> Override page title</translate>
|
|
<syntaxhighlight lang="wikitext">
-{{(}}T|zh-cn:tom hanks; zh-hk:SOUP HANS; zh-tw:TOM HANKS;{{)}}-
-{T|zh-cn:tom hanks; zh-hk:SOUP HANS; zh-tw:TOM HANKS;}-

</syntaxhighlight>
<translate><!--T:66--> (assuming the original title is "TomHanks")</translate>
<translate><!--T:66--> (assuming the original title is "TomHanks")</translate>
|<translate><!--T:67--> (shown as page title)</translate>
| <translate><!--T:67--> (shown as page title)</translate>
; zh ([[gerrit:19746]]): TomHanks
; zh ([[gerrit:19746]])
: TomHanks
; zh-hans, zh-cn, zh-sg: tom hanks
; zh-hans, zh-cn, zh-my, zh-sg
: tom hanks
; zh-hk: SOUP HANS
; zh-hant, zh-tw
; zh-tw: TOM HANKS
: TOM HANKS
; zh-hk, zh-mo
: SOUP HANS
|
|
|-
|-
Line 208: Line 326:
| <translate><!--T:68--> Describe conversion rule</translate>
| <translate><!--T:68--> Describe conversion rule</translate>
|
|
<syntaxhighlight lang="wikitext">
-{{(}}D|zh-cn:tom hanks; zh-hk:SOUP HANS; zh-tw:TOM HANKS{{)}}-
-{D|zh-cn:tom hanks; zh-hk:SOUP HANS; zh-tw:TOM HANKS}-
</syntaxhighlight>
|
|
;(all variants)
;(all variants)
:大陆:tom hanks;香港:SOUP HANS;臺灣:TOM HANKS;
:China: tom hanks; Hong Kong: SOUP HANS; Taiwan: TOM HANKS
| <translate><!--T:69--> Good for generating overviews in public conversion rule-groups.</translate>
| <translate><!--T:69--> Good for generating overviews in public conversion rule-groups.</translate>
|}
|}
Line 220: Line 340:
{|class = "wikitable"
{|class = "wikitable"
|-
|-
! rowspan = 2 width = 7% | <translate><!--T:27--> Flag</translate>
!rowspan="2" width=7%| <translate><!--T:27--> Flag</translate>
! rowspan = 2 width = 13% | <translate><!--T:28--> Description</translate>
!rowspan="2" width=13%| <translate><!--T:28--> Description</translate>
! colspan = 2 | <translate><!--T:29--> Example</translate>
!colspan="2"| <translate><!--T:29--> Example</translate>
! rowspan = 2 width = 12% | <translate><!--T:30--> Note</translate>
!rowspan="2" width=12%| <translate><!--T:30--> Note</translate>
|-
|-
! width = 37% | <translate><!--T:31--> Wikitext</translate>
! width=37%| <translate><!--T:31--> Wikitext</translate>
! <translate><!--T:32--> Output</translate>
! <translate><!--T:32--> Output</translate>
|-
|-
Line 231: Line 351:
| <translate><!--T:71--> Only consider certain variants for conversion</translate>
| <translate><!--T:71--> Only consider certain variants for conversion</translate>
|
|
<syntaxhighlight lang="wikitext">
-{{(}}H|zh-cn:blog; zh-hk:WEBJOURNAL; zh-tw:WEBLOG;{{)}}-
Test 1: -{{(}}zh;zh-hans;zh-hant|blog, WEBJOURNAL, WEBLOG{{)}}-
-{H|zh-cn:blog; zh-hk:WEBJOURNAL; zh-tw:WEBLOG;}-
Test 1:
Test 2: -{{(}}zh;zh-cn;zh-hk|blog, WEBJOURNAL, WEBLOG{{)}}-
-{zh;zh-hans;zh-hant|blog, WEBJOURNAL, WEBLOG}-


Test 2:
-{zh;zh-cn;zh-hk|blog, WEBJOURNAL, WEBLOG}-
</syntaxhighlight>
<translate><!--T:72--> (assuming this runs on a Chinese wiki)</translate>
<translate><!--T:72--> (assuming this runs on a Chinese wiki)</translate>
|
|
Line 241: Line 364:
:Test 1: blog, WEBJOURNAL, WEBLOG
:Test 1: blog, WEBJOURNAL, WEBLOG
:Test 2: blog, WEBJOURNAL, WEBLOG
:Test 2: blog, WEBJOURNAL, WEBLOG
;zh-hans
;zh-hans, zh-cn, zh-my, zh-sg
:test 1: blog, webjournal, weblog
:test 2: blog, blog, blog
;zh-hant, zh-tw
:TEST 1: BLOG, WEBJOURNAL, WEBLOG
:TEST 2: WEBLOG, WEBLOG, WEBLOG
;zh-cn, zh-sg
:test 1: blog, webjournal, weblog
:test 1: blog, webjournal, weblog
:test 2: blog, blog, blog
:test 2: blog, blog, blog
;zh-hk
;zh-hant, zh-hk, zh-mo, zh-tw
: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.</translate>
| <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

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
air
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.

Backup chain for MediaWiki language codes
Backup chain for MediaWiki language codes

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;}-
zh, zh-hans, zh-cn, zh-my, zh-sg
computer
zh-hant, zh-hk, zh-mo, 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
zh
Test: HUGEBLOCK, Macro
zh-hans, zh-my, zh-sg
test: hugeblock, macro
zh-hant, zh-hk, zh-mo, zh-tw
TEST: HUGEBLOCK, MACRO
zh-cn
test: macro, 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: -{R|SimpTrad}-)

(all variants)
SimpTrad
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 HANGUK and chosun)

zh
HANGUK, chosun
zh-hans, zh-cn, zh-my, zh-sg
hanguk, chosun
zh-hant, zh-hk, zh-mo, zh-tw
HANGUK, CHOSUN
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
Test: blog, WEBJOURNAL, WEBLOG
zh-hans
test: blog, webjournal, weblog
zh-hant
TEST: BLOG, WEBJOURNAL, WEBLOG
zh-cn, zh-my, zh-sg
test: blog, blog, blog
zh-hk, zh-mo
TEST: WEBJOURNAL, WEBJOURNAL, WEBJOURNAL
zh-tw
TEST: WEBLOG, WEBLOG, 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
zh
blog
Test: blog, WEBJOURNAL, WEBLOG
zh-hans
blog
test: blog, webjournal, weblog
zh-hant
WEBLOG
TEST: BLOG, WEBJOURNAL, WEBLOG
zh-cn, zh-my, zh-sg
blog
test: blog, blog, blog
zh-hk, zh-mo
WEBJOURNAL
TEST: WEBJOURNAL, WEBJOURNAL, WEBJOURNAL
zh-tw
WEBLOG
TEST: WEBLOG, WEBLOG, 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
zh
+ blog, WEBJOURNAL, WEBLOG
- blog, WEBJOURNAL, WEBLOG
zh-hans
+ blog, webjournal, weblog
- blog, webjournal, weblog
zh-hant
+ BLOG, WEBJOURNAL, WEBLOG
- BLOG, WEBJOURNAL, WEBLOG
zh-cn, zh-my, zh-sg
+ blog, blog, blog
- blog, webjournal, weblog
zh-hk, zh-mo
+ WEBJOURNAL, WEBJOURNAL, WEBJOURNAL
- BLOG, WEBJOURNAL, WEBLOG
zh-tw
+ WEBLOG, WEBLOG, WEBLOG
- 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)
zh (gerrit:19746)
TomHanks
zh-hans, zh-cn, zh-my, zh-sg
tom hanks
zh-hant, zh-tw
TOM HANKS
zh-hk, zh-mo
SOUP HANS
D Describe conversion rule
-{D|zh-cn:tom hanks; zh-hk:SOUP HANS; zh-tw:TOM HANKS}-
(all variants)
大陆:tom hanks;香港:SOUP HANS;臺灣: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)

zh
Test 1: blog, WEBJOURNAL, WEBLOG
Test 2: blog, WEBJOURNAL, WEBLOG
zh-hans, zh-cn, zh-my, zh-sg
test 1: blog, webjournal, weblog
test 2: blog, blog, blog
zh-hant, zh-hk, zh-mo, zh-tw
TEST 1: BLOG, WEBJOURNAL, WEBLOG
TEST 2: WEBJOURNAL, WEBJOURNAL, WEBJOURNAL
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]