Module:Mots rishonnants

È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 make link for each argument
-- Only use with Modele:MR as :
-- {{MR|arg1|arg2|...}} 
local p = {}
local builder = require("Module:Builder");
local alpha = mw.loadData("Module:Mots rishonnants/alpha")

local function in_array (arr, val)
    for i, v in ipairs(arr) do
        if v == val then
            return true
        end
    end

    return false
end

-- Hello -> hello
-- hellô -> hello
local function strcleaned(s)
	local t = {}
	for codepoint in mw.ustring.gcodepoint( s ) do
	     for key,arr in ipairs(alpha) do
			if(in_array(arr, mw.ustring.char(codepoint))) then
				table.insert(t, arr[1])
			end
		end
	end
	return table.concat(t)
end

function box(words, is_letter)
	if is_letter then
		info = "Ershonnantès letes"
	else
		info = "Ershonnants mots"
	end
	
    return '<div class="mr noprint"><i>' .. info..' :</i> ' ..words .. '.</div>'
end

-- Entry point of the module
function p.init(frame)
	local args = mw.getCurrentFrame():getParent().args
	local pagename = mw.title.getCurrentTitle().text
	local pnc = strcleaned(pagename)
	local hash = {}
	local words = {}
	local is_letter = false
	builder.init(frame)
	
	-- if pagename is a letter (a, b, ...)
	-- use alpha table
	if mw.ustring.len(pagename) == 1 then
		is_letter = true
		-- check the alpha table concerned
		for key,arr in ipairs(alpha) do
			if(in_array(arr, pagename)) then
				args = arr 
			end
		end
	end
		
	for key,val in ipairs(args) do
		if (val ~= pagename) then
			-- check duplicated word
			if (not hash[val]) then
				hash[val] = true
				table.insert( words, "[["..mw.text.trim(val).."]]" )
				if not is_letter and strcleaned(val) ~= pnc then
					builder.add_category("Årtikes avou des mots diferints dins l' modele MR")
				end
			else
				builder.add_category("Årtikes avou des doblons dins l' modele MR")
			end
		end
	end
	
	words = table.concat(words, ", ")

	-- make box
	builder.add_content(box(words, is_letter))
			
    return builder.get_content()
end

return p