Module:nl-common: difference between revisions

From Wiktionary, the free dictionary
Jump to navigation Jump to search
Content deleted Content added
No edit summary
m Protected "Module:nl-common": (bot) automatically protect highly visible templates/modules (reference score: 2000+ >= 1000) ([Edit=Allow only autoconfirmed users] (indefinite) [Move=Allow only autoconfirmed users] (indefinite))
 
(11 intermediate revisions by one other user not shown)
Line 3: Line 3:
-- Make a link out of a form, or show a dash if empty.
-- Make a link out of a form, or show a dash if empty.
function export.link_form(form, tag)
function export.link_form(form, tag)
if not PAGENAME then
PAGENAME = mw.title.getCurrentTitle().text
end
if type(form) == "table" then
if type(form) == "table" then
for n, subform in pairs(form) do
for n, subform in pairs(form) do
form[n] = link_form(subform, tag)
form[n] = export.link_form(subform, tag)
end
end
return table.concat(form, ", ")
return table.concat(form, ", ")
else
else
if form ~= "" then
if form ~= "" then
return "<" .. (tag or "span") .. " lang=\"nl\">[[" .. form .. (form ~= PAGENAME and "#Dutch|" .. form or "") .. "]]</" .. (tag or "span") .. ">"
if form == PAGENAME then
return "<" .. (tag or "span") .. " lang=\"nl\">[[" .. form .. "]]</" .. (tag or "span") .. ">"
else
return "<" .. (tag or "span") .. " lang=\"nl\">[[" .. form .. "#Dutch|" .. form .. "]]</" .. (tag or "span") .. ">"
end
else
else
return "&mdash;"
return "&mdash;"
end
end
end
end
end

function export.add_e(stem, weak_final, lengthen)
-- Vowel lengthening
if lengthen then
return stem:gsub("i(.)$", "e%1") .. "e"
-- Final weak syllable, no consonant doubling
elseif weak_final then
if stem:find("ie$") then
return stem:gsub("ie$", "ië")
else
return stem .. "e"
end
else
-- Ends in ee, ie, oe
if stem:find("[eio]e$") then
return stem .. "ë"
-- Ends in e
elseif stem:find("e$") then
return stem
-- Ends in double vowel + single consonant, remove one of the vowels
elseif stem:find("([aeou])%1[bcdfgklmnpqrstvxz]$") then
-- Add a diaeresis if the removal would create a digraph
if stem:find("[io]ee.$") then
return stem:gsub("..(.)$", "ë%1e")
else
return stem:gsub(".(.)$", "%1e")
end
-- Ends in single vowel + single consonant, double the consonant
elseif stem:find("[AaEeIiOoUu][bcdfgklmnpqrstvz]$") and not stem:find("[IiïOoö]e.$") and (not stem:find("[AaäEeëOoöUuü]i.$") or stem:find("qui.$")) and not stem:find("[AaäEeëOoö]u.$") then
return stem:gsub("(.)$", "%1%1e")
else
return stem .. "e"
end
end
end
end



Latest revision as of 09:33, 27 April 2024

This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

local export = {}

-- Make a link out of a form, or show a dash if empty.
function export.link_form(form, tag)
    if not PAGENAME then
        PAGENAME = mw.title.getCurrentTitle().text
    end
    
    if type(form) == "table" then
        for n, subform in pairs(form) do
            form[n] = export.link_form(subform, tag)
        end
        return table.concat(form, ", ")
    else
        if form ~= "" then
            return "<" .. (tag or "span") .. " lang=\"nl\">[[" .. form .. (form ~= PAGENAME and "#Dutch|" .. form or "") .. "]]</" .. (tag or "span") .. ">"
        else
            return "&mdash;"
        end
    end
end

function export.add_e(stem, weak_final, lengthen)
	-- Vowel lengthening
	if lengthen then
		return stem:gsub("i(.)$", "e%1") .. "e"
	-- Final weak syllable, no consonant doubling
	elseif weak_final then
		if stem:find("ie$") then
			return stem:gsub("ie$", "ië")
		else
			return stem .. "e"
		end
	else
		-- Ends in ee, ie, oe
		if stem:find("[eio]e$") then
			return stem .. "ë"
		-- Ends in e
		elseif stem:find("e$") then
			return stem
		-- Ends in double vowel + single consonant, remove one of the vowels
		elseif stem:find("([aeou])%1[bcdfgklmnpqrstvxz]$") then
			-- Add a diaeresis if the removal would create a digraph
			if stem:find("[io]ee.$") then
				return stem:gsub("..(.)$", "ë%1e")
			else
				return stem:gsub(".(.)$", "%1e")
			end
		-- Ends in single vowel + single consonant, double the consonant
		elseif stem:find("[AaEeIiOoUu][bcdfgklmnpqrstvz]$") and not stem:find("[IiïOoö]e.$") and (not stem:find("[AaäEeëOoöUuü]i.$") or stem:find("qui.$")) and not stem:find("[AaäEeëOoö]u.$") then
			return stem:gsub("(.)$", "%1%1e")
		else
			return stem .. "e"
		end
	end
end

return export