Module:User:TAKASUGI Shinji/zh/sandbox

Hello, you have come here looking for the meaning of the word Module:User:TAKASUGI Shinji/zh/sandbox. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:User:TAKASUGI Shinji/zh/sandbox, but we will also tell you about its etymology, its characteristics and you will know how to say Module:User:TAKASUGI Shinji/zh/sandbox in singular and plural. Everything you need to know about the word Module:User:TAKASUGI Shinji/zh/sandbox you have here. The definition of the word Module:User:TAKASUGI Shinji/zh/sandbox will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:User:TAKASUGI Shinji/zh/sandbox, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.


local M = {}

local m_data = mw.loadData('Module:zh/data')
local m_skeys = nil
local len = mw.ustring.len
local cmn_pron = nil

local py_detone={
	='a',='a',='a',='a',
	='o',='o',='o',='o',
	='e',='e',='e',='e',
	='i',='i',='i',='i',
	='u',='u',='u',='u',
	='ü',='ü',='ü',='ü'
};

local pos_aliases_title={
	='Noun', ='Proper noun', ='Proper noun', ='Pronoun', --things related to nouns
	='Verb', ='Adjective', ='Adjective', ='Adverb', --other main POSes
	='Preposition', ='Postposition', ='Conjunction', --sentence modifiers
	='Particle', ='Suffix', --word modifiers
	='Proverb', ='Idiom', ='Idiom', ='Idiom', ='Phrase', ='Interjection', --more than one word
	='Classifier', ='Numeral', ='Abbreviation', ='Determiner' --other
};

local pos_aliases_head={
	='noun', ='proper noun', ='proper noun', ='verb', ='adj', --main POSes
	='post', ='con', ='particle', ='pronoun', --sentence modifiers and word modifiers
	='proverb', ='idiom', ='idiom', ='idiom', ='phrase', ='interj', --more than one word
	='abbr', ='classifier', ='det' --other
};

local function replace_chars(s, tab)
	local output = {}
	for cp in mw.ustring.gcodepoint(s) do
		local ch = mw.ustring.char(cp)
		table.insert(output, tab or ch)
	end
	return table.concat(output)
end

function M.sortkey_conv(f)
	local rs = type(f) == 'table' and f.args or f
	local ch = mw.ustring.sub(rs,1,1)
	ch = m_data.sortkeys or ch
	return ch .. mw.ustring.sub(rs,2,mw.ustring.len(rs))
end

function M.py_detone(f)
	local text = type(f) == 'table' and f.args or f
	return replace_chars(text, py_detone)
end

function M.py_transf(f)
	local text = type(f) == 'table' and f.args or f
	if mw.ustring.match(text, '') then
		text = text .. '1'
	elseif mw.ustring.match(text, '') then
		text = text .. '2'
	elseif mw.ustring.match(text, '') then
		text = text .. '3'
	elseif mw.ustring.match(text, '') then
		text = text .. '4'
	end
	text = replace_chars(text, py_detone)
	return text
end

function M.tone_determ(f)
	local text = type(f) == 'table' and f.args or f
	if mw.ustring.match(text, '') then
		return '1'
	elseif mw.ustring.match(text, '') then
		return '2'
	elseif mw.ustring.match(text, '') then
		return '3'
	elseif mw.ustring.match(text, '') then
		return '4'
	else
		return '5'
	end
end

function M.ts_determ(f)
	local text = type(f) == 'table' and f.args or f
	for cp in mw.ustring.gcodepoint(text) do
		local ch = mw.ustring.char(cp)
		if m_data.ts then return 'trad' end
		if m_data.st then return 'simp' end
	end
	return 'both'
end

function M.ts(f)
	local text = type(f) == 'table' and f.args or f
	text = replace_chars(text, m_data.ts)
	return text
end

function M.st(f)
	local text = type(f) == 'table' and f.args or f
	text = replace_chars(text, m_data.st)
	return text
end

