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

local p = {}

local loc_langues = mw.loadData('Module:locution/data')

function p.contient_espaces(mot)
    if mot==nil then return nil end
    if (mw.ustring.find(mot, ". .") ~= nil) then
        return true
    else
        return false
    end
end

function p.is_locution(args, article, lang)
	if article == nil or article.text == nil or args == nil then return false end
	local titre = article.text
	
	-- Annexe ? Ne garde que la dernière sous-page
	if article.namespace==100 then
		titre = mw.ustring.gsub(titre, ".+\/", "")
	end
	
    -- Forcé par un paramètre
    if args['locution'] then
    	_ajoute_categorie('Wiktionnaire:Sections de type avec locution forcée')
 
    	if args['locution'] == 'oui' then
    		return true
    	elseif args['locution'] == 'non' then
    		return false
    	else
	    	_ajoute_categorie('Wiktionnaire:Sections avec paramètre locution invalide')
    	end
	end
	
	-- Liste blanche : on peut deviner automatiquement
	if loc_langues[lang] then
		return p.devine_locution(args, article, lang)
	else
		return false
	end
end

function p.devine_locution(args, article, lang)
	if article == nil or article.text == nil or args == nil then return false end
	local titre = article.text
	
    -- Cas spéciaux (par langue)
	if args[1] ~= nil and args[2] ~= nil then
		-- Verbes pronominaux français
		if args[2] == 'fr' and typ.get_nom_singulier(args[1]) == 'verbe' and mw.ustring.find(titre, "^se ") then
			if mw.ustring.find(titre, "^se [^ ]+ ") then
				return true
			else
				return false
			end
		-- Verbes pronominaux bretons
		-- https://fr.wiktionary.org/wiki/Wiktionnaire:Wikid%C3%A9mie/mars_2018#Verbes_pronominaux_en_breton
		elseif args[2] == 'br' and typ.get_nom_singulier(args[1]) == 'verbe' and mw.ustring.find(titre, "^en em ") then
			if mw.ustring.find(titre, "^en em [^ ]+ ") then
					return true
				else
					return false
				end
		-- Verbes pronominaux néerlandais
		elseif args[2] == 'nl' and typ.get_nom_singulier(args[1]) == 'verbe' and mw.ustring.find(titre, "^zich ") then
			if mw.ustring.find(titre, "^zich [^ ]+ ") then
					return true
				else
					return false
				end
		-- Verbes à particule néerlandais
		elseif args[2] == 'nl' and typ.get_nom_singulier(args[1]) == 'verbe'
		-- est-ce que le verbe finit par " aan", " achter", " af", etc ?
		and (mw.ustring.find(titre, " aan$")
		or mw.ustring.find(titre, " aaneen$")
		or mw.ustring.find(titre, " achter") 
		or mw.ustring.find(titre, " achterna$")
		or mw.ustring.find(titre, " achterover$")
		or mw.ustring.find(titre, " achteruit$")
		or mw.ustring.find(titre, " achteruit$")
		or mw.ustring.find(titre, " af$")
		or mw.ustring.find(titre, " beet$")
		or mw.ustring.find(titre, " bij$")  
		or mw.ustring.find(titre, " bijeen$")
		or mw.ustring.find(titre, " binnen$")
		or mw.ustring.find(titre, " bloot$")
		or mw.ustring.find(titre, " boven$")
		or mw.ustring.find(titre, " buiten$")
		or mw.ustring.find(titre, " deel$")
		or mw.ustring.find(titre, " dicht$")
		or mw.ustring.find(titre, " dood$")
		or mw.ustring.find(titre, " door$")
		or mw.ustring.find(titre, " droog$")
		or mw.ustring.find(titre, " fijn$")
		or mw.ustring.find(titre, " gaar$")
		or mw.ustring.find(titre, " gelijk$")
		or mw.ustring.find(titre, " glad$")
		or mw.ustring.find(titre, " goed$")
		or mw.ustring.find(titre, " groot$")
		or mw.ustring.find(titre, " hard$")
		or mw.ustring.find(titre, " in$")
		or mw.ustring.find(titre, " ineen$")
		or mw.ustring.find(titre, " klein$")
		or mw.ustring.find(titre, " kort$")
		or mw.ustring.find(titre, " kwijt$")
		or mw.ustring.find(titre, " lang$")
		or mw.ustring.find(titre, " langs$")
		or mw.ustring.find(titre, " leeg$")
		or mw.ustring.find(titre, " los$")
		or mw.ustring.find(titre, " mede$")
		or mw.ustring.find(titre, " mee$")
		or mw.ustring.find(titre, " mis$")
		or mw.ustring.find(titre, " na$")
		or mw.ustring.find(titre, " neer$")
		or mw.ustring.find(titre, " om$")
		or mw.ustring.find(titre, " omver$")
		or mw.ustring.find(titre, " onder$")
		or mw.ustring.find(titre, " op$")
		or mw.ustring.find(titre, " open$")
		or mw.ustring.find(titre, " opeen$")
		or mw.ustring.find(titre, " over$")
		or mw.ustring.find(titre, " raak$")
		or mw.ustring.find(titre, " recht$")
		or mw.ustring.find(titre, " rond$")
		or mw.ustring.find(titre, " samen$")
		or mw.ustring.find(titre, " scheef$")
		or mw.ustring.find(titre, " schoon$")
		or mw.ustring.find(titre, " stil$")
		or mw.ustring.find(titre, " stuk$")
		or mw.ustring.find(titre, " tegen$")
		or mw.ustring.find(titre, " terecht$")
		or mw.ustring.find(titre, " terug$")
		or mw.ustring.find(titre, " toe$")
		or mw.ustring.find(titre, " uit$")
		or mw.ustring.find(titre, " vast$")
		or mw.ustring.find(titre, " vlak$")
		or mw.ustring.find(titre, " vol$")
		or mw.ustring.find(titre, " voor$")
		or mw.ustring.find(titre, " voort$")
		or mw.ustring.find(titre, " voorbij$")
		or mw.ustring.find(titre, " vooruit$")
		or mw.ustring.find(titre, " vrij$")
		or mw.ustring.find(titre, " weg$")
		or mw.ustring.find(titre, " warm$")
		or mw.ustring.find(titre, " zwart$")) then
			-- On teste la présence d'une seule espace
			if mw.ustring.find(titre, "^[^ ]+ [^ ]+$") then
				return false
			else
				return true
			end
		end
	end
	
    -- Par défaut : espaces = locution
    if p.contient_espaces(titre) then
        return true
    else
    	return false
    end
end

return p