Jump to content

书写系统/语法

From mediawiki.org
This page is a translated version of the page Writing systems/Syntax and the translation is 73% complete.

#REDIRECTzh: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.

概念

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

Fallback among variants is available. In the following examples designed for Chinese, zh-cn and zh-sg are variants written in the zh-hans script, while zh-hk, zh-mo are variants written in the zh-hant script. For example, according to the $variantfallbacks definition in LanguageZh.php, if no rules for zh-hk were found, the converter would try using definitions for zh-hant, zh-mo, and zh-tw.

In this example you may notice that zh-mo and zh-sg are absent from most examples. This is due to their high similarity to other variants, zh-hk and zh-cn respectively.

语法

基本语法

称谓 功能 示例 备注
源码 输出结果
双向转换 实现双向转换,可带有转换标签, 为手动转换语法中最常用的功能
computer
zh, zh-hans, zh-cn, zh-sg
computer
zh-hant, zh-tw, zh-hk, zh-mo
ELECTRONICBRAIN
单向转换 实现单向转换,可带有转换标签, 主要用于新增全文转换规则,比双向转换效率高

Mainly useful for unifying language variance and preventing erratic conversion.

Test: HUGEBLOCK, macro
zh
Test: HUGEBLOCK, Macro
zh-hans, zh-sg
test: hugeblock, macro
zh-hant, zh-hk, zh-tw
TEST: HUGEBLOCK, MACRO
zh-cn
test: macro, macro
单向转换不带继承特性, 如左例中“zh-hans”和“zh-sg”并未使用zh-cn的用词。 使用zh-hans亦只会应用到“zh-hans”而不会应用“zh-cn”。
禁止字词转换 同时禁止繁简和地区词的转换
SimpTrad
<!--Alternatively, with the "R" flag: SimpTrad-->
(所有变体)
SimpTrad
这种写法将完全禁止字词转换,在某些场合(如只需禁止地区词转换)或不适用
禁止地区词转换 禁止被切断的地区词转换,但允许個別字之繁简转换
(breaking words apart, won't affect character transcription)

Useful for stopping erratic conversion by splitting words correctly.

HANGUK, chosun

(假定系统转换表中有“HANGUK”和“chosun”的对应规则)

zh
HANGUK, chosun
zh-hans, zh-cn, zh-sg

hanguk, chosun

zh-hant, zh-hk, zh-tw
HANGUK, CHOSUN
还有另一种组合转换标签的方式也可以实现同样的功能,并且便于在模板中使用, 详见后文
例如: HANGUK chosun

转换标签

常用标签

标签 功能 示例 备注
源码 输出结果
H 添加全文转换规则,并隐藏H转换文本
Test: blog, WEBJOURNAL, WEBLOG
zh
Test: blog, WEBJOURNAL, WEBLOG
zh-hans
test: blog, webjournal, weblog
zh-hant
TEST: BLOG, WEBJOURNAL, WEBLOG
zh-cn, zh-sg
test: blog, blog, blog
zh-hk
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 添加全文转换规则,并输出A转换解析文本
blog
→
blog, WEBJOURNAL, WEBLOG
zh
blog → blog, WEBJOURNAL, WEBLOG
zh-hans
blog → blog, webjournal, weblog
zh-hant
WEBLOG ⇒ BLOG, WEBJOURNAL, WEBLOG
zh-cn, zh-sg
blog → blog, blog, blog
zh-hk
WEBJOURNAL ⇒ WEBJOURNAL, WEBJOURNAL, WEBJOURNAL
zh-tw
WEBLOG ⇒ WEBLOG, WEBLOG, WEBLOG
注意和H转换对比结果
- 移除全文转换规则
 <!-- Add rule -->
+ blog, WEBJOURNAL, WEBLOG

 <!-- Remove 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-sg
+ blog, blog, blog
- blog, webjournal, weblog
zh-hk
+ WEBJOURNAL, WEBJOURNAL, WEBJOURNAL
- BLOG, WEBJOURNAL, WEBLOG
zh-tw
+ WEBLOG, WEBLOG, WEBLOG
- BLOG, WEBJOURNAL, WEBLOG
Compare test (+), test (-), and basic hans/hant
T 强制覆盖页面原有标题

(假定页面原始标题为“TomHanks”)

(显示在页面标题处)
zh (gerrit:19746)
TomHanks
zh-hans, zh-cn, zh-sg
tom hanks
zh-hk
SOUP HANS
zh-tw
TOM HANKS
D 描述转换规则
大陆:tom hanks;香港:SOUP HANS;臺灣:TOM HANKS;
(all variants)
China: tom hanks; Hong Kong: SOUP HANS; Taiwan: TOM HANKS
Good for generating overviews in public conversion rule-groups.

组合转换标签

标签 功能 示例 备注
源码 输出结果
zh

zh-hans zh-hant zh-cn zh-hk zh-sg zh-tw

限制要顯示的語言的有效範圍。
Test 1: blog, WEBJOURNAL, WEBLOG

Test 2: blog, WEBJOURNAL, WEBLOG

(假定这是在中文维基中运行的)

zh
Test 1: blog, WEBJOURNAL, WEBLOG
Test 2: blog, WEBJOURNAL, WEBLOG
zh-hans
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 2: blog, blog, blog
zh-hk
TEST 1: BLOG, WEBJOURNAL, WEBLOG
TEST 2: WEBJOURNAL, WEBJOURNAL, WEBJOURNAL
除了测试1和测试2之間有差異外,跟上方使用 H 標籤作转换的例子之間也有差異

不转换的内容

自动转换程序会自动规避“程序码”类的标签,包括‎<pre>...‎</pre>‎<code>...‎</code>和用于直接执行JavaScript的‎<script>...‎</script>三种。 如果要将前两种用于条目内的程序范例,可以使用空转换标签-{}-强制启用转换。 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.

参见