Модул:sw-utilities

Документација модула[прикажи] [уреди] [историја] [освежи]
За овај шаблон потребна документација.
Please document this template by describing its purpose and usage on the documentation page.

local m_links = require("Модул:links")
local m_head = require("Модул:headword")

local lang = require("Модул:languages").getByCode("sw")

local export = {}

function export.plural(frame)
    local word = frame.args[1]
    local sg_class = frame.args[2]

    word = word:gsub("^" .. sg_class .. (sg_class == "m" and "u?" or ""), "")

    return word
end

function link_words(input_string)
	local contains_words = false
	local spacingPunctuation = "([%s%p]+)"
	local notWordPunc = "([^-־׳״'.·*]+)"
	local function workaround_to_exclude_chars(s)
		return mw.ustring.gsub(s, notWordPunc, "]]%1[[")
	end
	for possibleWordBreak in mw.ustring.gmatch(input_string, spacingPunctuation) do
		if mw.ustring.find(possibleWordBreak, notWordPunc) then
			contains_words = true
			break
		end
	end
	if contains_words then
		return "[["
				.. mw.ustring.gsub(
					input_string,
					spacingPunctuation,
					workaround_to_exclude_chars
					)
				.. "]]"
	else
		return input_string
	end
end

function export.verb_headword(frame)
	local params = {
		[1] = {},
		["head"] = {},
	}
	
	local args = require("Модул:parameters").process(frame:getParent().args, params)
	local head = args["head"] or mw.title.getCurrentTitle().text
	local inf = args[1] or "ku"..head
	
	head = '-'..link_words(head)
	inf = link_words(inf)
	
	local data = {lang = lang,
		pos_category = "verbs",
		categories = {},
		heads = {head},
		inflections = {{label="infinitive", inf}}}

	return m_head.full_headword(data)
end

return export