Module:User:Justinrleung/zh-reg-syn
Jump to navigation
Jump to search
- This module sandbox lacks a documentation subpage. You may create it.
- Useful links: root page • root page’s subpages • links • transclusions • testcases • user page • user talk page • userspace
This is a private module sandbox of Justinrleung, for his own experimentation. Items in this module may be added and removed at Justinrleung's discretion; do not rely on this module's stability.
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]=] .. [=[
<div style="float: right; clear: right; font-size:60%"><span class="plainlinks">[]=] ..
tostring(mw.uri.fullUrl("Module:zh/data/reg-syn/" .. target_page, { ["action"] = "edit" })) ..
' edit]</span></div>'
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 '</span> <span style="font-size:60%"><i>' .. synonym_decomp[2] .. '</i></span>' ..
(i < #synonym_set and '<span class="Hani" lang="zh">' or "") or ""))
end
local reg_data = region_data[region]
text = text .. '\n|- style="background:#' .. reg_data.colour .. '"\n! [[w:' .. reg_data.link .. "|" .. region .. "]]" ..
'\n| ' .. table.concat(formatted_synonyms, "、")
end
end
return text .. '\n|}'
end
return export