Gaa na ọdịnaya

Module:Lang-zh

Shí Wikipedia, njikotá édémédé nke onyobulạ

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 = {}
 
-- articles in which traditional Chinese preceeds simplified Chinese
local t1st = {
	["228 Incident"] = true,
	["Bao'an County"] = true,
	["Chinese calendar"] = true,
	["Lippo Centre, Hong Kong"] = true,
	["Republic of China"] = true,
	["Republic of China at the 1924 Summer Olympics"] = true,
	["Taiwan"] = true,
	["Taiwan (island)"] = true,
	["Taiwan Province"] = true,
	["Wei Boyang"] = true,
}

-- the labels for each part 
local labels = {
	["c"] = "Chinese",
	["s"] = "simplified Chinese",
	["t"] = "traditional Chinese",
	["p"] = "pinyin",
	["tp"] = "Tongyong Pinyin",
	["w"] = "Wade–Giles",
	["j"] = "Jyutping",
	["cy"] = "Cantonese Yale",
	["poj"] = "Pe̍h-ōe-jī",
	["zhu"] = "Zhuyin Fuhao",
	["l"] = "literally",
}

-- article titles for wikilinks for each part
local wlinks = {
	["c"] = "Chinese language",
	["s"] = "simplified Chinese characters",
	["t"] = "traditional Chinese characters",
	["p"] = "pinyin",
	["tp"] = "Tongyong Pinyin",
	["w"] = "Wade–Giles",
	["j"] = "Jyutping",
	["cy"] = "Yale romanization of Cantonese",
	["poj"] = "Pe̍h-ōe-jī",
	["zhu"] = "Bopomofo",
}

-- for those parts which are to be treated as languages their ISO code
local ISOlang = {
	["c"] = "zh",
	["t"] = "zh-Hant",
	["s"] = "zh-Hans",
}
-- Categories for different kinds of Chinese text
local cats = {
	["c"] = "[[Category:Articles containing Chinese-language text]]",
	["s"] = "[[Category:Articles containing simplified Chinese-language text]]",
	["t"] = "[[Category:Articles containing traditional Chinese-language text]]",
}

function p.Zh(frame)
	local pframe = frame:getParent()
	local args = pframe.args
	return p._Zh(args)
end
	
function p._Zh(args)
	local no = args["links"] == "no" -- whether to add links
 
	local t1 -- whether traditional Chinese characters go first
	if (args["first"] == nil) then
		local title = mw.title.getCurrentTitle()
		t1 = t1st[title.text] == true
	else
		t1 = args["first"] == "t"
	end
	-- based on setting/preference specify order
	local orderlist
	if (t1) then
		orderlist = {"c", "t", "s", "p", "tp", "w", "j", "cy", "poj", "zhu", "l"}
	else
		orderlist = {"c", "s", "t", "p", "tp", "w", "j", "cy", "poj", "zhu", "l"}
	end
	
	-- rename rules. Rules to change parameters based on others
	-- hp an alias for p ([hanyu] pinyin)
	if args["hp"] then
		args["p"] = args["hp"]
	end
	-- if also Tongyu pinyin use full name for Hanyu pinyin
	if args["tp"] then
		labels["p"] = "Hanyu Pinyin"
	end
	
	-- Treat Simplified + Traditional as Chinese if they're the same
	if (args["s"] ~= "" and args["s"] == args["t"]) then
		args["c"] = args["s"]
		args["s"] = ""
		args["t"] = ""
	end

	local body = "" -- the output string
	local params -- for creating HTML spans

	-- go through all possible fields in loop, adding them to the output
	for i, part in ipairs(orderlist) do
		if (args[part]) then
			local val = args[part]
			local cat = ""
			if (val ~= "") then
				-- if has associated category add it
				if (cats[part]) then
					cat = cats[part]
				end
				if (ISOlang[part]) then -- add language if needed
					params = {["lang"] = ISOlang[part], ["xml:lang"] = ISOlang[part]}
					val = mw.text.tag({name="span",attrs=params, content=val})
				elseif (part == "p") then -- italicise pinyin
					val = "''" .. val .. "''"
				elseif (part == "l") then -- put literals in quotes
					val = '"' .. val .. '"'
				end
				-- build this entry
				if (no) or part == "l" then
					body = body .. labels[part] .. cat .. ": " .. val .. "; "
				else
					body = body .. "[[" .. wlinks[part] .. "|" .. labels[part] .. "]]" .. cat ..": " .. val .. "; "
				end
			end
		end
	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 = args[1]
		if (c) then
			if (c > "") then -- if there is treat it as Chinese
				params = {["lang"] = ISOlang["c"], ["xml:lang"] = ISOlang["c"]}
				c = mw.text.tag({name="span",attrs=params, content=c})
				return "[[" .. wlinks["c"] .. "|" .. labels["c"] .. "]]" .. cats["c"] .. ": " .. c
		end
	end
		return ""
	end
end

return p