From Wikipedia, the free encyclopedia

require('strict')



local p = {}



-- articles in which traditional Chinese preceeds simplified Chinese

local t1st = {

	"228 Incident" = 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",

	"sl" = "Sidney Lau",

	"poj" = "Pe̍h-ōe-jī",

	"zhu" = "Zhuyin Fuhao",

	"l" = "lit.",

	"tr" = "trans.",

}



-- 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",

	"sl" = "Sidney Lau romanisation",

	"poj" = "Pe̍h-ōe-jī",

	"zhu" = "Bopomofo",

	"l" = "Literal translation",

	"tr" = "Translation",

}



-- for those parts which are to be treated as languages their ISO code

local ISOlang = {

	"c" = "zh",

	"t" = "zh-Hant",

	"s" = "zh-Hans",

	"p" = "zh-Latn",

	"tp" = "zh-Latn-tongyong",

	"w" = "zh-Latn-wadegile",

	"j" = "yue-Latn-jyutping",

	"cy" = "yue-Latn",

	"sl" = "yue-Latn",

	"poj" = "nan-Latn",

	"zhu" = "zh-Bopo",

}



local italic = {

	"p" = true,

	"tp" = true,

	"w" = true,

	"j" = true,

	"cy" = true,

	"sl" = true,

	"poj" = true,

}



local superscript = {

	"w" = true,

	"sl" = true,

}



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

	-- load arguments module to simplify handling of args

	local getArgs = require('Module:Arguments').getArgs

	

	local args = getArgs(frame)

	return p._Zh(args)

end

	