function M.py(text,comp,pos,p,is_erhua)
	if not is_erhua then is_erhua = false end
	if type(text) == 'table' then text,comp,pos,p,is_erhua = text.args,text.args,text.args,text.args,text.args end
	comp = comp or ''
	local q = {}
	local sum = 0
	textconv = M.ts(text)
	len = mw.ustring.len(text)
	if is_erhua then len = len - 1 end
	text = ''
	if comp ~= '' and comp ~= '12' and comp ~= '21' and not ((pos == 'cy' or pos == 'Idiom' or pos == 'idiom') and len == 4) and not is_erhua then
		for i = 1,mw.ustring.len(comp) do
			sum = sum + tonumber(mw.ustring.sub(comp,i,i))
			q = 'y'
		end
	end
	if not p then p={} end
	local initial = true
	for i = 1,len do
		if p and p ~= '' then --pronunciation supplied
			text = text .. p
		else
			local char = mw.ustring.sub(textconv,i,i)
			char = m_data.py or char
			if is_erhua or initial or not mw.ustring.find(char,'^') then
				text = text .. char
			else
				text = text .. "'" .. char
			end
			
			if char ~= mw.ustring.sub(textconv,i,i) then
				initial = false
			else
				initial = true
			end
		end
		if q == 'y' and i ~= len and not is_erhua then text = text .. ' ' end
	end
	if is_erhua == true then text = text .. 'r' end
	if pos == 'pn' or pos == 'propn' then
		characters = mw.text.split(text,' ')
		for i=1,#characters do
			characters = mw.language.getContentLanguage():ucfirst(characters)
		end
		text = table.concat(characters,' ')
	end
	return text
end

function M.py_er(text,comp,pos,p)
	return M.py(text,comp,pos,p,true)
end

function M.pytemp(text,comp,pos,p,is_erhua)
	if not is_erhua then is_erhua = false end
	if type(text) == 'table' then text,comp,pos = text.args,text.args,text.args or 'n' end
	comp = comp or ''
	local q = {}
	local sum = 0
	textconv = M.ts(text)
	len = mw.ustring.len(text)
	if is_erhua == true then
		len = len - 1
		textconv = mw.ustring.sub(textconv,1,len)
	end
	text = ''
	if comp ~= '' and comp ~= '12' and comp ~= '21' and not is_erhua then
		for i = 1,mw.ustring.len(comp) do
			sum = sum + tonumber(mw.ustring.sub(comp,i,i))
			q = 'y'
		end
	end
	if not p then p={} end
	for i = 1,len do
		if p and p ~= '' then --pronunciation supplied
			text = text .. p
		else
			local char = mw.ustring.sub(textconv,i,i)
			if mw.ustring.find(char,'') then
				text = text .. char
			else
				char = m_data.py or char
				if i ~= 1 and mw.ustring.find(char,'^') then
					char = "'" .. char
				end
				text = text .. char
			end
		end
		if q == 'y' and i ~= len and not is_erhua then text = text .. ' ' end
	end
	text = mw.ustring.gsub(text," '"," ")
	if pos == 'pn' or pos == 'propn' then
		characters = mw.text.split(text,' ')
		for i=1,#characters do
			characters = mw.language.getContentLanguage():ucfirst(characters)
		end
		text = table.concat(characters,' ')
	end
	return text
end

function M.pytemp_er(text,comp,pos,p)
	return M.pytemp(text,comp,pos,p,true)
end

function M.pywordconv(text,p)
	if type(text) == 'table' then text = text.args end
	textconv = M.ts(text)
	len = mw.ustring.len(text)
	text = ''
	if not p then p={} for i=1,20 do p='' end end
	for i = 1,len do
		if p ~= '' then
			text = text .. M.py_transf(p)
		else
			char = mw.ustring.sub(textconv,i,i)
			cpy = m_data.py or char
			text = text .. M.py_transf(cpy)
		end
	end
	return text
end

function M.pywordconv_er(text,p)
	if type(text) == 'table' then text = text.args end
	len = mw.ustring.len(text) - 1
	textconv = mw.ustring.sub(M.ts(text),1,len)
	text = ''
	if not p then p={} for i=1,20 do p='' end end
	for i = 1,len do
		if p ~= '' then
			if i == len then p = p .. 'r' end
			text = text .. M.py_transf(p)
		else
			char = mw.ustring.sub(textconv,i,i)
			cpy = m_data.py or char
			if i == len then cpy = cpy .. 'r' end
			text = text .. M.py_transf(cpy)
		end
	end
	return text
