Module:AFE

Èn årtike di Wiccionaire.
Sauter à la navigation Sauter à la recherche
I gn a nén co di dzo-pådje /doc pol notûle d' esplikêyes. Clitchîz cial po l' ahiver.
-- This module makes span AFE for each argument
-- Only use with Modele:AFE as :
-- {{AFE|arg1|arg2|...}} 
local p = {}
local builder = require("Module:Builder"); 

function p.check_ipa(s)
	for cp in mw.ustring.gcodepoint( s ) do
	     if not (	(cp == 32 or cp == 46)					or	-- Latin Base 0020,002E (space,.)
	     			(cp >= 97 and cp <= 122)				or	-- Latin Base 0061–007A (a-z)
	     			(cp == 227 or cp == 228)				or	-- Latin-1 Supplement (ã,ä)
	     			(cp == 230 or cp == 231)				or	-- Latin-1 Supplement (æ,ç)
	     			(cp == 240 or cp == 245)				or	-- Latin-1 Supplement (ð,õ AFE ?)
	     			(cp == 248 or cp == 339)				or	-- Latin-1 Supplement (ø,œ)
	     			(cp == 295 or cp == 297 or cp == 331)	or	-- Latin Extended-A (ħ,ĩ AFE ?,ŋ) 
	    			(cp >= 592 and cp <= 687)				or	-- IPA Extensions 0250–02AF
	        		(cp >= 688 and cp <= 767)				or	-- Spacing Modifier Letters 02B0–02FF
	        		(cp >= 768 and cp <= 879)				or	-- Combining Diacritical Marks 0300–036F
	        		(cp == 946)								or	-- (β)
	        		(cp == 967)								or	-- (χ)
	        		(cp >= 7424 and cp <= 7551)				or	-- Phonetic Extensions 1D00–1D7F
	    			(cp >= 7552 and cp <= 7615)				or	-- Phonetic Extensions Supplement 1D80–1DBF
	    			(cp == 7869)							or	-- (ẽ) AFE ?
	    			(cp == 8255)								-- (‿)
	     ) then 
	    	--mw.log(cp .. " : "..mw.ustring.char(cp))
	    	return false
	    end
	end
	return true
end

function p.render(text)
	
	local span = mw.html.create("span")
	           : attr('class','afe')
	           : attr('title','Scrijhaedje e l’ alfabet fonetike eternåcionå')

	-- trim white spaces
	text = mw.text.trim(text)
	
	-- unicode char U+02C8 for primary stress, not « ' »
	text = string.gsub(text, "'", "ˈ")
	
	-- unicode char U+02D0 for long sound, not « : »
	text = string.gsub(text, ":", "ː")
	
	-- unicode char U+203F for linking, not « _ »
	text = string.gsub(text, "_", "‿")
	
	-- no treat \.+ or … as AFE
	if text == "" or string.find(text, '^%.+$') or text == "…" then
		builder.add_category("Årtikes avou des prononçaedjes a radjouter")
		builder.add_content('<span class="info">Prononçaedje a radjouter</span>')
		return 
	end
	
	-- delete / for check_ipa
	if string.sub(text, 1, 1) == "/" then
		text = string.sub(text, 2)
	end
	if string.sub(text, -1)== "/" then
		text = string.sub(text, 1,-2)
	end
	
	if not p.check_ipa(text) then
		span:addClass('flotche')
		builder.add_category("Årtikes avou des flotches dins l' AFE")
	end
	
	span:wikitext("/"..text.."/")
	builder.add_content(span)
end

-- Entry point of the module
function p.init(frame)
	local html = ''
	local i = 0
	local dup = {}

	builder.init(frame, "Årtikes avou ene flotche dins l' modele AFE")
	
	-- for each argument of the parent modele
	local modele = mw.getCurrentFrame():getParent()
	for key,val in ipairs(modele.args) do
		-- check duplicated arg
		if dup[val] ~= nil then
			builder.add_category("Årtikes avou des doblons dins l' modele AFE")
		else
			dup[val] = true
		
			-- white space between each span
			if i > 0 then
				builder.add_content(" ")
			end
			
			p.render(val)
			i = i + 1
		end
	end
	
    return builder.get_content()
end

return p