Pumunta sa nilalaman

Module:sl-common

Mula Wiksiyonaryo


local export = {}

local rsplit = mw.text.split
local ulower = mw.ustring.lower
local rfind = mw.ustring.find
local unfd = mw.ustring.toNFD
local u = require("Module:string/char")
local GRAVE     = u(0x0300)
local ACUTE     = u(0x0301)
local MACRON    = u(0x0304)
local DGRAVE    = u(0x030F)
local INVBREVE  = u(0x0311)

--[==[
Return true if `word` (a single word in NFC format) has accents.
]==]
function export.has_accents(word)
	return not not rfind(ulower(word), "[áéíóŕúȃȇȋȏȓȗāēīōūȁȅȉȍȕèẹọ" .. GRAVE .. ACUTE .. MACRON .. DGRAVE .. INVBREVE .. "]")
end

--[==[
Return true if `term` (which may be multiword but should be in NFC format) needs accents.

FIXME: This currently won't return true on a monosyllabic word containing a syllabic r without an accent.
]==]
function export.needs_accents(term)
	local words = rsplit(term, " ")
	for _, word in ipairs(words) do
		if rfind(ulower(unfd(word)), "[aeiou]") and not export.has_accents(word) then
			return true
		end
	end
	return false
end

--[==[
Remove accents from the specified Slovene term (which may be multiword).
]==]
function export.remove_accents(term)
	return (require("Module:languages").getByCode("sl"):makeEntryName(term))
end

function export.is_soft(stem)
	if mw.ustring.find(stem, "[cjčšž]$") then
		return true
	else
		return false
	end
end

function export.first_palat(stem)
	if stem:sub(-2) == "k" then return stem:sub(1, -2) .. "č"
	elseif stem:sub(-2) == "g" then return stem:sub(1, -2) .. "ž"
	elseif stem:sub(-3) == "sk" then return stem:sub(1, -3) .. "šč"
	else return stem
	end
end

function export.second_palat(stem)
	if stem:sub(-2) == "k" then return stem:sub(1, -2) .. "c"
	elseif stem:sub(-2) == "g" then return stem:sub(1, -2) .. "z"
	else return stem
	end
end

function export.iotation(stem)
	if stem:sub(-2) == "sk" then return stem:sub(1, -3) .. "šč"
	elseif stem:sub(-2) == "sl" then return stem:sub(1, -3) .. "šlj"
	elseif stem:sub(-1) == "t" or stem:sub(-1) == "k" or stem:sub(-1) == "c" then return stem:sub(1, -2) .. "č"
	elseif stem:sub(-1) == "g" or stem:sub(-1) == "z" then return stem:sub(1, -2) .. "ž"
	elseif stem:sub(-1) == "h" or stem:sub(-1) == "s" then return stem:sub(1, -2) .. "š"
	elseif stem:sub(-1) == "d" then return stem:sub(1, -2) .. "j"
	elseif stem:sub(-1) == "m" then return stem:sub(1, -2) .. "mlj"
	elseif stem:sub(-1) == "p" then return stem:sub(1, -2) .. "plj"
	elseif stem:sub(-1) == "b" then return stem:sub(1, -2) .. "blj"
	elseif stem:sub(-1) == "v" then return stem:sub(1, -2) .. "vlj"
	else return stem
	end
end

function export.t(stem)
	if mw.ustring.find(stem, "st$") then return stem
	elseif mw.ustring.find(stem, "[bp]$") then return stem .. "st"
	elseif mw.ustring.find(stem, "[dtz]$") then return (mw.ustring.gsub(stem, ".$", "st"))
	elseif mw.ustring.find(stem, "[čgkrž]$") then return (mw.ustring.gsub(stem, ".$", "č"))
	else return stem .. "t"
	end
end

return export