Module:Ricepeure

Èn årtike di Wiccionaire.
Sauter à la navigation Sauter à la recherche
I gn a nén co di dzo-pådje /doc pol notule d' esplikêyes. Clitchîz cial po l' ahiver.
-- This module is used for caesuras of a word for printers
-- Only use with Modele:Ric as :
-- {{ric|word}} 
local p = {}
local builder = require("Module:Builder");
local language = require("Module:Lingaedje");

-- don't use dot (.) as separator but MIDDLE DOT (U+00B7)
local _ricChar = "·"
local _litNum = {"deus", "troes", "cwate", "cénk", "shijh", "set", "ût", "nouv", "dijh"} 

-- number of first caesura in string
function countRic(s)
    return select(2, s:gsub(_ricChar, ""))
end

-- search position of first caesura in unicode string
function indexOfFirstRic(s)
    return select(2, mw.ustring.find(s, _ricChar))
end

function render(text, lang)
	-- use _ricChar as separator, not dot
	local text = string.gsub(text, '%.', _ricChar)
	local text = string.gsub(text, '•', _ricChar)
	-- number or separators in text 
	local c = countRic(text)
	-- first part of return content
	builder.add_content("[[ricepeure|Ricepeures]] : ")
	-- namespace number
	local ns = mw.title.getCurrentTitle().namespace
	
	-- if text cleaned != pagename
	local pagename = mw.title.getCurrentTitle().text
	local text_c = string.gsub(text, _ricChar, '')
	local text_c = string.gsub(text_c, " ", ' ') -- no U+00A0 in real page title but U+0020
	if text ~= "" and text_c ~= pagename then
		if ns == 0 then
			builder.error("li mot dins l' ricepeure « "..text_c.." » est diferin do tite « "..pagename.." »")
			return false
		end
	end
	
	p = c+1	 --  pî(s)			
	if c > 0 then
		local f = indexOfFirstRic(text)
		if f == 1 or string.sub(text, -string.len(_ricChar)) == _ricChar then
			builder.error("« "..text .. " » n' est nén ene coreke ricepeure")
		elseif c == 1 and f == 2 then
			builder.add_content("nén [[rcepåve]]")
			builder.add_category(language.grammar({args={"Mots", lang, "di deus pîs", vowel="1"}}), 0)
		else
			if f == 2 then
				text = string.gsub(text, _ricChar, "", 1)
			end
			builder.add_content(text)
			if _litNum[(p-1)] ~= nil then
				builder.add_category(language.grammar({args={"Mots", lang, "di ".._litNum[(p-1)].." pîs", vowel="1"}}), 0)
			end
		end
	else
		builder.add_content("nén [[rcepåve]]")
		builder.add_category(language.grammar({args={"Mots", lang, "d' on seu pî", vowel="1"}}), 0)
	end
				
	return true 
end

-- Entry point of the module
function p.init(frame)	
	local text = ''
	local lang = "wa"
	
	if frame.args[1] then
		text = frame.args[1]
	end
	
	if frame.args["lang"] then
		lang = frame.args["lang"]
	end
		
	builder.init(frame, "Årtikes avou ene flotche dins l' ricepeure")	
	render(text, lang)	
			
    return builder.get_content()
end

return p