Modul:Chybný zápis

Dokumentaci tohoto modulu lze vytvořit na stránce Nápověda:Modul:Chybný zápis

-- @brief
--  Backend for {{Chybný zápis}}.
-- 
-- @details
--  Writes the wrong spelling item.
-- 
-- @author
--  [[meta:User:Danny B.]]
local _module = {}
----------------------------------------


local Error = require "Module:Error"
local Language = require "Module:Language"


-- @brief
--  Writes the wrong spelling item.
-- 
-- @param
--  frame The current frame object
function _module.print( frame )
	
	local output = ""
	local parentFrame = frame:getParent()
	local templateArgs = parentFrame.args
	local errorData = { template = "Chybný zápis" }
	
	local entry = mw.text.trim( templateArgs["1"] or "" )
	local ofWhat = mw.text.trim( templateArgs["2"] or "slova" )
	local lang = mw.text.trim( templateArgs["jazyk"] or "" )
	
	local langName = Language:getName( lang )
	
	
	if entry == "" then
		errorData.missingValue = { paramName = 1, paramDesc = "správný zápis" }
		output = output .. Error.getText( errorData )
	end
	
	if lang == "" then
		errorData.missingValue = { paramName = "jazyk", paramDesc = "kód jazyka" }
		output = output .. Error.getText( errorData )
	end
	
	if not langName then
		errorData.unknownValue = { paramName = "jazyk", paramDesc = "kód jazyka" }
		output = output .. Error.getText( errorData )
	end
	
	if output == "" then
		output = "<span class=\"wrong-spelling\">Chybný zápis " .. ofWhat .. " [[" .. entry .. "]].</span>"
		if mw.title.getCurrentTitle().namespace == 0 then
			output = output .. "[[Kategorie:Chybný zápis/" .. langName .. "]]"
		end
	end
	
	output = frame:preprocess( output )
	
	return output
	
end


----------------------------------------
return _module