end

function M.decomp(text,comp)
	if type(text) == 'table' then text,comp = text.args,text.args or '' end
	comp = comp or tostring(mw.ustring.len(text))
	local num = tonumber(comp)
	char = mw.ustring.sub(text,num,num)
	return char
end

function M.compdecomp(title,comp)
	if type(title) == 'table' then title,comp = title.args,title.args end
	comp = comp or ''
	local start = 1
	local finish = 1
	local sum = 0
	local text = ''
	local p={}
	textlen = mw.ustring.len(title)
	if comp == '' then
		for i = 1,textlen do
			comp = comp .. '1'
		end
	end
	for i = 1,mw.ustring.len(comp) do
		p = tonumber(mw.ustring.sub(comp,i,i))
		sum = sum + p
	end
	if sum ~= textlen then
		comp = ''
		for j = 1,textlen do
			p = tonumber(1)
			comp = comp .. '1'
		end
	end
	for i = 1,mw.ustring.len(comp) do
		if i ~= 1 then start = start + p end
		finish = start + p - 1
		text = (text .. ']')
	end
	return text
end

function M.compdecompetym(title,comp)
	if type(title) == 'table' then title,comp = title.args,title.args end
	comp = comp or ''
	local start = 1
	local finish = 1
	local sum = 0
	local text = ''
	local p={}
	textlen = mw.ustring.len(title)
	if comp == '' then
		for i = 1,textlen do
			comp = (comp .. '1')
		end
	end
	for i = 1,mw.ustring.len(comp) do
		p = tonumber(mw.ustring.sub(comp,i,i))
		sum = sum + p
	end
	if sum ~= textlen then
		comp = ''
		for j = 1,textlen do
			p = tonumber(1)
			comp = (comp .. '1')
		end
	end
	for i = 1,mw.ustring.len(comp) do
		if i ~= 1 then start = start + p end
		finish = start + p - 1
		if i ~= 1 then text = (text .. '|') end
		text = (text .. mw.ustring.sub(title,start,finish))
	end
	return text
end

function M.hzbox(title,comp,e)
	if type(title) == 'table' then title,comp = title.args,title.args end
	local id = M.ts_determ(title)
	local text = '{{zh-forms'
	if e and e ~= "" then text = text .. '|' .. e end
	if id == 'simp' then
		text = text .. '|t=' .. M.st(title)
	elseif id == 'trad' then
		text = text .. '|s=' .. M.ts(title)
	end
	text = text .. ((comp and comp ~= "") and ('|type=' .. comp) or '')
	return text .. '}}'
end

function M.hzbox_er(title)
	if type(title) == 'table' then title = title.args end
	len = mw.ustring.len(title)
	if mw.ustring.sub(title,len,len) == '兒' then id = 'trad' else id = 'simp' end
	title = mw.ustring.sub(title,1,len-1)
	text = '{{zh-hanzi-box|'
	if id == 'simp' then
		text = (text .. ']]|]}}')
	else
		text = (text .. ']|]]}}')
	end
	return text
end

function M.sort(title)
	if type(title) == 'table' then title = title.args end
	local text = ''
	len = mw.ustring.len(title)
	title = M.ts(title)
	for i = 1,len do
		charpy = mw.ustring.sub(title,i,i)
		charpy = m_data.py or charpy
		text = text .. M.py_transf(charpy)
	end
	return text
end

function M.postitle(pos)
	pos = pos or ''
	if pos == '' then pos = 'n' end
	return pos_aliases_title or pos
end

function M.poshead(pos)
	pos = pos or ''
	if pos == '' then pos = 'n' end
	return pos_aliases_head or pos
end

function M.skeys(title)
	if m_skeys == nil then m_skeys = mw.loadData('Module:zh/data/skeys') end
	
	if type(title) == 'table' then title = title.args end
	text = mw.ustring.sub(title,1,1)
	text = m_skeys.skeys or text
	return text
