Notule d' esplikêyes

Ci module ci sieve a dner les infôrmåcions des lingaedjes sorlon leu côde ISO (cwand end a onk), metans wa pol walon. Les infôrmåcions sont dins les dzo-pådjes Module:Lingaedje/data et Module:Lingaedje/drapeas (po les drapeas)

Cisse pådje u ci hagnon ci est co a scrire, u a mete d’ adrame. Si vos avoz des cnoxhances so l’ sudjet, vos l’ ploz fé vos-minme.

Tcherdjaedje

candjî

Po poleur eployî ci module dins èn ôte, el fåt tcherdjî :

l = require("Module:Lingaedje")

Fonccions po les modules

candjî

get_table(code)

Ritoûne on tåvlea di dnêyes pol lingaedje k' a code come côde ISO, u bén nil si code n' est nén ricnoxhou.
table = l.get_table("fr")

get_name(code)

Ritoûne li no (e walon) do lingaedje k' a code come côde ISO, u bén nil si code n' est nén ricnoxhou.
name = l.get_name("fr") -- rind « francès »

get_flag(code[, small])

Ritoûne li wikicôde po håyner li (les) drapea(s) po l' lingaedje k' a code come côde ISO, u bén ene vude tchinne si code n' est nén ricnoxhou (lingaedje nén cnoxhou udonbén onk avou nou drapea d' defini).
Si small a-st ene valixhance di true, adon li drapea serè håyné pus ptit.
flag = l.get_flag("fr")
flag_small = l.get_flag("fr", true)

Fonccions po les modeles

candjî

get_name_template(1=code)

