Module:User:Aryamanarora/hi-dial-syn

From Wiktionary, the free dictionary
Jump to navigation Jump to search

This is a private module sandbox of Aryamanarora, for their own experimentation. Items in this module may be added and removed at Aryamanarora's discretion; do not rely on this module's stability.


local export = {}

local variety_list = {
	"Standard Hindi", "Poetic Hindi",
	"Standard Urdu",
	"Hindustani",
	"Braj", "Haryanvi", "Bundeli", "Kannauji",
	"Awadhi", "Bagheli", "Bhojpuri", "Chhattisgarhi",
}

local variety_colour = {
	["Standard Hindi"]	= "FAF0F2",
	["Poetic Hindi"]	= "FAF0F2",
	["Standard Urdu"]	= "FAF5F0",
	["Hindustani"]		= "F0F5FA",
	["Braj"]			= "F0F5FA",
	["Haryanvi"]		= "F0F5FA",
	["Bundeli"]			= "F0F5FA",
	["Kannauji"]		= "F0F5FA",
	["Awadhi"]			= "F0FAF3",
	["Bagheli"]			= "F0FAF3",
	["Bhojpuri"]		= "F0FAF3",
	["Chhattisgarhi"]	= "F0FAF3",
}

local special_note = {
	["Standard Hindi"] = "[[w:Hindi|Modern Standard Hindi]]",
	["Standard Urdu"] = "[[w:Urdu|Modern Standard Urdu]]",
}

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:Aryamanarora/hi-dial-syn/data" .. target_page
	local variety_data = require("Module:User:Aryamanarora/hi-dial-syn/data/dial")
	if mw.title.new(resource_page).exists then
		m_syndata = require(resource_page).list
	else
		return frame:expandTemplate{ title = "Template:hi-dial/uncreated", args = { target_page } }
	end
	
	local template = {
		["Standard Hindi"]	= {},
		["Poetic Hindi"]	= {},
		["Standard Urdu"]	= {},
		["Hindustani"]		= {},
		["Braj"]			= {},
		["Haryanvi"]		= {},
		["Bundeli"]			= {},
		["Kannauji"]		= {},
		["Awadhi"]			= {},
		["Bagheli"]			= {},
		["Bhojpuri"]		= {},
		["Chhattisgarhi"]	= {},
	}

	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 | Dialectal synonyms of <b><span class="Deva" lang="hi">]=] ..
		main_title .. '</span></b> (“' .. m_syndata["meaning"] .. '”) ' ..
		"[[Template:hi-dial-map/" .. target_page .. '|<small>&#91;map&#93;</small>]]\n' .. [=[
	|-
	! style="background:#E8ECFA" | Variety
	! style="background:#E8ECFA" | Location
	! style="background:#E8ECFA" | Words]=] .. [=[
	<div style="float: right; clear: right; font-size:60%"><span class="plainlinks">[]=] ..
		tostring(mw.uri.fullUrl("Module:User:Aryamanarora/hi-dial-syn/data/" .. target_page, { ["action"] = "edit" })) ..
	' edit]</span></div>'
	
	m_syndata["meaning"] = nil
	if m_syndata["note"] then
		note = m_syndata["note"]
		m_syndata["note"] = nil
	end
	
	for location, synonym_set in pairs(m_syndata) do
		if synonym_set[1] ~= "" then
			local formatted_synonyms = {}
			for i, synonym in ipairs(synonym_set) 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="Deva" lang="hi">' or "") or ""))
			end
			local location_data = variety_data[location]
			local location_name = mw.ustring.gsub(location_data.english or location, "(%(.*%))", "<small>%1</small>")
			local location_link = location_data.link or location_name
			table.insert(template[location_data.group],
				{ location_data.order, location_name, location_link, formatted_synonyms })
		end
	end
	
	for _, variety in ipairs(variety_list) do
		local colour = variety_colour[variety]
		if #template[variety] > 0 then
			table.sort(template[variety], function(first, second) return first[1] < second[1] end)
			for i, point_data in ipairs(template[variety]) do
				text = text .. "\n|-"
				if i == 1 then
					text = text .. "\n!rowspan=" .. #template[variety] .. (special_note[variety] and " colspan=2" or "") .. 
					' style="background:#' .. colour .. '"| ' .. (special_note[variety] or variety)
				end
				text = text .. ((point_data[2] and not special_note[variety]) and ('\n|style="background:#' .. colour .. '"| ' .. 
					'[[w:' .. point_data[3] .. '|' .. point_data[2] .. ']]') or '') ..
					'\n|style="background:#' .. colour .. '"| <span class="Deva" lang="hi">' ..
					table.concat(point_data[4], "、") .. '</span>'
			end
		end
	end

	if note and note ~= "" then
		text = text .. '\n|-\n! style="background:#FFF7FB; padding-top:5px; padding-bottom: 5px" | ' ..
			"<small>Note</small>\n| colspan=2|<small><i>" .. note .. "</i></small>"
	end
	
	return text .. '\n|}'
end

return export