Module:rm-dial

Hello, you have come here looking for the meaning of the word Module:rm-dial. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:rm-dial, but we will also tell you about its etymology, its characteristics and you will know how to say Module:rm-dial in singular and plural. Everything you need to know about the word Module:rm-dial you have here. The definition of the word Module:rm-dial will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:rm-dial, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.

Description

This module is invoked by {{rm-dial}}.


local export = {}
local m_links = require("Module:links")
local lang = require("Module:languages").getByCode("rm")

function export.rmdial(frame)
	
	local args = frame:getParent().args
	local pagename = mw.title.getCurrentTitle().text
	local target_page = args or pagename
	if pagename == "rm-dial" then
		target_page = "vacca"
	end
	local resource_page = "Module:rm/data/dial/" .. target_page
	local m_dialdata
	if mw.title.new(resource_page).exists then
		m_dialdata = require(resource_page).list
	else
		return frame:expandTemplate{ title = "Template:rm-dial/uncreated", args = { target_page } }
	end
	
	return export.make_table(m_dialdata, target_page)
	
end

function export.make_table(dialdata, headword)
	local result = {}
	local content = [=[
{| class="inflection-table vsSwitcher wikitable" style="margin: 0; margin-top: 2px; text-align: center; border-top: 0" rules="all"
! class="vsToggleElement" colspan="2" style="font-size:97.5%; background-color: var(--wikt-palette-red-2, #eaecf0); text-align:left; padding: 2px 10px 2px 10px" | Dialectal variants of this word
]=]
	table.insert(result, content)

	-- Normalise dialect names
	local name_map = {
		RG = "Rumantsch Grischun",
		Puter = "Putèr"
	}

	local grouped = {}
	for dial, form in pairs(dialdata) do
		form = mw.text.trim(form)
		dial = name_map or dial
		grouped = grouped or {}
		table.insert(grouped, dial)
	end

	local sorted_forms = {}
	for form in pairs(grouped) do
		table.insert(sorted_forms, form)
	end
	table.sort(sorted_forms)

	for _, form in ipairs(sorted_forms) do
		local dialects = grouped
		table.sort(dialects)
		for i, dial in ipairs(dialects) do
			form = format_links(form)
			if i == 1 then
				table.insert(result, '|- class="vsHide"\n! style="padding:10px; background-color: var(--wikt-palette-red-2, #eaecf0)" | ' .. dial .. '\n| style="padding:10px" rowspan="' .. #dialects .. '" | ' .. form)
			else
				table.insert(result, '|- class="vsHide"\n! style="padding:10px; background-color: var(--wikt-palette-red-2, #eaecf0)" | ' .. dial)
			end
		end
	end

	table.insert(result, '|}')
	return table.concat(result, '\n')
end

function format_links(link)
	if (link == nil or link == "" or link == "—") then
		return "—"
	else
		return m_links.full_link({lang = lang, term = link})
	end
end

return export