Module:Lang-zh
Appearance
![]() | This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
![]() | This Lua module is used on approximately 80,000 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
![]() | This module depends on the following other modules: |
Usage
This is the module for the template {{Lang-zh}}. Its main features are described on that template's documentation page, refer to that for how to use it in articles. This documentation describes some particular features of the module.
The first table in the module lists the articles in which the template will put traditional Chinese first. Add articles to this list in the same fashion (the order doesn't matter) to include them. If you cannot edit the module because its protected use the {{edit template-protected}} template on its talk page to request a change.
Use from other modules
The module can be called directly from another module as well as a template. To do this first load the module
local Zh = require("Module:Lang-zh")._Zh
Then call it as follows, with the arguments in a table
local output = Zh{["c"] = "中国", ["p"] = "zhōngguó"}
Tracking categories
local p = {
language = require "Module:Language",
fr = {
args = {}
}
}
function p.getParent()
return p.fr
end
function p.Zh(frame)
-- Get the args. I don't know if there's a preferred way to do it but this works
local args = {}
local pframe = frame:getParent()
for k, v in pframe:argumentPairs() do
args[k] = v
end
local body = "" -- the output string
-- Get all the parameters into vars, or use "" if none is supplied (avoids seperate test for empty strings)
local c = args["c"] or ""
local s = args["s"] or ""
local t = args["t"] or ""
local hp = args["p"] or args["hp"] or ""
local tp = args["tp"] or ""
local w = args["w"] or ""
local j = args["j"] or ""
local cy = args["cy"] or ""
local poj = args["poj"] or ""
local zhu = args["zhu"] or ""
local l = args["l"] or ""
local no = args["links"] == "no"
local t1 = args["first"] == "t"
if (c > "" or (s > "" and s == t)) then -- if simplified and traditional the same they are merged into Chinese.
c = c or s
p.fr.args[1], p.fr.args[2] = "zh", c
c = p.language.lang(p)
if (no) then -- handle "links=no"
body = body .. "Chinese: " .. c .. "; "
else
body = body .. "[[Chinese language|Chinese]]: " .. c .. "; "
end
end
-- temporaries, used for reordering
local sOut, tOut = "", ""
if (s ~= t) then -- if they are the same should under Chinese
if (s > "") then
p.fr.args[1], p.fr.args[2] = "zh-Hans", s
s = p.language.lang(p)
if (t > "") then -- only display full name if traditional also appears
name = "simplified Chinese"
else
name = "Chinese"
end
if (no) then -- handle "links=no"
sOut = name .. ": " .. s .. "; "
else
sOut = "[[Simplified Chinese character|" .. name .."]]: " .. s .. "; "
end
end
if (t > "") then
p.fr.args[1], p.fr.args[2] = "zh-Hant", t
t = p.language.lang(p)
if (s > "") then -- only display full name if simplified also appears
name = "traditional Chinese"
else
name = "Chinese"
end
if (no) then -- handle "links=no"
tOut = name .. ":" .. t .. "; "
else
tOut = "[[Traditional Chinese character|" .. name .."]]: " .. t .. "; "
end
end
if (t1) then -- order based on "first=t"
body = body .. tOut .. sOut
else
body = body .. sOut .. tOut
end
end
sOut = ""
tOut = ""
if (hp > "") then
if (tp > "") then -- only display full name if Tongyo pinyin also appears
name = "Hanyu Pinyin"
else
name = "pinyin"
end
if (no) then -- handle "links=no"
sOut = name .. ": ''" .. hp .. "''; "
else
sOut = "[[pinyin|" .. name .. "]]: ''" .. hp .. "''; "
end
end
if (tp > "") then
if (no) then -- handle "links=no"
tOut = "Tongyong Pinyin: " .. tp .. "; "
else
tOut = "[[Tongyong Pinyin]]: " .. tp .. "; "
end
end
if (t1) then -- order based on "first=t"
body = body .. tOut .. sOut
else
body = body .. sOut .. tOut
end
if (w > "") then
if (no) then -- handle "links=no"
body = body .. "Wade-Giles: " .. w .. "; "
else
body = body .. "[[Wade-Giles]]: " .. w .. "; "
end
end
if (j > "") then
if (no) then -- handle "links=no"
body = body .. "Jyutping: " .. j .. "; "
else
body = body .. "[[Jyutping]]: " .. j .. "; "
end
end
if (cy > "") then
if (no) then -- handle "links=no"
body = body .. "Yale: " .. cy .. "; "
else
body = body .. "[[Yale romanization|Yale]]: " .. cy .. "; "
end
end
if (poj > "") then
if (no) then -- handle "links=no"
body = body .. "Pe̍h-ōe-jī: " ..poj .. "; "
else
body = body .. "[[Pe̍h-ōe-jī]]: " ..poj .. "; "
end
end
if (zhu > "") then
if (no) then -- handle "links=no"
body = body .. "Zhuyin Fuhao: " .. zhu .. "; "
else
body = body .. "[[Bopomofo|Zhuyin Fuhao]]: " .. zhu .. "; "
end
end
if (l > "") then
body = body .. "literally: \"" .. l .. "\"; "
end
if (body > "") then -- check for empty string
return string.sub(body, 1, -3) -- chop off final semicolon and space
else --no named parameters; see if there's an unnamed first parameter
c = pframe.args[1] or ""
if (c > "") then -- if there is treat it as Chinese
if (no) then -- handle "links=no"
return "Chinese: " .. c
else
return "[[Chinese language|Chinese]]: " .. c
end
end
return body
end
end
return p