function p._Zh(args)

	if args"link" then args"links" = args"link"]; end

	if args"label" then args"labels" = args"label"]; end

		

	local uselinks = args"links" ~= "no" -- whether to add links

	local uselabels = args"labels" ~= "no" -- whether to have labels

	local capfirst = args"scase" ~= nil

	local out = nil -- which term to put before the brackets

	local usebrackets = 0 -- whether to have bracketed terms

	local numargs = 0

	

	if args"out" then

		out = args"out"

		usebrackets = 1

	end



	local t1 = false -- whether traditional Chinese characters go first

	local j1 = false -- whether Cantonese Romanisations go first

	local poj1 = false -- whether Hokkien Romanisations go first

	local testChar

	if (args"first"]) then

	 	 for testChar in mw.ustring.gmatch(args"first"], "%a+") do

			if (testChar == "t") then

				t1 = true

			end

			if (testChar == "j") then

				j1 = true

			end

			if (testChar == "poj") then

				poj1 = true

			end

		end

	end

	if (t1 == false) then

		local title = mw.title.getCurrentTitle()

		t1 = t1sttitle.text == true

	end



	-- based on setting/preference specify order

	local orderlist = {"c", "s", "t", "p", "tp", "w", "j", "cy", "sl", "poj", "zhu", "l", "tr"}

	if (t1) then

		orderlist2 = "t"

		orderlist3 = "s"

	end

	if (j1) then

		orderlist4 = "j"

		orderlist5 = "cy"

		orderlist6 = "sl"

		orderlist7 = "p"

		orderlist8 = "tp"

		orderlist9 = "w"

	end

	if (poj1) then

		orderlist4 = "poj"

		orderlist5 = "p"

		orderlist6 = "tp"

		orderlist7 = "w"

		orderlist8 = "j"

		orderlist9 = "cy"

		orderlist10 = "sl"

	end



	-- rename rules. Rules to change parameters and labels based on other parameters

	if args"hp" then

		-- hp an alias for p ([hanyu] pinyin)

		args"p" = args"hp"

	end

	if args"tp" then

		-- if also Tongyu pinyin use full name for Hanyu pinyin

		labels"p" = "Hanyu Pinyin"

	end

	

	if (args"s" and args"s" == args"t"]) then

		-- Treat simplified + traditional as Chinese if they're the same

		args"c" = args"s"

		args"s" = nil

		args"t" = nil

		if out == "s" or out == "t" then

			out = "c"

		end

	elseif (not (args"s" and args"t"])) then

		-- use short label if only one of simplified and traditional

		labels"s" = labels"c"

		labels"t" = labels"c"

	end

	if out then

		for i, v in ipairs (orderlist) do -- shift `out` to the beginning of the order list

			if v == out then

				table.remove(orderlist, i)

				table.insert(orderlist, 1, v)

				break

			end

		end

	end



	if (out == "c" and args"s"]) then usebrackets = 2; end



	local body = "" -- the output string

	local params -- for creating HTML spans

	local label -- the label, i.e. the bit preceeding the supplied text

	local val -- the supplied text

	

	-- go through all possible fields in loop, adding them to the output

	for i, part in ipairs(orderlist) do

		if (argspart]) then

			numargs = numargs + 1

			-- build label

			label = ""

			if (uselabels) then

				label = labelspart

				if (capfirst) then

					label = mw.language.getContentLanguage():ucfirst(label)

					capfirst = false

				end

				if (uselinks and part ~= "l" and part ~= "tr") then

					label = "[[" .. wlinkspart .. "|" .. label .. "]]"

				end

				if (part == "l" or part == "tr") then

					label = "<abbr title=\"" .. wlinkspart .. "\"><small>" .. label .. "</small></abbr>"

				else

					label = label .. "&colon;"

				end

				label = label .. " "

			end

			-- build value

			val = argspart

			if (catspart]) and mw.title.getCurrentTitle().namespace == 0 then

				-- if has associated category AND current page in article namespace, add category

				val = catspart .. val

			end

			if (ISOlangpart]) then

				-- add span for language if needed

				params = {["lang" = ISOlangpart]}

				val = mw.text.tag({name="span",attrs=params, content=val})

			elseif (part == "l") then

				local terms = ""

				-- put individual, potentially comma-separated glosses in single-quotes

				for term in val:gmatch("[^;,]+") do

					term = string.gsub(term, "^([ \"']*)(.*)([ \"']*)$", "%2")

					terms = terms .. "&apos;" .. term .. "&apos;, "

				end

				val = string.sub(terms, 1, -3)

			elseif (part == "tr") then

				-- put translations in double quotes

				val = "&quot;" .. val .. "&quot;"

			end

			if (italicpart]) then

				-- italicise

				val = "<i>" .. val .. "</i>"

			end

			if string.match(val, "</?sup>") then val = val.."[[Category:Pages using template Zh with sup tags]]" end

			if (superscriptpart]) then

				-- superscript

				val = val:gsub("(%d)", "<sup>%1</sup>"):gsub("(%d)</sup>%*<sup>(%d)", "%1*%2"):gsub("<sup><sup>([%d%*]+)</sup></sup>", "<sup>%1</sup>")

			end

			-- add both to body

			if numargs == usebrackets then

				-- opening bracket after the `out` term

				body = body .. label .. val .. " ("

			else

				body = body .. label .. val .. "; "

			end

		end

	end

	

	if (body > "") then -- check for empty string

		body = string.sub(body, 1, -3) -- chop off final semicolon and space

		if out and numargs > usebrackets then

			-- closing bracket after the rest of the terms

			body = body .. "&rpar;"

		end

		return body

	else --no named parameters; see if there's a first parameter, ignoring its name

		if (args1]) then

			-- if there is treat it as Chinese

			label = ""

			if (uselabels) then

				label = labels"c"

				if (uselinks) then

					label = "[[" .. wlinks"c" .. "|" .. label .. "]]"

				end

				label = label .. "&colon; "

			end

			-- default to show links and labels as no options given

			if mw.title.getCurrentTitle().namespace == 0 then

				-- if current page in article namespace

				val = cats"c" .. args1

			else

				val = args1

			end

			params = {["lang" = ISOlang"c"]}

			val = mw.text.tag({name="span",attrs=params, content=val})

			return label .. val

		end

		return ""

	end

end



return p
From Wikipedia, the free encyclopedia

require('strict')



local p = {}



