模板:LC zh

From Test Wiki
Revision as of 03:54, 24 January 2026 by Peterxy12 (talk | contribs) (Created page with "== 追踪分类 ==")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
模板文档

简要

此模板负责处理普通话(zh)页面标题和内容的语言转换(LC),尤其适用于带/不带命名空间名称(nsp参数)的页面标题,以及语言转换器页面与非语言转换器页面间的全部内容。

用法

每种内容类型的用法各不相同。

除非是特定的Wikitext语法(章节标题、列表),否则请勿将内容分割成碎片。

Green tickY {{LC zh|lang = {{{lang|}}}|type = C|zh-hans = 按需求配置。|zh-hant = 按需求设定组态。}}

N 按需求{{LC zh|lang = {{{lang|}}}|type = C|zh-hans = 配置|zh-hant = 设定组态}}

Green tickY {{LC zh|lang = {{{lang|}}}|type = C|zh-hans = '''按需求配置。'''|zh-hant = '''按需求设定组态。'''}}

N '''{{LC zh|lang = {{{lang|}}}|type = C|zh-hans = 按需求配置。|zh-hant = 按需求设定组态。}}'''

Green tickY == {{LC zh|lang = {{{lang|}}}|type = C|zh-hans = 按需求配置。|zh-hant = 按需求设定组态。}} ==

N {{LC zh|lang = {{{lang|}}}|type = C|zh-hans = == 按需求配置。 ==|zh-hant = == 按需求设定组态。 ==}}

N == 按需求{{LC zh|lang = {{{lang|}}}|type = C|zh-hans = 配置|zh-hant = 设定组态}}。 ==

Green tickY * {{LC zh|lang = {{{lang|}}}|type = C|zh-hans = 按需求配置。|zh-hant = 按需求设定组态。}}

N {{LC zh|lang = {{{lang|}}}|type = C|zh-hans = * 按需求配置。|zh-hant = * 按需求设定组态。}}

N * 按需求{{LC zh|lang = {{{lang|}}}|type = C|zh-hans = 配置|zh-hant = 设定组态}}

N - 命名空间名称

请勿在页面显示标题中使用此类型。

仅命名空间名称:

  • {{LC zh|lang = {{{lang|}}}|hide_ns = {{{nsp|}}}|type = N|ns = <英文中的命名空间名称>}}

包含伪命名空间名称:

  • {{LC zh|lang = {{{lang|}}}|hide_ns = {{{nsp|}}}|type = N|ns = <英文中的命名空间名称>|ns_2 = <英文中的伪命名空间名称>}}

示例:

  • {{LC zh|lang = {{{lang|}}}|hide_ns = {{{nsp|}}}|type = N|ns = Help}} → 帮助
  • {{LC zh|lang = {{{lang|}}}|hide_ns = {{{nsp|}}}|type = N|ns = Help|ns_2 = Extension}} → 帮助:扩展

T - 页面显示标题

在主命名空间的页面标题:

  • {{LC zh|lang = {{{lang|}}}|hide_ns = {{{nsp|}}}|type = T|ns = |zh-hans = <简体中文页面名称>|zh-hant = <繁体中文页面名称>}}

包含命名空间名称的页面标题:

  • {{LC zh|lang = {{{lang|}}}|hide_ns = {{{nsp|}}}|type = T|ns = <英文中的命名空间名称>|zh-hans = <简体中文页面名称>|zh-hant = <繁体中文页面名称>}}
  • {{LC zh|lang = {{{lang|}}}|hide_ns = {{{nsp|}}}|type = T|ns = <英文中的命名空间名称>|zh-hans = <简体中文页面名称>|zh-hant = <繁体中文(台湾)页面名称>|zh-hk = <繁体中文(香港)页面名称>}}

包含伪命名空间名称的页面标题:

  • {{LC zh|lang = {{{lang|}}}|hide_ns = {{{nsp|}}}|type = T|ns = <英文中的命名空间名称>|ns_2 = <英文中的伪命名空间名称>|zh-hans = <简体中文页面名称>|zh-hant = <繁体中文页面名称>}}
  • {{LC zh|lang = {{{lang|}}}|hide_ns = {{{nsp|}}}|type = T|ns = <英文中的命名空间名称>|ns_2 = <英文中的伪命名空间名称>|zh-hans = <简体中文页面名称>|zh-hant = <繁体中文(台湾)页面名称>|zh-hk = <繁体中文(香港)页面名称>}}

示例:

  • {{LC zh|lang = {{{lang|}}}|hide_ns = {{{nsp|}}}|type = T|ns = Project|zh-hans = 关于|zh-hant = 关于}} → 项目:关于

H - 章节标题

标题可以为不同的语言变体自动生成多个描点。

  • == {{LC zh|lang = {{{lang|}}}|type = H|zh-hans = <简体中文章节标题>|zh-hant = <繁体中文章节标题>}} ==
  • == {{LC zh|lang = {{{lang|}}}|type = H|zh-hans = <简体中文章节标题>|zh-hant = <繁体中文(台湾)章节标题>|zh-hk = <繁体中文(香港)章节标题>}} ==

