Tomonidan ishlatiladigan Andoza:zh-pron


local m_zh = require("Module:zh")
local m_zh_data = mw.loadData("Module:zh/data")
local m_links = require("Module:links")
local lang= require("Module:languages")
local gsub = mw.ustring.gsub
 
local export = {}
 
local langname = {
	['cdo']='Min Dong',
	['cmn']='Mandarin',
	['cjy']='Jin',
	['gan']='Gan',
	['hak']='Hakka',
	['hsn']='Xiang',
	['nan']='Min Nan',
	['wuu']='Wu',
	['yue']='Kantonis'
}

local pos_aliases_cat={
	['n']='ot soʻzlar', ['noun']='ot soʻzlar', ['pn']='atoqli', ['propn']='atoqli', ['proper']='atoqli soʻzlar', ['proper noun']='atoqli ot soʻzlar', ['pron']='olmoshlari', ['pronoun']='olmoshlari', --ism bilan bogʻliq narsalar
	['v']='feʼli soʻzlari', ['verb']='feʼli soʻzlari', ['a']='sifat soʻzlar', ['adj']='sifat soʻzlar', ['adjective']='sifat soʻzlar', ['adv']='holi soʻzlari', ['adverb']='holi soʻzlari', --boshqa asosiy solmoqda
	['prep']='edatlar', ['pre']='edatlar', ['postp']='oxirigalar', ['post']='oxirigalar', ['con']='qoʻshilishli', ['conj']='qoʻshilishli', ['conjunction']='qoʻshilishli', --hukm muharriridan
	['part']='zarralar', ['particle']='zarralar', ['pref']='prefiks', ['suf']='suffiks', ['suffix']='suffiks', ['interfix']='interfiks', --soʻz muharriridan
	['prov']='hikmatlari soʻzlari', ['proverb']='hikmatlari', ['id']='iboralar', ['idiom']='iboralar', ['ch']='chengyu', ['cy']='chengyu', ['chengyu']='chengyu', ['ph']='jumlaga', ['phrase']='jumlaga', ['intj']='nido soʻzlar', ['interj']='nido soʻzlar', ['interjection']='nido soʻzlar', --bir necha soʻz
	['cl']='tasniflagichlar', ['cls']='tasniflagichlar', ['classifier']='tasniflagichlar', ['num']='raqam soʻzlari', ['numeral']='raqam soʻzlari', ['abb']='abbreviations', ['abbreviation']='abbreviations', ['det']='determiners', ['deter']='determiners', ['determiner']='determiners', --boshqalar
};

function count(text)
	if text == "" then
		return 0
	end
	return 1
end

local m_pron = require("Module:cmn-pron")
local c_pron = require("Module:yue-pron")
local h_pron = require("Module:hak-pron")
local md_pron = require("Module:cdo-pron")
local mn_pron = require("Module:nan-pron")
local w_pron = require("Module:wuu-pron")