end

function M.chardecomp(title)
	if type(title) == 'table' then title = title.args end
	text = mw.text.split(title,"")
	return table.concat(text,"|")
end

function M.semantics(text,name,sem)
	if sem and sem ~= '' then
		text = (text .. '\n\n====' .. name .. '====')
		if name == 'Derived terms' then
			text = text .. '\n{{zh-der'
			for i = 1, #sem do
				text = text .. '|' .. sem
			end
			text = text .. '}}'
		else
			for i = 1, #sem do
				text = text .. '\n* {{zh-l|' .. sem .. '}}'
			end
		end
	end
	return text
end

function M.create_er(f)
	return M.create(f,true)
end

local function checkpos(pos)
	for poscode,posname in pairs(pos_aliases_head) do
		if pos == posname then
			return poscode
		end
	end
	for poscode,posname in pairs(pos_aliases_title) do
		if pos == posname then
			return poscode
		end
	end
	return pos
end

function M.headword(title,comp,pos,is_erhua)
	if not is_erhua then is_erhua = false end
	is_table = (type(title) == 'table')
	p = {}
	for i=4,23 do table.insert(p,(is_table and title.args or '')) end
	if type(title) == 'table' then title,comp,pos = title.args,title.args,title.args end
	text = '{{zh-' .. M.poshead(pos) .. '|'
	id = M.ts_determ(title)
	if id == 'both' then text = text .. 'ts' elseif id == 'simp' then text = text .. 's' else text = text .. 't' end
	if is_erhua then
		text = text .. '|pin=' .. M.py_er(title,comp,pos,p) .. '|pint=' .. M.pywordconv_er(title,p)
		if id == 'simp' then
			text = text .. '|tra=' .. M.st(title) .. '|sim=' .. title
		else
			text = text .. '|tra=' .. title .. '|sim=' .. M.ts(title)
		end
		text = text .. '}}\n\n# {{erhua form'
		if def ~= '' then text = text .. '|' .. def end
	else
		text = text .. '|pin=' .. M.py(title,comp,pos,p) .. '|pint=' .. M.pywordconv(title,p)
		if id == 'simp' then
			text = text .. '|tra=' .. M.st(title) .. '|sim=' .. title
		elseif id == 'trad' then
			text = text .. '|tra=' .. title .. '|sim=' .. M.ts(title)
		end
	end
	return text .. '}}'
end

function M.link(frame,mention,args,pagename)
	args = args or frame:getParent().args
	pagename = pagename or mw.title.getCurrentTitle().text
	if args and mw.ustring.match(args, '') then
		gloss = args or ''
		tr = args or ''
		text = args .. '/' .. args
	else
		text = args or ''
		if not args or args == '' then
			if args and (mw.ustring.match(args, '') or mw.ustring.match(args, 'h?y???g?')) then
				tr = args or ''
				gloss = args or ''
			else
				tr = ''
				gloss = args or ''
			end
		else
			tr = args or ''
			gloss = args
		end
	end
	if args and args ~= '' then
		tr = args
		gloss = gloss or args or ''
	end
	if text ~= '' and not text:match(']') then
		word = mw.text.split(text,"/",true)
		if #word == 1 and M.ts_determ(word) == 'trad' and not mw.ustring.match(word, '%*') then
			table.insert(word, M.ts(word))
		end
		if tr == '' and word and mw.title.new(word).exists and text ~= pagename then
			content = mw.title.new(word):getContent()
			content = mw.ustring.gsub(content, ",()", ";%1")
			template = mw.ustring.match(content, "{{zh%-pron*|m=(+)")
			if template and template ~= "" then
				if cmn_pron == nil then
				   cmn_pron = require("Module:cmn-pron")
				end
				tr = cmn_pron.str_analysis(template, 'link')
			end
		end
		for i = 1,#word do
			word = mw.ustring.gsub(word, '%*', '')
			if mention then
				word = '<i class="Hani mention" lang="zh"> .. '#Chinese|' .. word .. ']]</i>'
