Module:ga-mutation

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

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

local m_links = require("Module:links")

local lang = require("Module:languages").getByCode("ga")

local export = {}


local function repl(forms, param)
	if param ~= "normal" and forms[param] == forms["normal"] then
		return "''not applicable''"
	end
	
	local ret = m_links.full_link({lang = lang, term = forms[param]})
	
	if param == "len" and forms.an ~= forms.normal then
		ret = ret .. "<br/>''after " .. m_links.full_link({lang = lang, alt = "an"}) .. ",'' " .. m_links.full_link({lang = lang, term = forms.an})
	end
	
	return ret
end


local table_cons = [=[
{| border="1" cellpadding="4" cellspacing="0" class="inflection-table" style="align: left; margin: 0.5em 0 0 0; border-style: solid; border: 1px solid #7f7f7f; border-right-width: 2px; border-bottom-width: 2px; border-collapse: collapse; background-color: #F8F8F8; font-size: 95%;"
|-
! colspan="3" | [[Appendix:Irish mutations|Irish mutation]]
|-
! Radical
! Lenition
! Eclipsis
|-
| {{{normal}}}
| {{{len}}}
| {{{ecl}}}
|-
| colspan="3" | <small style="font-size:85%;">''Note:'' Some of these forms may be hypothetical. Not every possible mutated form of every word actually occurs.</small>
|}]=]


function export.mut_cons(frame)
	local params = {
		[1] = {required = true, default = "{{{1}}}"},
		[2] = {required = true, default = "{{{2}}}"},
		}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local forms = require("Module:ga-common").mutations(args[1] .. args[2])
	
	return (mw.ustring.gsub(table_cons, "{{{([a-z0-9_]+)}}}", function(param) return repl(forms, param) end))
end


local table_vowel = [=[
{| border="1" cellpadding="4" cellspacing="0" class="inflection-table" style="align: left; margin: 0.5em 0 0 0; border-style: solid; border: 1px solid #7f7f7f; border-right-width: 2px; border-bottom-width: 2px; border-collapse: collapse; background-color: #F8F8F8; font-size: 95%;"
|-
! colspan="4" | [[Appendix:Irish mutations|Irish mutation]]
|-
! Radical !! Eclipsis !! with ''h''-prothesis !! with ''t''-prothesis
|-
| {{{normal}}}
| {{{ecl}}}
| {{{hpro}}}
| {{{tpro}}}
|-
| colspan="4" | <small style="font-size:85%;">''Note:'' Some of these forms may be hypothetical. Not every possible mutated form of every word actually occurs.</small>
|}]=]


function export.mut_vowel(frame)
	local params = {
		["uc"] = {type = "boolean"},
		}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local forms = require("Module:ga-common").mutations(mw.title.getCurrentTitle().subpageText, "msn")
	
	return (mw.ustring.gsub(table_vowel, "{{{([a-z0-9_]+)}}}", function(param) return repl(forms, param) end))
end


function export.mut(frame)
	local params = {
		[1] = {},
		}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local forms = require("Module:ga-common").mutations(mw.title.getCurrentTitle().subpageText, args[1])
	local wikicode = mw.ustring.find(mw.ustring.lower(mw.title.getCurrentTitle().subpageText), "^[aeiouáéíóú]") and table_vowel or table_cons
	
	return (mw.ustring.gsub(wikicode, "{{{([a-z0-9_]+)}}}", function(param) return repl(forms, param) end))
end

return export