Module:Inflect senra: Difference between revisions

Created page with "local p = {} local function change_suffix(word, suffix) return (word:gsub("u$", suffix)) end local function template(language, word, tmpl) local lang = i18n[language] or i18n.en return (tmpl:gsub("[%$-][^%s]+", function(text) local suffix = text:match "%-(.*)" local translation = text:match "%$(.*)" if suffix then return change_suffix(word, suffix) elseif translation then return lang[translation] end end)) end local i18n = {} function p.table(lang..."
 
No edit summary
Line 21: Line 21:


function p.table(language, word)
function p.table(language, word)
do return language end
if not word:match"u$" then
if not word:match"u$" then
error("content word must be lemma (end with -u): "..word)
error("content word must be lemma (end with -u): "..word)

Revision as of 06:46, 18 September 2025

Documentation for this module may be created at Module:Inflect senra/doc

local p = {}

local function change_suffix(word, suffix)
	return (word:gsub("u$", suffix))
end

local function template(language, word, tmpl)
	local lang = i18n[language] or i18n.en
	return (tmpl:gsub("[%$-][^%s]+", function(text)
		local suffix = text:match "%-(.*)"
		local translation = text:match "%$(.*)"
		if suffix then
			return change_suffix(word, suffix)
		elseif translation then
			return lang[translation]
		end
	end))
end

local i18n = {}

function p.table(language, word)
	do return language end
	if not word:match"u$" then
		error("content word must be lemma (end with -u): "..word)
	end
	return template(language, word, [[
{{|class="wikitext"
|+ $inflections
! !! $regular !! $infinitive $imperative $adverbial
|-
! | || -u
|-
! $intransitive | -i | -ui | -e | -iń
|-
! $transitive | -a | -ua | -ea | -ań
}}
]])
end

i18n.en = {
	inflections = "inflections",
	regular = "regular",
	infinitive = "infinitive",
	imperative = "imperative",
	adverbial = "adverbial",
	intransitive = "intransitive",
	transitive = "transitive",
}

return p