function export.make_table(frame)
	local args = frame:getParent().args
	local m_rom = args["m"] or ""
	local c_rom = args["c"] or ""
	local g_rom = args["g"] or ""
	local h_rom = args["h"] or ""
	local j_rom = args["j"] or ""
	local md_rom = args["md"] or ""
	local mn_rom = args["mn"] or ""
	local mn_t_rom = args["mn-t"] or ""
	local w_rom = args["w"] or ""
	local x_rom = args["x"] or ""
	local m_audio = args["ma"] or ""
	local m_audio2 = args["ma2"] or ""
	local c_audio = args["ca"] or ""
	local g_audio = args["ga"] or ""
	local h_audio = args["ha"] or ""
	local j_audio = args["ja"] or ""
	local md_audio = args["mda"] or ""
	local mn_audio = args["mna"] or ""
	local mn_t_audio = args["mn-ta"] or ""
	local w_audio = args["wa"] or ""
	local x_audio = args["xa"] or ""
	local text = ''
	local count = count(m_rom..m_audio) + count(c_rom..c_audio) + count(md_rom..md_audio) + count(mn_rom..mn_audio) + count(w_rom..w_audio) + count(g_rom..g_audio) + count(h_rom..h_audio) + count(j_rom..j_audio) + count(x_rom..x_audio)
	c_rom = c_rom:gsub("%*","-")
	if g_rom ~= '' then g_rom = ipa_format(g_rom) end
	if j_rom ~= '' then j_rom = ipa_format(j_rom) end
	if x_rom ~= '' then x_rom = ipa_format(x_rom) end
	if count > 1 then
		text = text .. '<div class="toccolours mw-collapsible mw-collapsed" style="width:500px; font-size:100%">'
		if m_rom ~= "" then
			text = text .. '\n* [[w:Mandarin Chinese|Mandarin]]\n' .. m_pron.str_analysis(m_rom,'bosh')
		end
		if c_rom ~= "" then
			local c_processed = c_rom:gsub(',([^ ])',', %1')
			if mw.ustring.len(mw.title.getCurrentTitle().text) == 1 then
				c_processed = c_processed:gsub('([^, ]+)','[[%1]]')
				c_processed = c_processed:gsub('%[%[%[%[','[[')
				c_processed = c_processed:gsub('%]%]%]%]',']]')
				c_processed = gsub(c_processed, '%[%[([^%]]+)%]%]', function(a)
					return '[[' .. a .. '|' .. gsub(a, '([1-9-]*)', '<sup>%1</sup>') .. ']]' end)
			else
				c_processed = gsub(c_processed, '([1-9-]*)', '<sup>%1</sup>')
			end
			text = text .. '\n* [[w:Cantonese|Kanton]] (\'\'[[w:Jyutping|Jyutping]]\'\'): <tt>' .. c_processed .. '</tt>'
			c_rom = c_rom:gsub('[%[%]]','')
		end
		if g_rom ~= '' then
			text = text .. '\n* [[w:Gan Chinese|Gan]] (\'\'[[w:International Phonetic Alphabet|IPA]]\'\'): <span class="IPA">/' .. g_rom .. '/</span>'
		end
		if mw.ustring.find(h_rom,'^pfs') then
			text = text .. '\n* [[w:Hakka Chinese|Haqqa]] (\'\'[[w:Pha̍k-fa-sṳ|Pha̍k-fa-sṳ]]\'\'): <tt>' .. h_pron.rom_display(h_rom,'yes') .. '</tt>'
		end
		if j_rom ~= '' then
			text = text .. '\n* [[w:Jin Chinese|Jin]] (\'\'[[w:International Phonetic Alphabet|MFA]]\'\'): <span class="IPA">/' .. j_rom .. '/</span>'
		end
		if md_rom ~= "" then
			text = text .. '\n* [[w:Min Dong|Min Dong]] (\'\'[[w:Bàng-uâ-cê|BUC]]\'\'): <tt>' .. md_rom .. '</tt>'
		end
		if mn_rom ~= "" then
			text = text .. '\n* [[w:Min Nan|Min Nan]] (\'\'[[w:Pe̍h-ōe-jī|POJ]]\'\'): <tt>' .. mn_pron.poj_display(mn_rom) .. '</tt>'
		end
		if w_rom ~= "" then
			text = text .. '\n* [[w:Wu Chinese|Wu]] (\'\'[[Wiktionary:About Chinese/Wu|WT Romanisation]]\'\'): <tt>' .. w_pron.rom(w_rom) .. '</tt>'
		end
		if x_rom ~= '' then
			text = text .. '\n* [[w:Xiang Chinese|Xiang]] (\'\'[[w:International Phonetic Alphabet|MFA]]\'\'): <span class="MFA">/' .. x_rom .. '/</span>'
		end
		text = text .. '\n<div class="mw-collapsible-content">\n----'
	end
	text = text .. '\n'
	if m_rom .. m_audio ~= "" then
		m_args = {}
		m_args[1] = m_pron.str_analysis(m_rom,'')
		m_args_names = {'1n','1na','1nb','1nc','1nd','py','cap','tl','tl2','tl3','a','audio','er','ertl','ertl2','ertl3','era','eraudio','2n','2na','2nb','2nc','2nd','2py','2cap','2tl','2tl2','2tl3','2a','2audio','3n','3na','3nb','3nc','3nd','3py','3cap','3tl','3tl2','3tl3','3a','3audio','4n','4na','4nb','4nc','4nd','4py','4cap','4tl','4tl2','4tl3','4a','4audio'}
		for _,name in ipairs(m_args_names) do
			m_args[name] = m_pron.str_analysis(m_rom,name)
		end
		m_args[2] = m_pron.str_analysis(m_rom,'2')
		m_args[3] = m_pron.str_analysis(m_rom,'3')
		m_args[4] = m_pron.str_analysis(m_rom,'4')
		m_args['a'] = m_audio
		m_args['a2'] = m_audio2
		local debug = ""
		for code,name in pairs(m_args) do
			debug = debug .. code .. ":" .. name .. ","
		end
		text = text .. m_pron.make_args(m_args)
		if args["m_note"] then text = text .. '\n** Note: <small>' .. args["m_note"] .. '</small>.' end
	end
	if c_rom .. c_audio ~= "" then
		text = text .. '\n* [[w:Cantonese|Kantonchada]]'
		local c_hom = mw.loadData("Module:yue-pron/hom")
		local c_hom_exists = false
		for _,c_first in ipairs(c_pron.jyutping_format(c_rom)) do
			if c_hom[c_first] then
				c_hom_exists = c_first
			end
		end
		text = text .. '\n** (\'\'[[w:Standard Cantonese|Standarti kanton]], [[w:Guangzhou Cantonese|Guangzhou]]\'\')'
		if not c_hom_exists then
			text = text .. '<sup><small><abbr title="Kantoncha soʻz, lekin leksema qoʻshish (va siz nima qilayotganingizni bilish faqat agar agar bu bosing!)"><span class="plainlinks">[' .. tostring(mw.uri.fullUrl("Module:yue-pron/hom",{["action"]="edit"})) .. ' +]</span></abbr></small></sup>'
		end
		c_comma = gsub(c_rom,',([^ ])',', %1')
		text = text .. '\n*** \'\'[[w:Jyutping|Jyutping]]\'\': <tt>' .. gsub(c_comma, '([1-9-]*)', '<sup>%1</sup>') .. '</tt>'
		text = text .. '\n*** \'\'[[w:Yale romanization of Cantonese|Yale]]\'\': <tt>' .. c_pron.jyutping_to_yale(c_rom) .. '</tt>'
		text = text .. '\n*** \'\'[[w:Cantonese Pinyin|Cantonese Pinyin]]\'\': <tt>' .. gsub(c_pron.jyutping_to_cantonese_pinyin(c_rom), '([1-9-]*)', '<sup>%1</sup>') .. '</tt>'
		text = text .. '\n*** [[Wiktionary:International Phonetic Alphabet|MFA]] <sup>([[w:Cantonese phonology|key]])</sup>: <span class="IPA">/' .. c_pron.jyutping_to_ipa(c_rom) .. '/</span>'
		for _,c_first in ipairs(c_pron.jyutping_format(c_rom)) do
			if c_hom_exists == c_first then
				local hom_text = '\n*** Homophones: <table class="wikitable mw-collapsible mw-collapsed" style="width:15em;margin:0; position:left; text-align:center"><tr><th></th></tr><tr><td><sup><div style="float: right; clear: right;"><span class="plainlinks">[' .. tostring(mw.uri.fullUrl("Module:yue-pron/hom",{["action"]="edit"})) .. ' edit]</span></div></sup><div style="visibility:hidden; float:left"><sup><span style="color:#FFF">edit</span></sup></div>'
				for _,hom in ipairs(c_hom[c_first]) do
					hom_text = hom_text .. "[[" .. mw.ustring.gsub(hom,"/","]]/[[") .. "]]<br />"
				end
				hom_text = mw.ustring.gsub(hom_text,"<br />$","")
				hom_text = hom_text .. '</td></tr></table>'
				hom_text = m_links.language_link(hom_text, nil, lang, nil, false)
				text = text .. hom_text .. '[[Turkum:Soʻz, lekin leksema bilan Xitoy shartlari#c]]'
			end
		end
		text = add_audio(text,c_audio,'yue')
		if args["c_note"] then text = text .. '\n** Note: <small>' .. args["c_note"] .. '</small>.' end
	end
	if g_rom .. g_audio ~= "" then
		text = text .. '\n* [[w:Gan Chinese|Gan]]'
		text = text .. '\n** (\'\'[[w:Nanchang dialekt|Nanchang]]\'\')'
		if g_rom ~= '' then text = text .. '\n*** [[Wiktionary:International Phonetic Alphabet|MFA]] <sup>([[w:Changsha dialekt|key]])</sup>: <span class="MFA">/' .. g_rom .. '/</span>' end
		text = add_audio(text,g_audio,'gan')
	end
	if h_rom .. h_audio ~= "" then
		text = text .. '\n* [[Wiktionary:About Chinese/Hakka|Hakka]]'
		if h_rom ~= '' then text = text .. '\n** Romanisations:' .. h_pron.rom_display(h_rom,'') end
		if mw.ustring.find(h_rom, '^pfs') and not mw.ustring.match(h_rom, '[ ;]') and not mw.ustring.match(h_rom, '([^/]*)-([^/]*)-([^/]*)') then
			text = text .. '\n*** [[Wiktionary:International Phonetic Alphabet|MFA]] (\'\'[[w:zh:四縣話|Siyen]]\'\'): <span class="MFA">/'
			i = 0
			for word in mw.text.gsplit(h_rom, '/') do
				i = i + 1
				if i ~= 1 then
					text = text .. '/, /'
				end
				text = text .. h_pron.ipa(word)
			end
			text = text .. '/</span>'
		end
		if h_audio ~= '' then text = add_audio(text,h_audio,'hak') end
	end
	if j_rom .. j_audio ~= "" then
		text = text .. '\n* [[w:Jin Chinese|Jin]]'
		text = text .. '\n** (\'\'[[w:Taiyuan|Taiyuan]]\'\')<sup>[[:w:zh:太原話|+]]</sup>'
		if j_rom ~= '' then text = text .. '\n*** [[Wiktionary:International Phonetic Alphabet|MFA]] <sup>([[w:Changsha dialekt|key]])</sup>: <span class="MFA">/' .. j_rom .. '/</span>' end
		text = add_audio(text,j_audio,'cjy')
	end
	if md_rom .. md_audio ~= "" then
		text = text .. '\n* [[w:Min Dong|Min Dong]]'
		text = text .. '\n** (\'\'[[w:Fuzhou dialekt|Fuzhou]]\'\')'
		if md_rom ~= '' then
			text = text .. '\n*** \'\'[[w:Bàng-uâ-cê|Bàng-uâ-cê]]\'\': <tt>' .. md_rom .. '</tt>'
			if not mw.ustring.match(md_rom, ' ') and not mw.ustring.match(md_rom, '([^/]*)-([^/]*)-([^/]*)') then
				text = text .. '\n*** [[Wiktionary:International Phonetic Alphabet|MFA]] <sup>([[w:Fuzhou dialekt|key]])</sup>: <span class="MFA">/'
				i = 0
				for word in mw.text.gsplit(md_rom, '/') do
					i = i + 1
					if i ~= 1 then
						text = text .. '/, /'
					end
					text = text .. md_pron.ipa(word)
				end
				text = text .. '/</span>'
			end
		end
		text = add_audio(text,md_audio,'cdo')
		if args["md_note"] then text = text .. '\n** Note: <small>' .. args["md_note"] .. '</small>.' end
	end
	if mn_rom .. mn_audio .. mn_t_rom .. mn_t_audio ~= "" then
		text = text .. '\n* [[w:Min Nan|Min Nan]]'
		if mn_rom .. mn_audio ~= "" then
			text = text .. '\n** (\'\'[[w:Hokkien|Hokkien]]\'\')'
			text = text .. '\n*** \'\'[[w:Pe̍h-ōe-jī|Pe̍h-ōe-jī]]\'\': <tt>' .. mn_pron.poj_display(mn_rom) .. '</tt>'
			mn_tailo = mn_pron.poj_to_tl_conv(mn_rom)
			mn_tailo = gsub(mn_tailo,'/([^ ])',' / %1')
			text = text .. '\n*** \'\'[[w:Tâi-lô|Tâi-lô]]\'\': <tt>' .. mn_tailo .. '</tt>'
			mn_space = mw.ustring.find(mn_rom,' ')
			mn_double_hyphen = mw.ustring.find(mn_rom,'--')
			if not mn_space and mn_double_hyphen then
					text = text .. '\n*** [[Wiktionary:International Phonetic Alphabet|MFA]] (\'\'[[w:Taipei|Taipei]]\'\'): <span class="MFA">/' .. mn_pron.poj_to_ipa_conv(mn_rom,'Taipei') .. '/</span>'
					text = text .. '\n*** [[Wiktionary:International Phonetic Alphabet|MFA]] (\'\'[[w:Zhangzhou|Zhangzhou]]\'\'): <span class="MFA">/' .. mn_pron.poj_to_ipa_conv(mn_rom,'Zhangzhou') .. '/</span>'
			end
			text = add_audio(text,mn_audio,'nan')
			if args["mn_note"] then text = text .. '\n** Note: <small>' .. args["mn_note"] .. '</small>.' end
		end
		if mn_t_rom .. mn_t_audio ~= "" then
			text = text .. '\n** (\'\'[[w:Teochew dialekt|Teochew]]\'\')'
			text = text .. '\n*** \'\'[[w:Guangdong Romanization#Teochew|Peng\'im]]\'\': <tt>' .. mn_t_rom .. '</tt>'
		end
	end
	if w_rom .. w_audio ~= "" then
		text = text .. '\n* [[w:Wu Chinese|Wu]]'
		text = text .. '\n** (\'\'[[w:Shanghainese|Shanghaicha]]\'\')'
		text = text .. '\n*** \'\'[[Wiktionary:About Chinese/Wu|WT Romanisation]]\'\': <tt>' .. w_pron.rom(w_rom) .. '</tt>'
		text = text .. '\n*** [[Wiktionary:International Phonetic Alphabet|IPA]] <sup>([[w:Shanghainese|key]])</sup>: <span class="MFA">/' .. w_pron.ipa_conv(w_rom) .. '/</span>'
		if args["w_note"] then text = text .. '\n** Note: <small>' .. args["w_note"] .. '</small>.' end
		text = add_audio(text,w_audio,'wuu')
	end
	if x_rom .. x_audio ~= "" then
		text = text .. '\n* [[w:Xiang Chinese|Xiang]]'
		text = text .. '\n** (\'\'[[w:Changsha dialekt|Changsha]]\'\')'
		if x_rom ~= '' then text = text .. '\n*** [[Wiktionary:International Phonetic Alphabet|MFA]] <sup>([[w:Changsha dialekt|key]])</sup>: <span class="IPA">/' .. x_rom .. '/</span>' end
		text = add_audio(text,x_audio,'hsn')
	end
	if count > 1 then
		text = text .. '</div></div>'
	end
	if c_rom == "" then text = text .. "[[Turkum:Ning sinov turkumga kiruvchi 2]]" end
	return text
