Module:Automatik/Outils

La documentation pour ce module peut être créée à Module:Automatik/Outils/Documentation

local p = {}

-- Retourne le code langue à partir du nom d'une langue ou retourne le nom de la langue sinon
function getCode( langue )
	local langues = mw.loadData('Module:langues/data')
	
	for k, v in pairs(langues) do
		if langues[k]['nom'] == langue then
			return k
		end
	end
	
	return langue
end

function p.langue_vers_code_L(frame)
	local nom_langue = frame.args[1]
	
	langue = mw.language.new( 'fr' )
	langue = langue:lcfirst( frame.args[1] )
	code = getCode( langue )
	
	if ( langue == code ) then
		return frame.args[1]
	else
		return code
	end
end

return p