Sari la conținut

Modul:License scope

--[=[
Implements [[Template:License scope]] and [[Template:License grammar]]
]=]

local p = {} --p stands for package

local getArgs = require('Modul:Arguments').getArgs
local yesno = require('Modul:Yesno')

local namespace = mw.title.getCurrentTitle().nsText

function p.plural_namespace()
	local plural_namespaces = {
		["Autor"] = true,
		["Discuție Autor"] = true,
		["Portal"] = true,
		["Discuție Portal"] = true,
		["Categorie"] = true,
		["Discuție Categorie"] = true
	}
	return plural_namespaces[namespace] or false
end

--[=[
Implements [[Template:License scope]]
]=]

function p._license_scope(args)
	if not args then
		args = {}
	end
	
	local text
	if p.plural_namespace() then
		local usesome
		if namespace == "Categorie" or namespace == "Discuție Categorie" then
			usesome = yesno(args.usesome or 'no')
		else
			usesome = yesno(args.usesome or 'yes')
		end
		if usesome then
			text = "Unele sau toate lucrările "
		else
			text = "Lucrările "
		end
		if namespace == "Autor" or namespace == "Discuție Autor" then
			text = text .. "acestui autor"
		elseif namespace == "Portal" or namespace == "Discuție Portal" then
			text = text .. "listate în acest portal"
		elseif namespace == "Categorie" or namespace == "Discuție Categorie" then
			text = text .. "din această categorie"
		end
	elseif namespace == "Fișier" or namespace == "Discuție Fișier" then
		text = "Acest fișier"
	elseif namespace == "Imagine" or namespace == "Discuție Imagine" then
		text = "Această imagine"
	else
		text = "Această lucrare"
	end
	
	local useverb = yesno(args.useverb) or args.useverb == nil
	if useverb then
		local past = yesno(args.past or 'no')
		if past and p.plural_namespace() then
			text = text .. " au fost"
		elseif past then
			text = text .. " a fost"
		elseif p.plural_namespace() then
			text = text .. " sunt"
		else
			text = text .. " este"
		end
	end
	
	if yesno(args.lc or 'no') then
		text = string.lower(text)
	end
	
	return text
end

function p.license_scope(frame)
	return p._license_scope(getArgs(frame))
end

--[=[
Implements [[Template:License grammar]]
]=]

function p._license_grammar(args)
	if not args then
		args = {}
	end
	if p.plural_namespace() then
		return args[2]
	else
		return args[1]
	end
end

function p.license_grammar(frame)
	return p._license_grammar(getArgs(frame))
end

return p