Module:User:Chagneling/zh-pron

-- Works 60% of the time, all the time. local export = {}

local gsub = mw.ustring.gsub local match = mw.ustring.match

local langname = { ["yue"] = "Cantonese", }

local langname_abbr = { ["c"] = "Cantonese", ["c-t"] = "Taishanese", }

local pos_aliases_cat = { ["n"] = "nouns", ["noun"] = "nouns", ["pn"] = "proper nouns", ["propn"] = "proper nouns", ["proper"] = "proper nouns", ["proper noun"] = "proper nouns", ["pron"] = "pronouns", ["pronoun"] = "pronouns", ["v"] = "verbs", ["verb"] = "verbs", ["a"] = "adjectives", ["adj"] = "adjectives", ["adjective"] = "adjectives", ["adv"] = "adverbs", ["adverb"] = "adverbs", ["prep"] = "prepositions", ["pre"] = "prepositions", ["postp"] = "postpositions", ["post"] = "postpositions", ["con"] = "conjunctions", ["conj"] = "conjunctions", ["conjunction"] = "conjunctions", ["part"] = "particles", ["particle"] = "particles", ["pref"] = "prefixes", ["prefix"] = "prefixes", ["suf"] = "suffixes", ["suffix"] = "suffixes", ["interfix"] = "interfixes", ["prov"] = "proverbs", ["proverb"] = "proverbs", ["id"] = "idioms", ["idiom"] = "idioms", ["ch"] = "chengyu", ["cy"] = "chengyu", ["chengyu"] = "chengyu", ["ph"] = "phrases", ["phrase"] = "phrases", ["intj"] = "interjections", ["interj"] = "interjections", ["interjection"] = "interjections", ["cl"] = "classifiers", ["cls"] = "classifiers", ["classifier"] = "classifiers", ["num"] = "numerals", ["numeral"] = "numerals", ["abb"] = "abbreviations", ["abbreviation"] = "abbreviations", ["det"] = "determiners", ["deter"] = "determiners", ["determiner"] = "determiners", }

local function makeNote(text) if match(text, ": ") then text = "\n*" .. gsub(gsub(text, "\n", ".\n*"), "([:;]) ", "%1\n**") elseif match(text, "; ") then text = "\n*" .. gsub(text, '; ', ";\n*") end text = gsub(text, '“([^”]+)”', function (a) return '“' .. gsub(a, ";\n%*+", "; ") .. '”' end) return "\nNote: " .. text .. ". " end

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

function export.make(frame) -- local args = frame:getParent.args local args = frame.args local pagename = mw.title.getCurrentTitle.text local c_rom = args["c"] or "" local c_t_rom = args["c-t"] or "" local only_cat = ""

local text = {} local textShow = {' '} local textHide = {} local c_pron = require("Module:yue-pron") -- local c_pron = require("Module:User:Changeling/yue-pron") if c_rom .. c_t_rom ~= "" then if c_rom ~= "" then c_rom = c_rom:gsub("%*","-") 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  .. gsub(a, '([1-9-]+)', '%1') ..  end) else c_processed = gsub(c_processed, '([1-9-]+)', '%1') end if c_t_rom == "" then table.insert(textShow, ' (')			else				table.insert(textShow, '\n*: (Guangzhou, ') end table.insert(textShow, 'Jyutping) : ' .. c_processed .. ' ')			c_rom = c_rom:gsub('[%[%]]',)			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			table.insert(textHide, '\n** (Standard Cantonese, Guangzhou) ')			if not c_hom_exists then				table.insert(textHide, '  [')				table.insert(textHide, tostring(mw.uri.fullUrl("Module:yue-pron/hom",{["action"]="edit"})))				table.insert(textHide, ' +] ')			end			local c_comma = gsub(c_rom,',([^ ])',', %1')			table.insert(textHide, '\n*** Jyutping : ')			table.insert(textHide, tostring(gsub(c_comma, '([1-9-]+)', '%1')))			table.insert(textHide, ' ')			table.insert(textHide, '\n*** Yale'' : ') table.insert(textHide, c_pron.jyutping_to_yale(c_rom)) table.insert(textHide, ' ') table.insert(textHide, '\n*** Cantonese Pinyin : ') table.insert(textHide, tostring(gsub(c_pron.jyutping_to_cantonese_pinyin(c_rom), '([1-9-]+)', '%1'))) table.insert(textHide, ' ') table.insert(textHide, '\n*** Guangdong Romanization : ') table.insert(textHide, tostring(gsub(c_pron.jyutping_to_guangdong(c_rom), '([1-9-]+)', '%1'))) table.insert(textHide, ' ') table.insert(textHide, '\n*** IPA (key) : /') table.insert(textHide, c_pron.jyutping_to_ipa(c_rom)) table.insert(textHide, '/ ') for _,c_first in ipairs(c_pron.jyutping_format(c_rom)) do				if c_hom_exists == c_first then local hom_textHide = {'\n*** Homophones : ')					table.insert(textHide, table.concat(hom_textHide))					table.insert(textHide, )				end			end			if not args["c_note"] and (match(c_rom, "^[ao]") or match(c_rom, ",[ao]")) and mw.ustring.len(mw.title.getCurrentTitle.text) == 1 then				args["c_note"] = "The zero initial /∅-/ is commonly pronounced with a ng-initial /ŋ-/ in some varieties of Cantonese, including Hong Kong Cantonese"			end			if args["c_note"] then table.insert(textHide, makeNote(args["c_note"])) end		end		if c_t_rom ~= "" then			local c_t_processed = c_t_rom:gsub(',([^ ])',', %1')			c_t_processed = gsub(c_t_processed, '([1-9%*]%-?[1-9%*]?)', '%1')			table.insert(textShow, ((c_rom ~= "") and '\n*:' or ) .. ' (Taishan, Wiktionary) : ')			table.insert(textShow, c_t_processed .. ' ')			c_t_rom = c_t_rom:gsub('[%[%]]',)			local c_t_comma = gsub(c_t_rom,',([^ ])',', %1')			table.insert(textHide, '\n** (Taishanese, Taicheng) ')			table.insert(textHide, '\n*** Wiktionary : ')			table.insert(textHide, tostring(gsub(c_t_comma, '([1-9%*]%-?[1-9%*]?)', '%1')))			table.insert(textHide, ' ')			table.insert(textHide, '\n*** IPA (key) : ')			table.insert(textHide, c_pron.hoisanva_to_ipa(c_t_rom))			table.insert(textHide, ' ')			if args["c-t_note"] then table.insert(textHide, makeNote(args["c-t_note"])) end		end	end	local conv_text = {}	text = {table.concat(textShow), '\n \n\n', table.concat(textHide), ' '}	if mw.title.getCurrentTitle.nsText ~=  then		return (gsub(table.concat(text) .. table.concat(conv_text), "%[%[Category:[^%]]+%]%]", "")) else return (table.concat(text) .. table.concat(conv_text)) end end

return export