Modul:s ali z

Iz Wikipedije, proste enciklopedije
Documentation icon Dokumentacija modula[predogled] [uredi] [zgodovina] [osveži]

Modul implementira predlogo S ali z. Izjeme so shranjene v Modul:S ali z/besede.

local p = {}
local words = mw.loadData('Modul:S ali z/besede')

local lcSChars = 'aeioubdgjlmnrvzž'
local ucSvChars = 'AEIOUBDGJLMNRVZŽ'

local function findWord(s, t)
	for i, v in ipairs(t) do
		if mw.ustring.find(s, '^' .. v .. '$') then
			return true
		end
	end
end

function p._main(args)
	local s = args[1] and mw.text.trim(args[1])
	local pron = 's'
	local ret = ''
	
	if s and s ~= '' then
		local origStr = s
		
		s = mw.ustring.gsub(s, '</?[A-Za-z][^>]->', '') -- Odstrani HTML-oznake
		s = mw.ustring.gsub(s, '%[%[[^%|]+%|(..-)%]%]', '%1') -- Odstrani wikipovezave
		s = mw.ustring.gsub(mw.ustring.gsub(s, '%[%[', ''), '%]%]', '')
		s = mw.ustring.match(s, '^%.?[0-9%u%l]+') or s -- Izvleci prvo besedo
		
		if mw.ustring.find(s, '^[-+]?[0-9]') then -- Če se začne s številko
			s = mw.ustring.match(s, '^[-+]?[0-9]+') -- Izvleci številko
			if findWord(s, words.vNumsZ) then -- Številke z z
				pron = 'z'
			end
		elseif mw.ustring.match(s, '^[0-9%u]+$') then -- It looks like an acronym
			if mw.ustring.find(s, '^[' .. ucSvChars .. ']')
			then
				pron = 'z'
			end
		else
			s = mw.ustring.lower(s) -- Uncapitalize
			if mw.ustring.find(s, '^['.. lcSChars .. ']') then -- Črka s
				if not findWord(s, words.vcWords) -- Exclude 'euro' etc.
					or findWord(s, words.vvWords) -- But not 'Euler' etc.
				then
					pron = 'z'
				end
			end
		end
		ret = pron .. ' ' .. origStr
	end
	
	return ret
end

function p.main(frame)
	return p._main(frame:getParent().args)
end

return p