--[[ (disabled to allow links to, for example, a link to 冥王星#Chinese from 冥王星#Japanese. 18 May, 2016)
			elseif word == pagename then
				word = '<span class="Hani" lang="zh"><b>' .. word .. '</b></span>'
]]
			else
				word = '<span class="Hani" lang="zh"> .. '#Chinese|' .. word .. ']]</span>'
			end
		end
		text = table.concat(word,"/")
	elseif text:match(']') or text == pagename then
		if mention then
			text = '<i class="Hani mention" lang="zh">' .. text .. '</i>'
		else
			text = '<span class="Hani" lang="zh">' .. text .. '</span>'
		end
	end
	if tr == '-' then
		tr = '' -- allow translit to be disabled: remove translit if it is "-", just like normal {{l}}
	end
	if tr ~= '' or gloss ~= '' then
		text = text .. ' ('
		if tr ~= '' then
			text = text .. '<span class="tr"><i>' .. tr .. '</i></span>'
			if gloss ~= '' then
				text = text .. ', '
			end
		end
		if gloss ~= '' then
			text = text .. '“' .. gloss .. '”'
		end
		text = text .. ')'
	end
	return text
end

function M.mention(frame)
	return M.link(frame,true)
end

function M.check_pron(text, variety, length, entry_creation)
	if type(text) == 'table' then text, variety = text.args, text.args end
	if not text then
		return
	end
	startpoint, address = {  = 51,  = 19968,  = 19968 }, {  = 'Jyutping_word/%03d',  = 'hak-pron/%02d',  = 'nan-pron/%03d' }
	unit = 1000
	first_char = mw.ustring.sub(text, 1, 1)
	codepoints = {  = mw.ustring.codepoint(first_char),  = mw.ustring.codepoint(M.st(first_char)) }
	texts = {  = text,  = M.st(text) }
	local result = false
	for identity, codepoint in pairs(codepoints) do
		if length == 1 and variety == "yue" then
			success, data = pcall(mw.loadData, 'Module:zh/data/Jyutping character')
		else
			page_index = math.floor((codepoint - startpoint) / unit)
			success, data = pcall(mw.loadData,
				('Module:zh/data/' .. address):format(page_index)
			)
		end
		if success then
			result = data] or false
		else
			result = false
		end
		if result then
			if variety == "nan" and entry_creation then
				result = mw.ustring.gsub(result, "%-á%-", "-仔-")
				result = mw.ustring.gsub(result, "%-á/", "-仔/")
				result = mw.ustring.gsub(result, "%-á$", "-仔")
				result = mw.ustring.gsub(result, "^(.+)%-%1%-%1$", "(%1)")
				result = mw.ustring.gsub(result, "^(.+)%-%1%-%1()", "(%1)%2")
				result = mw.ustring.gsub(result, "()(.+)%-%1%-%1$", "%1(%2)")
				result = mw.ustring.gsub(result, "()(.+)%-%1%-%1()", "%1(%2)%3")
			end
			return result
		end
	end
	return result
end

function M.nan_for_bot()
	text = mw.title.getCurrentTitle().text
	result = M.check_pron(text, 'nan')
	if result then
		return '\n|mn=' .. result
	else
		return
	end
end