示例:

  • == {{LC zh|lang = {{{lang|}}}|type = H|zh-hans = 关于|zh-hant = 关于}} == → == 关于 ==

C - 内容

  • {{LC zh|lang = {{{lang|}}}|type = C|zh-hans = <简体中文内容>|zh-hant = <繁体中文内容>}}
  • {{LC zh|lang = {{{lang|}}}|C|zh-hans = <简体中文内容>|zh-hant = <繁体中文(台湾)内容>|zh-hk =<繁体中文(香港)内容>}}

示例:

  • {{LC zh|lang = {{{lang|}}}|type = C|zh-hans = 关于|zh-hant = 关于}} → 关于

与其他模板和模块整合

注释

如果该模板属于用户页模板、全域公告等无法通过字词转换器转换的类型,建议使用Template:Conversion-zh 替代此模板。

模板数据

This is the TemplateData for this template used by TemplateWizard, VisualEditor and other tools. See a monthly parameter usage report for Template:LC zh in articles based on its TemplateData.

TemplateData for LC zh

<templatedata>{"paramOrder":["lang","hide_ns","type","ns","ns_2","zh-hans","zh-hant","zh-hk"],"description":"Language conversion template for Mandarin namespace names, page display titles, section headings and content. Only support zh-hans, zh-hant, zh-hk","params":{"ns_2":{"suggested":false,"type":"string","required":false,"label":"2nd English canonical namespace name","example":"Extension","description":"(type = N, T) The canonical name of the secondary pseudo-namespace in English. For example, \"Extension\" in \"Help:Extension:Example\"."},"type":{"suggested":false,"type":"string","required":true,"label":"内容类型","example":"T","description":"The content type, values: \"N\" - Namespace names - Do not use this type in page display title, \"T\" - Page display title, \"H\" - Section heading, \"C\" - Text content, \"U\" - Unconvertible content - Only use this type in unconvertible content, e.g., global announcements, syntax highlight blocks, system messages, user page templates. Aliases: \"1\".","autovalue":"C"},"zh-hk":{"suggested":false,"type":"content","default":"{{{zh-hant|{{{zh-hans|}}}}}}","label":"Mandarin - Traditional Han script, Hong Kong","description":"The text content in Mandarin - Traditional Han script, Hong Kong.","example":"Example_zh-Hant-HK","required":false},"hide_ns":{"suggested":false,"type":"boolean","required":false,"label":"是否隐藏命名空间前缀","example":"1","description":"(type = N, T) Whether to hide the namespace prefix (only apply to parameter \"ns\", does not affect parameter \"ns_2\"). Value is passed from the \"nsp\" parameter of Template:Localized link. Aliases: \"2\", \"nsp\".","autovalue":"{{{nsp|}}}"},"zh-hant":{"suggested":true,"type":"content","default":"{{{zh-hk|{{{zh-hans|}}}}}}","label":"Mandarin - Traditional Han script","description":"The text content in Mandarin - Traditional Han script.","example":"Example_zh-Hant","required":false},"zh-hans":{"suggested":true,"type":"content","default":"{{{zh-hant|{{{zh-hk|}}}}}}","label":"Mandarin - Simplified Han script","description":"The text content in Mandarin - Simplified Han script.","example":"Example_zh-Hans","required":false},"lang":{"suggested":false,"type":"string","required":false,"label":"输出语言/语言变体","example":"zh-hant","description":"要输出的语言/语言变体。(\"zh-hans\"、\"zh-hans\"、\"zh-hk\")","autovalue":"{{{lang|}}}"},"ns":{"suggested":false,"type":"string","required":false,"label":"English canonical namespace name","example":"Help","description":"(type = N, T) The canonical name of the namespace in English. Aliases: \"3\", \"namespace\"."}}}</templatedata>编辑参数翻译

测试样例

All tests passed.

test_main:

