Notule d' esplikêyes

Ci module ci sieve a dner les infôrmåcions des sistinmes di scrijhaedje sorlon leu côde ISO (cwand end a onk), metans Latn pol sicrijhaedje e latenès letes, Cyrl pol cirilike, evnd. Les infôrmåcions sont dins l' dizo-pådje Module:Scripe/data; vos l' poloz ecråxhî tot rcopiant des dnêyes di wikt:en:Module:scripts/data (mins asteme ki les nos des tchamsp polèt esse diferins)

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î :

s = require("Module:Scripe")

Fonccions po les modules candjî

get_table(code)

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

get_name(code)

Ritoûne li no (e walon) do sistinme di scrijhaedje k' a code come côde ISO, u bén nil si code n' est nén ricnoxhou.
name = s.get_name("Cyrl") -- rind « cirilike »

findBestScript(text, lang)

Ritoûne li côde ISO do scripe ki corespond å tecse « text » sicrît dins l' lingaedje ki s' côde ISO est lang.
Po les lingaedjes ki s' sicrijhèt avou on seu sistinme, li côde di ç' sistinme la est rtourné; ôtrumint, li tecse est comparé ås djivêyes di caracteres characters di tchaeke sicripe do lingaedje.
cisse fonccion ci eploye divintrinnmint l' module Module:Lingaedje po-z aveur les scripes do lingaedje.
Si l' lingaedje n' est nén cnoxhou, il est veyou come li code und, po les nén cnoxhous lingaedjes, eyet bråmint di scripes vont esse sayîs (mins ça prind pus di timps, a-z eviter si possibe)
Si l' tecse est vude, ou si l' sicripe ni pout nén esse trové, li code None est rtourné.
code = s.findBestScript("غرشال", "ary") -- rind « Arab »
code = s.findBestScript("guerchane", "ary") -- rind « Latn »
code = s.findBestScript("ⴰⴱⴰⴱⴱⴰ", "") -- rind « Tfng », mins ça va pus abeye si "zgh" est dné come lingaedje
code = s.findBestScript(" 123 ", "wa") -- rind « None »

CO A FÉ candjî

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.
  • fé des fonccions po rtourner les ôtes parametes (li no addjectif pluriyal, po-z eployî dins les categoreyes; li sôre (alfabet, abouguida,...); li sinse di scrijhaedje (hintche a droete ou droete a hintche)
  • recråxhî les dnêyes

Fonccions po les modeles candjî

get_name_template(1=code)

Ritoûne li no do sistinme di scrijhaedje k' a code come côde ISO, u bén ene vude tchinne si code n' est nén ricnoxhou.
{{#invoke:Scripe|get_name_template|Armn}} → « årmenyin »
{{#invoke:Scripe|get_name_template|Abcxyz}} → «  »
Li paramete 1 pout vni d' on modele, metans
dins Modele:ÈMBIAMODELE : {{#invoke:Scripe|get_name_template}}, k' est l' minme ki {{#invoke:Scripe|get_name_template|{{{1|}}}}} u co {{#invoke:Scripe|get_name_template|1={{{1|}}}}}
adon {{ÈMBIAMODELE|Latn}} → « latén »


CO A FÉ candjî

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.
  • candjî get_script_template a on meyeu no
  • fé des fonccions po rtourner les ôtes parametes (li no addjectif pluriyal, po-z eployî dins les categoreyes; li sôre (alfabet, abouguida,...); li sinse di scrijhaedje (hintche a droete ou droete a hintche)

local p = {}

-- Return the table of a script 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)

	-- normalize
	local langObj = mw.language.new("wa")
    code = langObj:ucfirst(code)

    -- get the table of scripts
    local scripts = mw.loadData('Module:Scripe/data')
    
    -- return the table of a script code, if exists
    if (scripts[code] and scripts[code]['name']) then
        return scripts[code]
    else
        return nil
    end
end

-- Return the name of a script by its code
function p.get_name(code)
	script = p.get_table(code)
    if (script and script['name']) then
        return script['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 script = p.get_name(code)
    
    if (script == nil or script == '') then
        return ''
    else
        return script
    end
end

-- count the matching characters
-- (copied from wkt:en:Template:script)
function p.countCharacters(text,characters)
	if (characters == nil or characters == '') then return 0 end
	if (text == nil or text == '') then return 0 end

	local _, num = mw.ustring.gsub(text, "[" .. characters .. "]", "")
	
	return num
end

-- Find the best script to use, based on the characters of a string.
-- (copied/adapted from wkt:en:Template:script)
function p.findBestScript(text, lang)
	if not text then
		return "None"
	end
	if not lang then
		lang = "und" -- undetermined
	end

	local l = require("Module:Lingaedje")
	local scripts = l.get_scripts(lang)
	
	if not scripts then return "None" end

	-- if there is only a single script for the language, no need to test
	if not scripts[2] then
		return scripts[1]
	end
	
	--[=[
		Remove any HTML entities; catfix function in [[Module:utilities]]
		adds tagging to a no-break space ( ), which contains Latin characters;
		hence Latin was returned as the script if "Latn" is one of the language's scripts.
	]=]
	text = string.gsub(text, "&[a-zA-Z0-9]+;", "")
	
	-- Try to match every script against the text,
	-- and return the one with the most matching characters.
	local bestcount = 0
	local bestscript = "" --nil
	
	-- Get length of text minus any spacing or punctuation characters.
	-- Counting instances of UTF-8 character pattern is faster than mw.ustring.len.
	local _, length = string.gsub(mw.ustring.gsub(text, "[%s%p]+", ""), "[\1-\127\194-\244][\128-\191]*", "")
	
	if length == 0 then
		return "None"
	end

	for _, i in ipairs(scripts) do
		local script = p.get_table(i)

		if (script and script.characters ~= nil)
		then
			local count = p.countCharacters(text, script.characters)

			if count >= length then
				return i
			end

			if count > bestcount then
				bestcount = count
				bestscript = i
			end
		end
	end
	
	if bestscript then
		return bestscript
	end
	
	-- No matching script was found. Return "None".
	return "None"
end

-- Get script from text template
function p.get_script_template(frame)
    local args
    if frame.args ~= nil and frame.args[1] ~= nil then
        args = frame.args
    else
        args = frame:getParent().args
    end
    local text = args[1]
    local lang = args[2]

    return "« " .. text .. " », sicrît e : " ..  p.findBestScript(text, lang)
end


return p