-- articles in which traditional Chinese preceeds simplified Chinese

local t1st = {

	"228 Incident" = 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",

	"sl" = "Sidney Lau",

	"poj" = "Pe̍h-ōe-jī",

	"zhu" = "Zhuyin Fuhao",

	"l" = "lit.",

	"tr" = "trans.",

}



-- 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",

	"sl" = "Sidney Lau romanisation",

	"poj" = "Pe̍h-ōe-jī",

	"zhu" = "Bopomofo",

	"l" = "Literal translation",

	"tr" = "Translation",

}



-- for those parts which are to be treated as languages their ISO code

local ISOlang = {

	"c" = "zh",

	"t" = "zh-Hant",

	"s" = "zh-Hans",

	"p" = "zh-Latn",

	"tp" = "zh-Latn-tongyong",

	"w" = "zh-Latn-wadegile",

	"j" = "yue-Latn-jyutping",

	"cy" = "yue-Latn",

	"sl" = "yue-Latn",

	"poj" = "nan-Latn",

	"zhu" = "zh-Bopo",

}



local italic = {

	"p" = true,

	"tp" = true,

	"w" = true,

	"j" = true,

	"cy" = true,

	"sl" = true,

	"poj" = true,

}



local superscript = {

	"w" = true,

	"sl" = true,

}



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

	-- load arguments module to simplify handling of args

	local getArgs = require('Module:Arguments').getArgs

	

	local args = getArgs(frame)

	return p._Zh(args)

end

	