Text Expected Actual
Yes {{#invoke:LC zh|main}} An error Caught expected error: Lua error: Unknown content type code "nil".
Yes {{#invoke:LC zh|main|lang = {{{lang|}}}}} An error Caught expected error: Lua error: Unknown content type code "nil".
Yes {{#invoke:LC zh|main|lang = {{{lang|}}}|type = N}} An error Caught expected error: Lua error: Missing parameter "ns".
Yes {{#invoke:LC zh|main|lang = {{{lang|}}}|type = N|ns = }}
Yes {{#invoke:LC zh|main|lang = {{{lang|}}}|type = N|ns = User}} 用户 用户
Yes {{#invoke:LC zh|main|lang = {{{lang|}}}|type = N|ns = Help}} 帮助 帮助
Yes {{#invoke:LC zh|main|lang = {{{lang|}}}|type = T}} An error Caught expected error: Lua error: Require at least one of the parameter: "zh-hans", "zh-hant", "zh-hk".
Yes {{#invoke:LC zh|main|lang = {{{lang|}}}|type = T|ns = User}} An error Caught expected error: Lua error in Module:LC_zh at line 591: Require at least one of the parameter: "zh-hans", "zh-hant", "zh-hk".
Yes {{#invoke:LC zh|main|lang = {{{lang|}}}|type = T|ns = User|zh-hans = Example|zh-hant = Example}} 用户:Example 用户:Example
Yes {{#invoke:LC zh|main|lang = {{{lang|}}}|type = T|ns = Help|zh-hans = 示例|zh-hant = 范例}} 帮助:示例 帮助:示例
Yes {{#invoke:LC zh|main|lang = {{{lang|}}}|type = T|ns = Help|zh-hant = 范例}} 帮助:范例 帮助:范例
Yes {{#invoke:LC zh|main|lang = {{{lang|}}}|type = T|hide_ns = 1|ns = Help}} An error Caught expected error: Lua error: Require at least one of the parameter: "zh-hans", "zh-hant", "zh-hk".
Yes {{#invoke:LC zh|main|lang = {{{lang|}}}|type = T|hide_ns = 1|ns = Help|zh-hans = 示例|zh-hant = 范例}} 示例 示例
Yes {{#invoke:LC zh|main|lang = {{{lang|}}}|type = H}} An error Caught expected error: Lua error in Module:LC_zh at line 620: Require at least one of the parameter: "zh-hans", "zh-hant", "zh-hk".
Yes {{#invoke:LC zh|main|lang = {{{lang|}}}|type = H|zh-hans = 用户|zh-hant = 使用者|zh-hk = 用户}} 用户 用户
Yes {{#invoke:LC zh|main|lang = {{{lang|}}}|type = C}} An error Caught expected error: Lua error: Require at least one of the parameter: "zh-hans", "zh-hant", "zh-hk".
Yes {{#invoke:LC zh|main|lang = {{{lang|}}}|type=C|zh-hans=示例|zh-hant=范例}} 示例 示例

test_template:

Text Expected Actual
Yes {{LC zh}} An error Caught expected error: Lua error: Unknown content type code "nil".
Yes {{LC zh|lang = {{{lang|}}}}} An error Caught expected error: Lua error: Unknown content type code "nil".
Yes {{LC zh|lang = {{{lang|}}}|type = N}} An error Caught expected error: Lua error: Missing parameter "ns".
Yes {{LC zh|lang = {{{lang|}}}|type = N|ns = }}
Yes {{LC zh|lang = {{{lang|}}}|type = N|ns = User}} 用户 用户
Yes {{LC zh|lang = {{{lang|}}}|type = N|ns = Help}} 帮助 帮助
Yes {{LC zh|lang = {{{lang|}}}|type = T}} An error Caught expected error: Lua error: Require at least one of the parameter: "zh-hans", "zh-hant", "zh-hk".
Yes {{LC zh|lang = {{{lang|}}}|type = T|ns = User}} An error Caught expected error: Lua error in Module:LC_zh at line 591: Require at least one of the parameter: "zh-hans", "zh-hant", "zh-hk".
Yes {{LC zh|lang = {{{lang|}}}|type = T|ns = User|zh-hans = Example|zh-hant = Example}} 用户:Example 用户:Example
Yes {{LC zh|lang = {{{lang|}}}|type = T|ns = Help|zh-hans = 示例|zh-hant = 范例}} 帮助:示例 帮助:示例
Yes {{LC zh|lang = {{{lang|}}}|type = T|ns = Help|zh-hant = 范例}} 帮助:范例 帮助:范例
Yes {{LC zh|lang = {{{lang|}}}|type = T|hide_ns = 1|ns = Help}} An error Caught expected error: Lua error: Require at least one of the parameter: "zh-hans", "zh-hant", "zh-hk".
Yes {{LC zh|lang = {{{lang|}}}|type = T|hide_ns = 1|ns = Help|zh-hans = 示例|zh-hant = 范例}} 示例 示例
Yes {{LC zh|lang = {{{lang|}}}|type = H}} An error Caught expected error: Lua error in Module:LC_zh at line 620: Require at least one of the parameter: "zh-hans", "zh-hant", "zh-hk".
Yes {{LC zh|lang = {{{lang|}}}|type = H|zh-hans = 用户|zh-hant = 使用者|zh-hk = 用户}} 用户 用户
Yes {{LC zh|lang = {{{lang|}}}|type = C}} An error Caught expected error: Lua error: Require at least one of the parameter: "zh-hans", "zh-hant", "zh-hk".
Yes {{LC zh|lang = {{{lang|}}}|type=C|zh-hans=示例|zh-hant=范例}} 示例 示例

test_template_localized_link:

Text Expected Actual
Yes {{Localized link}} [[Special:MyLanguage/{{{1}}}|{{{1}}}]]<span style="display:none">[[:{{{1}}}| ]]</span> [[Special:MyLanguage/{{{1}}}|{{{1}}}]]<span style="display:none">[[:{{{1}}}| ]]</span>

test_template_localized_link_sandbox:

Text Expected Actual
Yes {{Localized link/sandbox}} [[Special:MyLanguage/{{{1}}}|{{{1}}}]]<span style="display:none">[[:{{{1}}}| ]]</span> [[Special:MyLanguage/{{{1}}}|{{{1}}}]]<span style="display:none">[[:{{{1}}}| ]]</span>

追踪分类