Bu modul uchun Modul:zh-shakllari/doc nomli hujjat sahifasini yaratishingiz mumkin

local export = {}

function export.make(frame)
	local args = frame:getParent().args
	local form = { ['simp'] = {}, ['trad'] = {} }
	local comp_type = args["type"] or false
	table.insert(form['simp'], args["s"] or nil)
	table.insert(form['simp'], args["s2"] or nil)
	table.insert(form['simp'], args["s3"] or nil)
	table.insert(form['trad'], args["t"] or mw.title.getCurrentTitle().subpageText)
	table.insert(form['trad'], args["t2"] or nil)
	table.insert(form['trad'], args["t3"] or nil)

	if #form['trad'] ~= 1 and #form['simp'] == 0 then
		table.insert(form['simp'], form['trad'][1])
	end

	local var_fmt = '\n|-\n! style="padding: 0.5em;border: 1px solid #aaa;background: #E0FFFF;font-weight: normal;font-size: smaller;" colspan="2" |'
	local char_gap = '\n| style="padding: 0.5em;border-bottom: 1px solid #aaa;font-size: x-large;" lang="zh" class="Hani" | '
	local char_last = '\n| style="padding: 0.5em;border-right: 1px solid #aaa;border-bottom: 1px solid #aaa;font-size: x-large;" lang="zh" class="Hani" | '

	local function header(length)
		return (length > 7 and ':{|' or '{| align=right') .. ' style="margin: 1em 1em 1em 1em;border-collapse: collapse;text-align: center"\n|-\n! colspan=2|'
	end
	
	local function gloss_fmt(length, colspan)
		return '\n! style="padding: 0.5em;border: 1px solid #aaa;background:#F5F5DC;font-weight: normal;font-size: 80%; width:' ..
			(30*length+40) .. 'px" colspan=' .. (colspan or 1)  ..'|'
	end

	local function form_fmt(text, length)
		return length ~= 1 and '<span style="font-size:140%">(<span lang="zh" class="Hani">[[' .. table.concat(text, "]]/[[") .. ']]</span>)</span>' or ''
	end
	
	local function char_fmt(text)
		return (#text ~= 1 and (char_gap .. table.concat(text, char_gap, 1, #text-1)) or '') .. char_last .. text[#text]
	end
	
	local test_word = form['trad'][1]
	local length = mw.ustring.len(test_word)
	local word_division, i = {}, 1
	if comp_type then
		for index in mw.text.gsplit(comp_type, "", true) do
			if mw.ustring.match(mw.ustring.sub(test_word, i, i), '[,%-]') then
				table.insert(word_division, { i, i } )
				i = i + 1
			elseif mw.ustring.sub(test_word, i, i) == '…' then
				table.insert(word_division, { i, i + 1 } )
				i = i + 2
			end
			table.insert(word_division, { i, i + index - 1 } )
			i = i + index
		end
		if i - 1 ~= mw.ustring.len(mw.ustring.gsub(test_word, '…+$', '')) then
			error("'type' parameter does not match word length.")
		end
	else
		for i = 1, length do
			table.insert(word_division, { i, i } )
		end
	end

	local char_set = { ['simp'] = {}, ['trad'] = {} }
	local identity = #form['simp'] == 0 and { 'trad' } or { 'simp', 'trad' }
	local uncreated = {}
	
	for _, id in ipairs(identity) do
		for i, position in ipairs(word_division) do
			local char_string = { ['simp'] = '', ['trad'] = '' }
			for j = 1, #form[id] do
				local word_form = mw.ustring.sub(form[id][j], position[1], position[2])
				if not mw.ustring.find(char_string[id], word_form) then
					char_string[id] = (char_string[id] ~= "" and (char_string[id] .. '/') or "") .. word_form
				end
			end
			if not mw.ustring.match(char_string[id], '[,%-]') then
				char_string[id] = "[[" .. mw.ustring.gsub(char_string[id], '/', ']]/[[') .. "]]"
			end
			table.insert(char_set[id], char_string[id])
		end
		for _, item in ipairs(form[id]) do
			if not (mw.title.new(item) or {}).exists then
				table.insert(uncreated, '"[[' .. item .. ']]"')
			end
		end
	end

	local scripts = { ['一-龯㐀-䶵'] = 'Hani' , ['a-zA-ZāēīōūĀĒĪŌŪa-zA-Z'] = 'Latn', ['0-90-9'] = 'Numb', ['Ͱ-Ͽ'] = 'Grek' }
	local script = {}
	for range, script_name in pairs(scripts) do
		if mw.ustring.match(test_word, '[' .. range .. ']') then
			table.insert(script, script_name)
		end
	end

	note = #script > 1 and '[[Turkum:Bir necha skript yozilgan Xitoy shartlari]]' or ""
	note = #uncreated > 0 and note .. '[[Turkum:Yaratilmagan shakllari bilan Xitoy shartlari]]' .. 
		'<small class="attentionseeking">(Hanziʼga qutisiga shakllarini kamida bir yaratilmagan boʻladi. aniqlash: ' .. 
			table.concat(uncreated, ", ") .. '.)</small>' or note
	literal = (args["lit"] or args["note"] or "" ~= "") and '\n|-' .. 
		(length > 3 and '\n|\n|' .. gloss_fmt(length, #word_division) or gloss_fmt(length, #word_division + 2)) .. '<i>' .. 
		((args["lit"] or "" ~= "") and 'soʻzma-soʻz: ' or '') .. (args["lit"] or args["note"]) .. '</i>' or ""
	
	local gloss, m_gloss_data = {}, require("Module:zh/data/silliqlar")
	if args['gloss'] == '-' then
		gloss = { gloss_fmt(length * 1.6, #word_division) .. '<i>fonetik</i>' }
	elseif length == 1 then
		gloss = { gloss_fmt(1.6, #word_division) .. '-' }
	else
		for i, position in ipairs(word_division) do
			character = mw.ustring.sub(form['trad'][1], position[1], position[2])
			local gloss_text = args[i] or m_gloss_data.glosses[character] or ""
		
			if gloss_text == "" and position[2] > position[1] then
				local content = mw.title.new(character):getContent() or false
				if content then
					content = mw.ustring.match(mw.text.split(content, '%-%-%-%-')[1] .. '\n', '\n#([^#\n]+)\n') or ""
					gloss_text = mw.ustring.gsub(content, '([%{%(]+[^%}%)]+[%}%)]+)', function(captured)
						wiki_link = mw.ustring.match(captured, "%{%{w|(.+)%}%}") or false
						return wiki_link or "" end)
				end
			end
			if mw.ustring.len(mw.ustring.gsub(gloss_text, '[^;]', '')) > 2 then
				gloss_text = '<div class="vsSwitcher vsClass-pronunciations"><span class="putButtonHere">&nbsp;</span><div class="showme" style="display:none">' ..
					mw.ustring.match(gloss_text, '^[^;]+;[^;]+;[^;]+') .. '</div><div class="hideme">' .. gloss_text .. '</div></div>'
			end
			local word_length = mw.ustring.match(character, '[,…%-]') and 0 or mw.ustring.len(mw.ustring.gsub(char_set['trad'][i], '[%[%]/]', ''))
			table.insert(gloss, gloss_fmt(word_length, 1) .. gloss_text)
		end
	end

	output_text = header(length) .. table.concat(gloss, "") .. 
		(#identity == 1 and
			(var_fmt .. '[[Soddalashtirilgan Xitoycha|simp.]] va [[anʼanaviy Xitoycha|trad.]]<br>' .. 
				form_fmt(form['trad'], length) .. char_fmt(char_set['trad']))
		or
			 var_fmt .. '[[anʼanaviy Xitoycha|trad.]] ' .. 
			 	form_fmt(form['trad'], length) .. char_fmt(char_set['trad']) ..

			(var_fmt .. '[[Soddalashtirilgan Xitoycha|simp.]] ' ..
				form_fmt(form['simp'], length) .. char_fmt(char_set['simp']))

		) .. literal .. '\n|}' .. note
	
	return output_text
end

return export