Module:User:Justinrleung/zh-reg-syn

local export = {}

local region_list = { "Mainland China", "Taiwan", "Hong Kong", "Macau", "Malaysia", "Singapore" }

local region_data = { ["Mainland China"] = { colour = "FAF0F2", link = "Mainland China", },

["Taiwan"] = { colour = "F0F5FA", link = "Taiwanese Mandarin", },

["Hong Kong"] = { colour = "FAF5F0", link = "Hong Kong", },

["Macau"] = { colour = "F0FAF3", link = "Macau", },

["Malaysia"] = { colour = "FAF9F0", link = "Malaysian Mandarin", },

["Singapore"] = { colour = "FAF0F6", link = "Singaporean Mandarin" }, }

function export.main(frame) local args = frame:getParent.args local pagename = mw.title.getCurrentTitle.text local target_page = args[1] or pagename local resource_page = "Module:User:Justinrleung/North Korea" --"Module:zh/data/reg-syn/" .. target_page if mw.title.new(resource_page).exists then m_syndata = require(resource_page).list else return-- frame:expandTemplate{ title = "Template:zh-dial/uncreated", args = { target_page } } end

main_title = mw.ustring.gsub((target_page == pagename and pagename or  .. target_page .. ), "[0-9%-]", "") text = [=[ {| class="wikitable mw-collapsible mw-collapsed" style="margin:0; text-align:center;" |-	! style="background:#FCFFFC; width:40em" colspan=3 | Regional synonyms of ]=] .. main_title .. "\n" .. [=[	|-	! style="background:#E8ECFA" | Region ! style="background:#E8ECFA" | Words]=] .. [=[	 []=] ..		tostring(mw.uri.fullUrl("Module:zh/data/reg-syn/" .. target_page, { ["action"] = "edit" })) .. ' edit] ' for _, region in ipairs(region_list) do		local synonyms = m_syndata[region] if synonyms[1] ~= "" then local formatted_synonyms = {} for i, synonym in ipairs(synonyms) do				local synonym_decomp = mw.text.split(synonym, ":") table.insert(formatted_synonyms, "" .. synonym_decomp[1] .. "" ..					(synonym_decomp[2] and ' ''' .. synonym_decomp[2] .. ''' ' ..					(i < #synonym_set and ' ' or "") or "")) end local reg_data = region_data[region] text = text .. '\n|- style="background:#' .. reg_data.colour .. '"\n! " .. region .. "" .. '\n| ' .. table.concat(formatted_synonyms, "、") end end return text .. '\n|}' end

return export