function M.der(frame)
	local m_columns = require("Module:columns")
	local args = frame:getParent().args
	local pagename = mw.title.getCurrentTitle().text
	local result = {}
	for i, word in ipairs(args) do
		table.insert(result, M.link(frame,nil,{ word },pagename))
	end
	return m_columns.create_table((mw.ustring.len(pagename) > 1 and 2 or 3), result, 1, "#F5F5FF", (#result > 72 and 1 or 0), "Derived terms",
		"Derived terms from <span lang=\"zh\" class=\"Hani\">" .. pagename .. "</span>",
		math.floor(80 / (mw.ustring.len(pagename) > 1 and 2 or 3)), "* ", nil)
end

local lang_abbrev = {
	 = 'Mandarin',
	 = 'Cantonese',  = 'Gan',  = 'Hakka',  = 'Jin',
	 = 'Min Dong',  = 'Min Nan',  = 'Teochew',
	 = 'Wu',  = 'Xiang',
}

function M.cls(frame)
	local args = frame:getParent().args
	local result = {}
	for i, combination in ipairs(args) do
		part = mw.text.split(combination, ":")
		if #part == 2 then
			local dialect = { "" }
			local function annotate(main_text, annotation)
				return "<span style=\"border-bottom: 1px dotted #000; cursor:help\" " ..
					"title=\"" .. annotation .. "\"><i>" .. main_text .. "</i></span>"
			end
			for variety in mw.text.gsplit(part, ",") do
				table.insert(dialect, annotate(variety, lang_abbrev))
			end
			note = table.concat(dialect, " ")
		else
			note = false
		end
		table.insert(result, mw.getCurrentFrame():expandTemplate{ title = "Template:zh-l",
			args = { "*" .. (part or part) }, tr = "-" } .. (note or ""))
	end
	return "&nbsp;&nbsp;<small><span style=\"background:#EDFFFF\">(Classifier: " .. table.concat(result, "; ") .. ")</span></small>"
end

function M.newDer(frame)
	local title = mw.title.getCurrentTitle().text
	local wordlist = require("Module:zh/data/wordlist").list
	local args = frame:getParent().args
	local result = {}
	local limit = args and tonumber(args) or false
	args = nil
	for _, arg in ipairs(args) do
		table.insert(result, arg)
	end
	for _, word in ipairs(wordlist) do
		if mw.ustring.match(word, title) and word ~= title and not (len(title) == 1 and len(word) > (limit or 4)) then
			table.insert(result, word)
		end
	end
	local hash, res = {}, {}
	for _, element in ipairs(result) do
		if not hash then
			res = element
			hash = true
		end
	end
	return "{{zh-der|" .. table.concat(res, "|") .. "}}"
end

function M.create(f,is_erhua)
	if not is_erhua then is_erhua = false end
	local title = mw.title.getCurrentTitle().text
	local params = {
		 = {},  = {alias_of = "type"},
		 = {list = true, allow_holes = true},
		 = {list = true, allow_holes = true},
		 = {list = true, allow_holes = true},
		 = {list = "e"},  = {list = "etym"},  = {list = "etymology"},  = {list = true},  = {list = true},
		 = {},  = {alias_of = "k"},  = {alias_of = "k"},
		 = {},  = {alias_of = "kt"},  = {alias_of = "kt"},  = {alias_of = "kt"},  = {alias_of = "kt"},  = {alias_of = "kt"},  = {alias_of = "kt"},  = {alias_of = "kt"},
		 = {},  = {alias_of = "ke"},  = {alias_of = "ke"},  = {alias_of = "ke"},
		 = {},  = {alias_of = "v"},  = {alias_of = "v"},
		 = {},  = {alias_of = "ve"},  = {alias_of = "ve"},  = {alias_of = "ve"},  = {alias_of = "ve"},
		 = {list = true},  = {list = true},  = {list = true},
		 = {},  = {alias_of = "e"},  = {alias_of = "e"},  = {alias_of = "e"},  = {alias_of = "e"},  = {alias_of = "e"},
		 = {list = true},  = {list = true},
		 = {list = true},  = {list = true},
		 = {list = true},  = {list = true},  = {list = true},  = {list = true},
		 = {list = true},  = {list = true},  = {list = true},  = {list = true},
		 = {},  = {alias_of = "wp"},  = {alias_of = "wp"},
		 = {list = true},  = {list = true},  = {list = true},  = {list = true},  = {list = true},  = {list = true},  = {list = true},
		 = {},  = {alias_of = "pic"},  = {alias_of = "pic"},  = {alias_of = "pic"},
		 = {},  = {alias_of = "piccap"},  = {alias_of = "piccap"},  = {alias_of = "piccap"},
		 = {},  = {alias_of = "er"},
		 = {},  = {alias_of = "tl"},  = {alias_of = "tl"},  = {alias_of = "tl"},  = {alias_of = "tl"},  = {alias_of = "tl"},
		 = {},  = {alias_of = "a"},  = {alias_of = "a"},  = {alias_of = "a"},  = {alias_of = "a"},
		 = {list = true},  = {list = true},  = {list = true},  = {list = true},  = {list = true},  = {list = true},
		 = {},  = {alias_of = "c"},  = {alias_of = "c"},
		 = {},  = {alias_of = "mn"},  = {alias_of = "mn"},
		 = {},  = {alias_of = "w"},  = {alias_of = "w"},
		 = {},
		 = {},
		 = {},
		 = {},
		 = {},
	}
	local args = require("Module:parameters").process(f:getParent().args, params)
	local comp = args or ""
	local pos = {}
	local def = {}
	for i=1,math.max(args.maxindex/2, args.maxindex, args.maxindex) do
		table.insert(pos, args or args or "")
		table.insert(def, args or args or "")
	end
	
	local function expand(arg)
		local result = {}
		local maximum = 0
		for i=1,#arg do if #arg > maximum then maximum = #arg end end
		local current = nil
		for i=1,maximum do
			current = nil
			for j=1,#arg do
				if current then
					break
				else
					current = arg
				end
			end
			current = current or ""
			table.insert(result, current)
		end
		return result
	end
	
	local function fetch_all(arg)
		local result = {}
		for i=1,#arg do
			for j=1,#arg do
				table.insert(result,arg)
			end
		end
		return result
	end
	
	local etyms = expand({args, args, args, args, args})
	local ko = args or ""
	local kotrans = args or ""
	local kodef = args or def or ""
	local vi = args or ""
	local videf = args or def or ""
	local p = expand({args, args, args})
	local etym = args or ""
	local syn = expand({args, args})
	local ant = expand({args, args})
	local der = expand({args, args, args, args})
	local also = expand({args, args, args, args})
	local wp = args or ""
	local cat = fetch_all({args, args, args, args, args, args, args})
	local pic = args or ""
	local piccap = args or ""
	local er = args or ""
	local tl = args or ""
	local audio = args or ""
	local alt = expand({args, args, args, args, args, args})
	local c = args or ""
	local mn = args or ""
	local w = args or ""
	local m = args or ""
	local h = args or ""
	local md = args or ""
	local mc = args or ""
	local oc = args or ""
	text = ''
	if not pos or pos == '' then pos = 'n' end
	for i=1,#pos do pos = checkpos(pos) end
	text = (text .. '==Chinese==\n')
	if M.ts_determ(title) == 'simp' then
		return text .. '{{zh-see|' .. M.st(title) .. ('}}\n\n]'):format(mw.title.getCurrentTitle().text)
	end
	length = mw.ustring.len(title)
	noerhua = mw.ustring.sub(title,1,length-1)
	erhua = mw.ustring.sub(title,length,length)
	text = text .. (is_erhua and M.hzbox_er(title) or M.hzbox(title,comp,table.concat(etyms,'|')))
	if wp ~= '' then text = (text .. '\n{{wikipedia|lang=zh}}') end
	if pic ~= '' then text = (text .. '\n]')	end
	if is_erhua then
		text = (text .. '\n\n===Etymology===\n{{zh-compound|' .. noerhua .. '|' .. erhua .. '|')
		if def and def ~= '' then text = text .. def end
		text = (text .. "|''diminutive suffix''}}\n\n")
		text = (text .. '===Pronunciation===\n{{zh-pron\n\|m=' .. M.pytemp_er(title,comp,pos,p) .. 'r\n|cat=' .. table.concat(pos,',') .. '\n}}\n\n')
	else
		text = (text .. '\n\n')
		if #alt > 0 then
			text = (text .. '===Alternative forms===')
			for i=1,#alt do text = (text .. '\n* {{zh-l|' .. alt .. '}}') end
			text = (text .. '\n\n')
		end
		if etym ~= '' then text = (text .. '===Etymology===\n' .. etym .. '\n\n') end
		if #etyms > 0 then
			text = (text .. '===Etymology===\n')
			text = (text .. '{{zh-compound|' .. M.compdecompetym(title,comp) .. '|' .. table.concat(etyms,'|') .. '}}\n\n')
		end
		text = (text .. '===Pronunciation===\n{{zh-pron')
		if m ~= '-' then
			if m ~= '' then
				m_pron = m
				text = (text .. '\n|m=' .. m_pron)
			else
				m_pron = mw.ustring.gsub(M.pytemp(title,comp,pos,p), ',', ', ')
				text = (text .. '\n|m=' .. m_pron)
				if er ~= '' then text = (text .. ',er=' .. er) end
				if tl ~= '' then text = (text .. ',tl=y') end
			end
		end
		if c == '' then c = M.check_pron(title, 'yue', length) or '' end
		if length == 1 or (c ~= '' and c ~= '-') then text = (text .. '\n|c=' .. (c or "")) end
		if h == '' then h = M.check_pron(title, 'hak') or '' end
		if length == 1 or (h ~= '' and h ~= '-') then text = (text .. '\n|h=' .. (h and ("pfs=" .. h) or "")) end
		if length == 1 or md ~= '' then text = (text .. '\n|md=' .. (md or "")) end
		if mn == '' then mn = M.check_pron(title, 'nan', nil, true) or '' end
		if length == 1 or (mn ~= '' and mn ~= '-') then text = (text .. '\n|mn=' .. (mn or "")) end
		if length == 1 or w ~= '' then text = (text .. '\n|w=' .. (w or "")) end
		if audio ~= '' then text = (text .. '\n|ma=') if audio ~= 'y' then text = (text .. audio) else text = (text .. 'y') end end
		if length == 1 or mc ~= '' then text = (text .. '\n|mc=' .. (mc ~= "" and mc or 'y')) end
		if length == 1 or oc ~= '' then text = (text .. '\n|oc=' .. (oc ~= "" and oc or 'y')) end
		text = (text .. '\n|cat=' .. table.concat(pos,',') .. '\n}}\n\n')
	end
	text = (text .. '===' .. (length == 1 and "Definitions" or M.postitle(pos)) .. '===\n')
	text = (text .. '{{zh-' .. (length == 1 and "hanzi" or M.poshead(pos)) .. '}}\n\n')
	if is_erhua then
		text = text .. '# {{context|Mandarin|lang=zh}} {{erhua form'
		if def and def ~= '' then text = text .. '|' .. def end
		text = text .. '}}'
	else
		text = (text .. '# ' .. ((def and def ~= "") and def or "{{rfdef|lang=zh}}"))
	end
	text = M.semantics(text,'Synonyms',syn)
	text = M.semantics(text,'Antonyms',ant)
	text = M.semantics(text,'Derived terms',der)
	for i=2,#pos do
		text = text .. '\n\n===' .. M.postitle(pos) .. '===\n'
		text = text .. '{{zh-' .. M.poshead(pos) .. '}}\n\n'
		if is_erhua then
			text = text .. '# {{context|Mandarin|lang=zh}} {{erhua form'
			if def ~= '' then text = text .. '|' .. def end
			text = text .. '}}'
		else
			text = text .. '# ' .. def
		end
	end
	if #also > 0 then
		text = (text .. '\n\n===See also===')
		for i=1,#also do
			text = (text .. '\n* {{zh-l|' .. also .. '}}')
		end
	end
	if #cat > 0 then text = (text .. '\n\n{{zh-cat|' .. table.concat(cat,'|') .. '}}') end
	if ko ~= '' then
		text = text .. '\n\n----\n\n==Korean==\n{{ko-hanjatab}}\n\n===Noun===\n{{ko-noun|hj|hangeul=' .. ko .. '}}\n\n# {{hanja form of|' .. ko .. '|' .. kodef .. '}}'
	end
	if vi ~= '' then
		text = text .. '\n\n----\n\n==Vietnamese==\n{{vi-hantutab}}\n\n===' .. M.postitle(pos) .. '===\n{{vi-hantu}}\n\n# {{han tu form of|' .. vi .. '|' .. videf .. '}}'
	end
	if not mw.title.getCurrentTitle().exists then
		text = text .. ('\n\n]'):format(mw.title.getCurrentTitle().text)
	end
	return text
end

return M