Module:fi-dialects/helper

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

Implements utility functions for Finnish dialectal data modules.

add_word_for

[edit]

add_word_for(syns, word, parishes)

Adds the given word to syns, as returned by dialectal data modules, for all of the given parishes. parishes may be a table or a comma-separated list of parishes as a string.

local export = {}

local function add_word(syns, parish, word)
	if not syns[parish] then
		syns[parish] = word
	elseif type(syns[parish]) == "string" then
		syns[parish] = { syns[parish], word }
	else
		table.insert(syns[parish], word)
	end
end

function export.add_word_for(syns, word, parishes)
	if type(parishes) == "string" then
		for parish in mw.text.gsplit(parishes, ",") do
			add_word(syns, mw.ustring.gsub(mw.text.trim(parish), "[ .]", ""), word)
		end
	else
		for _, parish in ipairs(parishes) do
			add_word(syns, parish, word)
		end
	end
end

return export