Vejatz lo contengut

Mòdul:AFI

Un article de Wikipèdia, l'enciclopèdia liura.

La documentacion d'utilizacion d'aquel modul se pòt crear a Mòdul:AFI/ús

local IPA = { }

local Aisinas = require ( 'Mòdul:Aisinas' )

local success, toolTip = pcall ( mw.loadData, 'Mòdul:AFI/Infobotiòla' )

-- error if data not loaded
local messageFormat = [[<strong class="error">Le chargement du module AFI/Infobotiòla génère une erreur : </strong><br> %s<br> 
<span class="error">Cette erreur doit être corrigée pour que les infobulles explicatives soient de nouveau affichées.</span>
]]
local errorMessage
if not success then
	errorMessage = string.format( messageFormat, toolTip )
	toolTip = { }
end

local ipaClass = ' class="AFI nowrap"'
local ipaTitle = ' title="Alfabet fonetic internacional"'

local ipaStyle = ' style="font-family:'
	.. "'Segoe UI',"                  -- Widonws Vista, 7, 8
	.. "'DejaVu Sans',"               -- Most linux, OpenOffice, LibreOffice
	.. "'Lucida Grande',"             -- MacOsX
	.. "'Lucida Sans Unicode',"       -- Windows XP (but lack U+203F & U+035C)
	.. "'Arial Unicode MS',"          -- MS Office (provides U+203F & U+035C to Windows XP users)
	.. "'Hiragino Kaku Gothic Pro',"  -- ios 3+
	.. "sans-serif"                   -- default, Android.
	.. ';"'

local function symbolWithExemple( symbol )
	if type( symbol ) == 'string' then
		local title = toolTip[ Outils.trim( symbol ) ]
		if title then 
			return '<span title="' .. title ..'">' .. symbol .. '</span>'
		else
			return symbol
		end
	end
end

local function symbolWithLink( symbol )
	if symbol == '[' or symbol == ']' then
		return mw.text.nowiki( symbol )
	elseif symbol ~= '/' and Outils.trim( symbol ) then
		return '[[API ' .. symbol .. '|'.. symbolWithExemple( symbol ) .. ']]'
	else 
		return symbol
	end
end

local function separateSymbols( args )
	local len1 = args[1] and mw.ustring.len( args[1] )
	if args[2] == nil and len1 and len1 > 1 then
		local api = args[1]
		local apiCodes = { mw.ustring.codepoint( args[1], 1, len1 ) }
		local result = { }
		local i = 1
		while apiCodes[i] do
			local tmplen = 0
			if apiCodes[i + 2] and  apiCodes[i + 1] > 859 and apiCodes[i + 1] < 867 then -- tie
				tmplen = 2
			end
			if apiCodes[i + tmplen + 1] and apiCodes[i + tmplen + 1] > 767 and apiCodes[i + tmplen + 1] < 860 then -- Diacritical
				tmplen = tmplen + 1
			end
			table.insert( result, mw.ustring.sub( api, i, i + tmplen ) )
			i = i + tmplen + 1
		end
		return result
	end
	return args
end

local function symbolsWithLink( args )
	local wikiTable = {
		'<span' .. ipaClass .. ipaTitle ..  ipaStyle .. '>' 
	}
	local symbolsTable = separateSymbols( args )
	 
	local i = 1
	local symbol
	while symbolsTable[i] do
		symbol = symbolWithLink( symbolsTable[i] )
		if symbol then 
			table.insert( wikiTable, symbol )
		end
		i = i + 1
	end
	table.insert( wikiTable, '</span>' )
	
	return wikiTable
end

function IPA.mapi( frame )
	local args = Outils.extractArgs( frame )
	local wikiTable = symbolsWithLink( args )
	return table.concat( wikiTable )
end

function IPA.msapi ( frame )
	local args = Outils.extractArgs( frame )
	local wikiTable = symbolsWithLink( args )
	
	if mw.ustring.match(wikiTable[2], '[ʃɲjʄɟ]' ) then
		table.insert( wikiTable, 2, '&#8198;' )          -- &#8198; =  	Six-Per-Em Space, otherwise ʃ touches [ on windows.
	end
	if mw.ustring.match(wikiTable[#wikiTable - 1], '[ʃʈɭʄɖɻʠʧ]' ) then
		table.insert( wikiTable, #wikiTable, '&#8198;' )
	end
	 
	if not ( wikiTable[2] == '&#91;' or wikiTable[2] == '/' ) then
		table.insert( wikiTable, 2, '&#91;' )          -- &#91; = <nowiki>[</nowiki> 
		table.insert( wikiTable, #wikiTable, '&#93;' ) -- &#93; = <nowiki>]</nowiki> 
	end
	return table.concat( wikiTable )
end

function IPA.afi() --IPA.afi o IPA.api?
end

-- erreurModuleData affiche  d'un message d'erreur si le Module:Langue/Data n'a pas été chargé correctement,
-- pour la page de discussion de la base de donnée et ceux qui veulent surveiller cette page.
function IPA.toolTipModuleError()
    if success == false then 
        return errorMessage
    end
end

return IPA