end

function ipa_format(text)
	local numbers = { [1]='¹',[2]='²',[3]='³',[4]='⁴',[5]='⁵' }
	return gsub(text,'[1-5]',numbers)
end

function add_audio(text,audio,lang)
	if audio ~= "" then
		if audio == "y" then audio = lang .. '-' .. mw.title.getCurrentTitle().baseText .. '.ogg' end
		text = text .. '\n*** ' .. mw.getCurrentFrame():expandTemplate{title="Andoza:audio",args={audio,['lang']=lang}}
		text = text .. '[[Turkum:'..langname[lang]..' audio yoʻnalishlarga ega atamalar]]'
	end
	return text
end

function export.make_cat(frame)
	local args = frame:getParent().args
	local m_rom = args["m"] or ''
	local c_rom = args["c"] or ''
	local g_rom = args["g"] or ''
	local h_rom = args["h"] or ''
	local j_rom = args["j"] or ''
	local md_rom = args["md"] or ''
	local mn_rom = args["mn"] or ''
	local w_rom = args["w"] or ''
	local x_rom = args["x"] or ''
	local g_audio = args["ga"] or ''
	local h_audio = args["ha"] or ''
	local j_audio = args["ja"] or ''
	local md_audio = args["mda"] or ''
	local mn_audio = args["mna"] or ''
	local w_audio = args["wa"] or ''
	local x_audio = args["xa"] or ''
	local text = args["cat"]
	local cat = {}
	local conv_text = ''
	local cat_start = '[[Turkum:'
	local cat_end = ']]'
	if m_rom == '' then
		m_rom = mw.title.getCurrentTitle().text
	end
	if mw.ustring.match(m_rom,'[一-龯㐀-䶵]') then
		m_rom = gsub(m_rom,'.',m_zh_data.py)
	end
	m_rom = m_pron.py_transform(m_rom,true,true)
	if w_rom ~= '' then
		w_rom = gsub(w_rom, '%d', '')
	end
	if text and text ~= '' and mw.title.getCurrentTitle().nsText == '' or mw.title.getCurrentTitle().nsText == 'User' then
		cat = mw.text.split(text,',',true)
		if (pos_aliases_cat[cat[1]] or "") == 'chengyu' then
			table.insert(cat, 2, 'iboralar')
		end
		table.insert(cat, 1, "lemmalar")
		for i = 1, #cat do
			cat[i] = gsub(cat[i], '^ +', '')
			cat[i] = pos_aliases_cat[cat[i]] or cat[i]
			conv_text = conv_text .. cat_start .. 'Xitoychada ' .. cat[i] .. '|' .. m_rom .. cat_end
			if args["m"] then
				conv_text = conv_text .. cat_start .. 'Mandarinchada ' .. cat[i] .. '|' .. m_rom .. cat_end
			end
			if c_rom ~= '' then conv_text = conv_text .. cat_start .. 'Kantonchada ' .. cat[i] .. '|' .. c_rom:gsub('[%[%]]','') .. cat_end end
			if g_rom ~= '' or g_audio ~= '' then conv_text = conv_text .. cat_start .. 'Ganchada ' .. cat[i] .. '|' .. m_rom .. cat_end end
			if h_rom ~= '' or h_audio ~= '' then conv_text = conv_text .. cat_start .. 'Haqqachada ' .. cat[i] .. '|' .. m_rom .. cat_end end
			if j_rom ~= '' or j_audio ~= '' then conv_text = conv_text .. cat_start .. 'Jinchada ' .. cat[i] .. '|'  .. m_rom .. cat_end end
			if md_rom ~= '' or md_audio ~= '' then conv_text = conv_text .. cat_start .. 'Min-dongchada ' .. cat[i] .. '|' .. md_rom .. cat_end end
			if mn_rom ~= '' or mn_audio ~= '' then conv_text = conv_text .. cat_start .. 'Min-nanchada ' .. cat[i] .. '|' .. mn_rom .. cat_end end
			if w_rom ~= '' or w_audio ~= '' then conv_text = conv_text .. cat_start .. 'Wuchada ' .. cat[i] .. '|' .. w_rom .. cat_end end
			if x_rom ~= '' or x_audio ~= '' then conv_text = conv_text .. cat_start .. 'Xiangchada ' .. cat[i]  .. '|'  .. m_rom .. cat_end end
		end
	end
	if mw.ustring.len(mw.title.getCurrentTitle().text) == 1 then
		conv_text  = conv_text .. cat_start .. 'Xitoy hanzi|' .. m_rom .. cat_end
	end
	return conv_text
end

return export