Ritoûne li no do lingaedje k' a code come côde ISO, u bén ene vude tchinne si code n' est nén ricnoxhou.
{{#invoke:Lingaedje|get_name_template|fr}} → « francès »
{{#invoke:Lingaedje|get_name_template|abcxyz}} → «  »
Li paramete 1 pout vni d' on modele, metans
dins Modele:ÈMBIAMODELE : {{#invoke:Lingaedje|get_name_template}}, k' est l' minme ki {{#invoke:Lingaedje|get_name_template|{{{1|}}}}} u co {{#invoke:Lingaedje|get_name_template|1={{{1|}}}}}
adon {{ÈMBIAMODELE|fr}} → « francès »

local p = {}
local builder = require("Module:Builder")

-- Return the table of a language by its code
function p.get_table(code)
    -- if none code given, return nil
    if (code == nil) then return nil end
    -- trim code
    code = mw.text.trim(code)
    -- lower case
    code = string.lower(code)
    
    -- get the table of languages
    local languages = mw.loadData('Module:Lingaedje/data')
    
    -- return the table of a language code, if exists
    if (languages[code] and languages[code]['name']) then
        return languages[code]
    else
        return nil
    end
end

-- Return the name of a language by its code
function p.get_name(code)
	language = p.get_table(code)
    if (language and language['name']) then
        return language['name']
    else
        return nil
    end
end

-- Get name from template
function p.get_name_template(frame)
    local args
    if frame.args ~= nil and frame.args[1] ~= nil then
        args = frame.args
    else
        args = frame:getParent().args
    end
    local code = args[1]
    
    local language = p.get_name(code)
    
    if (language == nil or language == '') then
        return ''
    else
        return language
    end
end

-- Return a list of scripts used by the given language
function p.get_scripts(code)
	language = p.get_table(code)
    if (language and language['scripts']) then
        return language['scripts']
    else
        return nil
    end
end

-- Return flag(s) as wikitext of a language by its code
function p.get_flag(code, small)
    code = string.lower(code)
	language = p.get_table(code)
	local flag = ""
	local size = 3 -- large
	
	if small == true then
		size = 2
	end
	
    if (language and language['name']) then
    	local flags = require("Module:Lingaedje/drapeas")
    	if (flags[code] ~= nil and flags[code] ~= {}) then
        	if(type(flags[code][1]) == "table") then
        		flag = flag .. "[[Imådje:"..flags[code][1][1].."|"..flags[code][1][size].."px|link=]]"
        		flag = flag .. "[[Imådje:"..flags[code][2][1].."|"..flags[code][2][size].."px|link=]]"
        		if (flags[code][3] ~= nil) then
        			flag = flag .. "[[Imådje:"..flags[code][3][1].."|"..flags[code][3][size].."px|link=]]"	
        		end
        	elseif flags[code][1] ~= nil then
        		flag = "[[Imådje:"..flags[code][1].."|"..flags[code][size].."px|link=]]"
        	end
        	return flag
        end
    else
        return nil
    end
end

-- Get name from template
function p.get_flag_template(frame)
    local args
    if frame.args ~= nil and frame.args[1] ~= nil then
        args = frame.args
    else
        args = frame:getParent().args
    end
    local code = args[1]
    local small = args[2]
    
    if small == "oyi" then
    	small = true
    else
    	small = false
    end
    
    local flag = p.get_flag(code, small)
    
    if (flag == nil or flag == '') then
        return ''
    else
        return flag
    end
end

-- Get title from language code
function p.get_title(frame)
    builder.init(frame)
    local args = frame.args
    local lang, lang_code , lang_name = nil
    local help_link = ' <sup>[[Wiccionaire:Djivêye des lingaedjes|(?)]]</sup>'
    local scrijha, script = nil

    -- get language name
    if args[1] ~= nil and args[1] ~= "" then
    	lang_code = args[1]
    	lang = p.get_table(lang_code)
    end
    
    if (lang == nil or lang == '' or 
    	lang.name == nil or lang.name == '') then
    	builder.add_category('Årtikes avou on lingaedje nén rkinoxhou')
    	builder.add_content('<span data-lang-section="unknown-lang">Lingaedje nén rkinoxhou « '..lang_code..' »</span>' .. help_link)
        return builder.get_content()
    end
    
    -- if a flag exists prepend it
    flag = p.get_flag(lang_code)
	if flag ~= nil then
		builder.add_content(flag .. " ") 
	end

    local langObj = mw.language.new("wa")
	-- maybe it isn't a language but:
	-- a script name
	if lang_code == "s" and args[2] ~= nil then
    	scrijha = require('Module:Scripe')
    	script = scrijha.get_table(args[2])
    	
		local script_code = args[2]
		local script_name = script['name'] 

		-- TODO: radjouter on loyén eviè l' sistinme di scrijhaedje (so wikipedia ?)
		
		if script_name == nil then
			script_name = ''
		else
			script_name = ' '..script_name
		end
		lang_code = script_code
		title_name = langObj:ucfirst(lang.name)..script_name
	-- a translingual symbol
	elseif lang_code == "mul" then
		title_name = langObj:ucfirst(lang.name)
	-- a language name
	else
    	local title_page =mw.title.new( langObj:ucfirst(lang.name), "Wiccionaire" )
    	local title_ucfirst = langObj:ucfirst(lang.name)
    	if(title_page.exists) then
    		title_name = '[[Wiccionaire:'..title_ucfirst..'|'..title_ucfirst..']]'
    	else
    		title_name = title_ucfirst
    	end
    end
   	-- special compatibility case (for external links)
   	if lang_code == "wa-fel" then
   		builder.add_content(frame:newParserValue('<span id="Walon-Feller">'..
	    										 '<span id="'..lang_code..'" data-lang-section="'..lang_code..'">'..title_name..'</span>'
	    										 ..'</span>').expand())
	else
	    builder.add_content(frame:newParserValue('<span id="'..lang_code..'" data-lang-section="'..lang_code..'">'..title_name..'</span>').expand())
   	end
    
	-- if there is a complement title
	if (lang.comp_title ~= nil and lang.comp_title ~= '') then
        builder.add_content(frame:newParserValue("<small>"..lang.comp_title.."</small>").expand())
    end
    
    -- lingaedje u bén scrijha
    if scrijha ~= nil then
    		builder.add_category( 'Scrijhas '.. script['addjpl'] )
    else
    	-- mot u bén boket d' lingaedje/dijhêye
	    if(lang_code ~= "mul") then
		    if args[2] ~= nil and (args[2] == "bl" or args[2] == "dijh") then
		    	if args[2] == "dijh" then
		    		builder.add_category( p.grammar({args={'Dijhêyes', lang_code, '', fem='1'}}), 0 )
		    	end
		    	builder.add_category( p.grammar({args={'Bokets do lingaedje', lang_code, ''}}), 0 )
		    else
		    	builder.add_category( p.grammar({args={'Mots', lang_code, '', vowel='1'}}), 0 )
		    end
    	end
    	builder.add_category( langObj:ucfirst(lang.name), 0 )
    end
    
    -- tipografeye
    -- fåreut fé 'ne sacwè d' pus prôpe
    if lang_code == "fr" or lang_code == "wa" then
    	-- pådje avou on (des) « ' » dins l' tite 
    	if string.match(mw.title.getCurrentTitle().text, "'") then
    		builder.add_category( 'Årtikes ki fåreut mete ene apostrofe-crolete', 0 )
    	end
    	
    	-- coridjaedje otomatike sol tite del pådje (nén fwait pa MediaWiki)
    	-- [[:mw:Help:Magic_words#DISPLAYTITLE]]
    	local title_typo = mw.title.getCurrentTitle().text
    	title_typo = string.gsub(title_typo, "’ ", "’ " ) -- ’ + U+00A0
    	title_typo = string.gsub(title_typo, " :", " :" ) -- U+00A0 + :
    	title_typo = string.gsub(title_typo, " ;", " ;" ) -- U+202F + ;
    	if mw.title.getCurrentTitle().text ~= title_typo then
    		builder.add_content(frame:newParserValue('{{DISPLAYTITLE:'..title_typo..'}}').expand())
    		builder.add_category( 'Årtikes avou coridjaedje otomatike del tipografeye sol tite', 0 )
    	end
    end
    
    -- les mots avou on pont sol roye
    if lang_code == "pcd" or  lang_code == "pcd-fel"
    or lang_code == "wa-fel" then
    	if string.match(mw.title.getCurrentTitle().text, "%.") then
    		builder.add_category( p.grammar({args={'Mots', lang_code, 'avou on pont sol roye', vowel='1'}}), 0 )
    	end
    end
    
    -- les mots avou ene munute
    if lang_code == "wa-fel" 
    and string.match(mw.title.getCurrentTitle().text, "′") then
    		builder.add_category( p.grammar({args={'Mots', lang_code, 'avou ene munute', vowel='1'}}), 0 )
    end
    
    -- mot d' ene lete nén rcepåve po tos les lingaedjes
    if  mw.ustring.len(mw.title.getCurrentTitle().text) == 1 
    and lang_code ~= "mul" 
    and lang.name ~= "scrijha" then
    	builder.add_category(p.grammar({args={"Mots", lang_code, "d' on seu pî", vowel="1"}}), 0)	
    end
    
    return builder.get_content()
end

--[[
 V + do + C		: Mots do walon
 V + d’ l’ + V	: Mots d’ l’ almand
 C + do + C		: Sustantifs do walon
 C + di l’ + V	: Sustantifs di l’ almand
 
 e + C			: e walon
 e-n + V		: e-n inglès
]]--
function p.grammar(frame) 
	local langObj = mw.language.new("wa")
	local first = frame.args[1]
	local lang_code = string.lower(frame.args[2])
	local lang = p.get_name(lang_code)
	local last = frame.args[3]
	local sdo = "do"
	local cat = ""

	if lang and lang ~= "" then

		-- special case
		if lang_code == "la-vul" then
			lang = "patwès do latén"
			sdo = "d' on"
		end

		if first == "e" or string.match(first, " e$") then
			sdo = nil
		end
		
		-- if lang starting by vowel
		if string.find(lang, "^[aåeéèiïîou]") then
			if first == "e" or string.match(first, " e$") then
				first = string.gsub(first, "e$", "e-n")
			else
				-- if first ending by voyale (as « mots »)
				if frame.args.vowel and frame.args.vowel == "1" then
					sdo = "d' l'"
				else
					sdo = "di l'"
				end
			end
		end
		
		-- do + kimon => do cmon
		if string.find(lang, "^kimon ") then
			lang = string.gsub(lang, "kimon", "cmon")
		end
		
		-- lang variante Fel, vsis
		local variant = nil
		local pl = "s"
		if string.find(lang_code, "-fel$") then
			variant = " e Feller"
		elseif string.find(lang_code, "-vsis$") then
			variant = " ezès vîs sistinmes"
		elseif string.find(lang_code, "-wis$") then
			variant = " e sistinme Wisconsene"
		end
		if variant ~= nil then
			if frame.args.sg ~= nil and frame.args.sg == "1" then pl="" end
			if frame.args.fem and frame.args.fem == "1" then
				if mw.ustring.match( lang, "ès$") or
					mw.ustring.match( lang, "[aéiou]n$") or
					mw.ustring.match( lang, "[a]nd$") or
					mw.ustring.match( lang, "[aåéiîou]$") 
				then
					variant = " scrîte" .. pl .. variant
				else
					variant = " sicrîte" .. pl .. variant
				end
			else
				if mw.ustring.match( lang, "ès$") or
					mw.ustring.match( lang, "[aéiou]n$") or
					mw.ustring.match( lang, "[a]nd$") or
					mw.ustring.match( lang, "[aåéiîou]$") 
				then
					variant = " scrît" .. pl .. variant
				else
					variant = " sicrît" .. pl .. variant
				end
			end	
			last = variant .. " " .. last
		end
	
		if frame.args.ritch and frame.args.ritch == "1" then
			lang = "[["..lang.."]]"	
		end
		
		if sdo ~= nil then
			cat = first .. " " .. sdo .. " " .. lang .. " " ..last
		else
			cat = first .. " " .. lang .. " " ..last
		end
	else
		cat = first .. " " ..last
	end
	
	-- candje ’ e ' (po les categoreyes)
	if frame.args.keep_typo_quote ~= nil and frame.args.keep_typo_quote == "1" then
		cat = string.gsub(cat, "'", "’")
		cat = string.gsub(cat, "’ ", "’ ") -- non-breaking space
	else
		cat = string.gsub(cat, '’', "'")
	end
	
	return mw.text.trim(langObj:ucfirst(cat))
end

return p