function p._Zh(args)

	if args"link" then args"links" = args"link"]; end

	if args"label" then args"labels" = args"label"]; end

		

	local uselinks = args"links" ~= "no" -- whether to add links

	local uselabels = args"labels" ~= "no" -- whether to have labels

	local capfirst = args"scase" ~= nil

	local out = nil -- which term to put before the brackets

	local usebrackets = 0 -- whether to have bracketed terms

	local numargs = 0

	

	if args"out" then

		out = args"out"

		usebrackets = 1

	end



	local t1 = false -- whether traditional Chinese characters go first

	local j1 = false -- whether Cantonese Romanisations go first

	local poj1 = false -- whether Hokkien Romanisations go first

	local testChar

	if (args"first"]) then

	 	 for testChar in mw.ustring.gmatch(args"first"], "%a+") do

			if (testChar == "t") then

				t1 = true

			end

			if (testChar == "j") then

				j1 = true

			end

			if (testChar == "poj") then

				poj1 = true

			end

		end

	end

	if (t1 == false) then

		local title = mw.title.getCurrentTitle()

		t1 = t1sttitle.text == true

	end



	-- based on setting/preference specify order

	local orderlist = {"c", "s", "t", "p", "tp", "w", "j", "cy", "sl", "poj", "zhu", "l", "tr"}

	if (t1) then

		orderlist2 = "t"

		orderlist3 = "s"

	end

	if (j1) then

		orderlist4 = "j"

		orderlist5 = "cy"

		orderlist6 = "sl"

		orderlist7 = "p"

		orderlist8 = "tp"

		orderlist9 = "w"

	end

	if (poj1) then

		orderlist4 = "poj"

		orderlist5 = "p"

		orderlist6 = "tp"

		orderlist7 = "w"

		orderlist8 = "j"

		orderlist9 = "cy"

		orderlist10 = "sl"

	end



	-- rename rules. Rules to change parameters and labels based on other parameters

	if args"hp" then

		-- hp an alias for p ([hanyu] pinyin)

		args"p" = args"hp"

	end

	if args"tp" then

		-- if also Tongyu pinyin use full name for Hanyu pinyin

		labels"p" = "Hanyu Pinyin"

	end

	

	if (args"s" and args"s" == args"t"]) then

		-- Treat simplified + traditional as Chinese if they're the same

		args"c" = args"s"

		args"s" = nil

		args"t" = nil

		if out == "s" or out == "t" then

			out = "c"

		end

	elseif (not (args"s" and args"t"])) then

		-- use short label if only one of simplified and traditional

		labels"s" = labels"c"

		labels"t" = labels"c"

	end

	if out then

		for i, v in ipairs (orderlist) do -- shift `out` to the beginning of the order list

			if v == out then

				table.remove(orderlist, i)

				table.insert(orderlist, 1, v)

				break

			end

		end

	end



	if (out == "c" and args"s"]) then usebrackets = 2; end



	local body = "" -- the output string

	local params -- for creating HTML spans

	local label -- the label, i.e. the bit preceeding the supplied text

	local val -- the supplied text

	

	-- go through all possible fields in loop, adding them to the output

	for i, part in ipairs(orderlist) do

		if (argspart]) then

			numargs = numargs + 1

			-- build label

			label = ""

			if (uselabels) then

				label = labelspart

				if (capfirst) then

					label = mw.language.getContentLanguage():ucfirst(label)

					capfirst = false

				end

				if (uselinks and part ~= "l" and part ~= "tr") then

					label = "[[" .. wlinkspart .. "|" .. label .. "]]"

				end

				if (part == "l" or part == "tr") then

					label = "<abbr title=\"" .. wlinkspart .. "\"><small>" .. label .. "</small></abbr>"

				else

					label = label .. "&colon;"

				end

				label = label .. " "

			end

			-- build value

			val = argspart

			if (catspart]) and mw.title.getCurrentTitle().namespace == 0 then

				-- if has associated category AND current page in article namespace, add category

				val = catspart .. val

			end

			if (ISOlangpart]) then

				-- add span for language if needed

				params = {["lang" = ISOlangpart]}

				val = mw.text.tag({name="span",attrs=params, content=val})

			elseif (part == "l") then

				local terms = ""

				-- put individual, potentially comma-separated glosses in single-quotes

				for term in val:gmatch("[^;,]+") do

					term = string.gsub(term, "^([ \"']*)(.*)([ \"']*)$", "%2")

					terms = terms .. "&apos;" .. term .. "&apos;, "

				end

				val = string.sub(terms, 1, -3)

			elseif (part == "tr") then

				-- put translations in double quotes

				val = "&quot;" .. val .. "&quot;"

			end

			if (italicpart]) then

				-- italicise

				val = "<i>" .. val .. "</i>"

			end

			if string.match(val, "</?sup>") then val = val.."[[Category:Pages using template Zh with sup tags]]" end

			if (superscriptpart]) then

				-- superscript

				val = val:gsub("(%d)", "<sup>%1</sup>"):gsub("(%d)</sup>%*<sup>(%d)", "%1*%2"):gsub("<sup><sup>([%d%*]+)</sup></sup>", "<sup>%1</sup>")

			end

			-- add both to body

			if numargs == usebrackets then

				-- opening bracket after the `out` term

				body = body .. label .. val .. " ("

			else

				body = body .. label .. val .. "; "

			end

		end

	end

	

	if (body > "") then -- check for empty string

		body = string.sub(body, 1, -3) -- chop off final semicolon and space

		if out and numargs > usebrackets then

			-- closing bracket after the rest of the terms

			body = body .. "&rpar;"

		end

		return body

	else --no named parameters; see if there's a first parameter, ignoring its name

		if (args1]) then

			-- if there is treat it as Chinese

			label = ""

			if (uselabels) then

				label = labels"c"

				if (uselinks) then

					label = "[[" .. wlinks"c" .. "|" .. label .. "]]"

				end

				label = label .. "&colon; "

			end

			-- default to show links and labels as no options given

			if mw.title.getCurrentTitle().namespace == 0 then

				-- if current page in article namespace

				val = cats"c" .. args1

			else

				val = args1

			end

			params = {["lang" = ISOlang"c"]}

			val = mw.text.tag({name="span",attrs=params, content=val})

			return label .. val

		end

		return ""

	end

end



return p

Videos

Youtube | Vimeo | Bing

Websites

Google | Yahoo | Bing

Encyclopedia

Google | Yahoo | Bing

Facebook