Modulo:Lingvonomo

El Vikipedio, la libera enciklopedio
Saltu al: navigado, serĉo
Dokumentado Dokumentado


Ŝablona programado Diskutoj Lua Testoj Subpaĝoj
Modulo Esperanto English Deutsch Modulo: Dokumentado

Se vi havas demandon pri ĉi tiu Lua-modulo, tiam vi povas demandi en la diskutejo pri Lua-moduloj. La Intervikiaj ligiloj estu metataj al Vikidatumoj. (Vidu Helpopaĝon pri tio.)
-- modul lingvonomo -- 2016-07-16
-- main functions:
-- language -- creates a link to a language article and an adverb like text
-- flag -- creates a flag and a link to a language article and an adverb like text
-- lang - creates a link to a language article and an adverb like text followed by a parsed {{Lang}} template.
-- exist -- returs true, if a code is a language code, else false
-- list -- returns a table with the ordered language codes and their rilated names in esperanto
--		   (partly translated only :-()

-- the functions "language" and "flag" have one needed parameter only
-- all functons have the optional parameters:
-- "koloro" (color), that defines the color of the text
-- "fono" (background), that defines the background color of the text
-- "grando" (size), that defines the size of the text
-- "pezo" (weight), that defines the font-weight

-- error handling:
-- factory
-- message
-- analyze
-- message2
-- analyze2

-- helping function:
-- getLanguages
-- getAccusative
-- getFlags
-- template
-- image
-- testweight

local messagePrefix = "lua-module-Lingvonomo-"
local l10nDef = {}
l10nDef[ "en" ] = {
	noLanguage	= "Error in language - in the function",
	emptyLanguage = "Language is empty - in the function",
	noText		= "Error in the text - in the function",
	emptyText	 = "Text is empty - in the function",
	noFlag		= "The page [[Modulo:Lingvonomo/listo/flagoj]] doesnt have a suitable flag."
}
l10nDef[ "de" ] = {
	noLanguage	= "Fehler bei Sprache - in der Funktion",
	emptyLanguage = "Sprache ist leer - in der Funktion",
	noText		= "Fehler im Text - in der Funktion",
	emptyText	 = "Text ist leer - in der Funktion",
	noFlag		= "Auf der Seite [[Modulo:Lingvonomo/listo/flagoj]] gibt es keine geeignete Fahne."
}
l10nDef[ "eo" ] = {
	noLanguage	= "Eraro en la lingvo - en la funkcio",
	emptyLanguage = "Lingvo estas malplena - en la funkcio",
	noText		= "Eraro en la teksto - en la funkcio",
	emptyText	 = "Teksto estas malplena - en la funkcio",
	noFlag		= "La paĝo [[Modulo:Lingvonomo/listo/flagoj]] ne enhavas taŭgan flagon."
}

-- error handling
local function factory( say )
	-- Retrieve localized message string in content language
	-- Precondition:
	--	 say  -- string; message ID
	-- Postcondition:
	--	 Return some message string
	-- Uses:
	--	 >  messagePrefix
	--	 >  l10nDef
	--	 mw.language.getContentLanguage()
	--	 mw.message.new()
	local c = mw.language.getContentLanguage():getCode()
	local m = mw.message.new( messagePrefix .. say )
	local r = false
	if m:isBlank() then
		local l10n = l10nDef[ c ]
		if not l10n then
			l10n = l10nDef[ "en" ]
		end
		r = l10n[ say ]
	else
		m:inLanguage( c )
		r = m:plain()
	end
	if not r then
		r = "(((".. say .. ")))"
	end
	return r
end -- factory()

-- for one needed parameter only
local function message (first, f)
	-- first - the first required parameter in the main function is wrong
	-- f - in which function it occurs
	 local r = ""
	 if (first ~="") then
		 r = factory (first) .. ": " .. f .. "()"
	 end

	-- error (r, 0)
	 r = "<span class='error'>" .. r .. "</span>"
	 return r
end -- message ()

local function analyze (first, f)
	-- first - the first required parameter has to be analyzed
	-- f - in which function it occurs
	-- r - message text
		local r =""
		if (first ==nil) or (first =="") then
		   local param1 =""
		   local r =""
		   if (first == nil) then
			  param1= "noLanguage"
		   end
		   if (first=="") then
			  param1= "emptyLanguage"
		   end

		   r=message (param1, f)
		   return r
		end

	return r
end  -- analyze ()

-- for two needed parameters
local function message2 (first, second, f)
	-- first - the first required parameter in the main function is wrong
	-- second - the second required parameter in the main function is wrong
	-- f - in which function it occurs
	 local r = ""
	 if (first ~="") then
		 r = factory (first) .. ": " .. f .. "()"
	 end
	 if (second ~="") then
		 if (r ~="") then
		 r = r .. "<br />" .. factory (second) .. ": " .. f .. "()"
		 else r = factory (second) .. ": " .. f .. "()"
		 end
	 end
	-- error (r, 0)
	 r = "<span class='error'>" .. r .. "</span>"
	 return r
end -- message2 ()

local function analyze2 (first, second, f)
	-- first - the first required parameter has to be analyzed
	-- second - the second required parameter has to be analyzed
	-- f - in which function it occurs
	-- r - message text
		local r =""
		if (first ==nil) or (first =="") or (second ==nil) or (second=="") then
		   local param1 =""
		   local param2 =""
		   local r =""
		   if (first == nil) then
			  param1= "noLanguage"
		   end
		   if (first=="") then
			  param1= "emptyLanguage"
		   end
		   if (second == nil)  then
			  param2 ="noText"
		   end
		   if (second=="") then
			  param2 ="emptyText"
		   end
		   r=message2 (param1, param2, f)
		   return r
		end
--		local lenfirst=mw.ustring.len(first)
  --	  local lensecond=mw.ustring.len(second)
		-- if the first (language) is longer than the second (text), then it returns a text, which
		-- in the main function exchanges the values of the variables
--		if (lenfirst>lensecond) then
--			r="change"
--			return r
--		end
	return r
end  -- analyze2 ()

-- gets the adverb and name according to a language code using mw.language.fetchLanguageName
local function getLanguages(s)
	-- Gets an adverb and name using the Lua function mw.language.fetchLanguageName.
	local r1, r2
	if s == "ady" then
		r1, r2 = "adigee", "adigea lingvo"
	elseif s == "arc" then
		r1, r2 = "aramee", "aramea lingvo"
	elseif s == "ast" then
		r1, r2 = "asturie", "asturia lingvo"
	elseif s == "bal" then
		r1, r2 = "baluĉe", "baluĉa lingvo"
	elseif s == "bar" then
		r1, r2 = "bavare", "bavara lingvo"
	elseif s == "bs" then
		r1, r2 = "bosne", "bosna lingvo"
	elseif s == "my" then
		r1,r2 = "birme", "birma lingvo"
	elseif s == "ceb" then
		r1, r2 = "cebue", "cebuo"
	elseif s == "ch" then
		r1, r2 = "ĉamore", "ĉamora lingvo"
	elseif s == "chg" then
		r1, r2 = "ĉagataje", "ĉagataja lingvo"
	elseif s == "ckt" then
		r1, r2 = "ĉukĉe", "ĉukĉa lingvo"
	elseif s == "crh" then
		r1, r2 = "krime-tatare", "krime-tatara lingvo"
	elseif s == "csb" then
		r1, r2 = "kaŝube", "kaŝuba lingvo"
	elseif s == "cv" then
		r1, r2 = "ĉuvaŝe", "ĉuvaŝa lingvo"
	elseif s == "dz" then
		r1, r2 = "dzonke", "dzonka lingvo"
	elseif s == "egy" then
		r1, r2 = "egipte", "egipta lingvo"
	elseif s == "ell" then
		r1, r2 = "novgreke", "novgreka lingvo"
	elseif s == "eo" then
		r1, r2 = "esperante", "esperanto"
	elseif s == "ett" then
		r1, r2 = "etruske", "etruska lingvo"
	elseif s == "frr" then
		r1, r2 = "nordfrise", "nordfrisa lingvo"
	elseif s == "fy" then
		r1, r2 = "okcidentfrise", "okcidentfrisa lingvo"
	elseif s == "gd" then
		r1, r2 = "skotgaele", "skotgaela lingvo"
	elseif s == "gil" then
		r1, r2 = "kiribate", "kiribata lingvo"
	elseif s == "grc" then
		r1, r2 = "antikve-greke", "antikva greka lingvo"
	elseif s == "gv" then
		r1, r2 = "mankse", "manksa lingvo"
	elseif s == "hi" then
		r1, r2 = "hindie", "hindia lingvo"
	elseif s == "hsb" then
		r1, r2 = "suprasorabe", "suprasoraba lingvo"
	elseif s == "inh" then
		r1, r2 = "inguŝe", "inguŝa lingvo"
	elseif s == "io" then
		r1, r2 = "ide", "ido"
	elseif s == "jbo" then
		r1, r2 = "loĵbane", "loĵbano"
	elseif s == "kg" then
		r1, r2 = "konge", "konga lingvo"
	elseif s == "kjh" then
		r1, r2 = "ĥakase", "ĥakasa lingvo"
	elseif s == "kw" then
		r1, r2 = "kornvale", "kornvala lingvo"
	elseif s == "la" then
		r1, r2 = "latine", "latino"
	elseif s == "lld" then
		r1, r2 = "ladine", "ladina lingvo"
	elseif s == "lua" then
		r1, r2 = "lube", "luba lingvo"
	elseif s == "mnc" then
		r1, r2 = "manĉure", "manĉura lingvo"
	elseif s == "mni" then
		r1, r2 = "manipure", "manipura lingvo"
	elseif s == "nb" then
		r1, r2 = "bukmole", "bukmola lingvo"
	elseif s == "non" then
		r1, r2 = "norene", "norena lingvo"
	elseif s == "nr" then
		r1, r2 = "sud-ndebele", "sud-ndebela lingvo"
	elseif s == "nso" then
		r1, r2 = "pede", "peda lingvo"
	elseif s == "os" then
		r1, r2 = "osete", "oseta lingvo"
	elseif s == "pap" then
		r1, r2 = "papiamente", "papiamento"
	elseif s == "pi" then
		r1, r2 = "palie", "palia lingvo"
	elseif s == "pms" then
		r1, r2 = "piemonte", "piemonta lingvo"
	elseif s == "ps" then
		r1, r2 = "paŝtune", "paŝtuna lingvo"
	elseif s == "rup" then
		r1, r2 = "arumane", "arumana lingvo"
	elseif s == "sa" or s == "san" then
		r1, r2 = "sanskrite", "sanskrito"
	elseif s == "sah" then
		r1, r2 = "jakute", "jakuta lingvo"
	elseif s == "sco" then
		r1, r2 = "skote", "skota lingvo"
	elseif s == "slo" then
		r1, r2 = "slovianske", "slovianska lingvo"
	elseif s == "stq" then
		r1, r2 = "saterfrise", "saterfrisa lingvo"
	elseif s == "sw" then
		r1, r2 = "svahile", "svahila lingvo"
	elseif s == "szl" then
		r1, r2 = "silezia-pole", "silezia-pola lingvo"
	elseif s == "tlh" then
		r1, r2 = "klingone", "klingona lingvo"
	elseif s == "tpi" then
		r1, r2 = "tokpisine", "tokpisino"
	elseif s == "tyv" then
		r1, r2 = "tuve", "tuva lingvo"
	elseif s == "tzl" then
		r1, r2 = "talose", "talosa lingvo"
	elseif s == "udm" then
		r1, r2 = "udmurte", "udmurta lingvo"
	elseif s == "ur" then
		r1, r2 = "urdue", "urduo"
	elseif s == "vo" then
		r1, r2 = "volapuke", "volapuko"
	elseif s == "wa" then
		r1, r2 = "valone", "valona lingvo"
	elseif s == "xal" then
		r1, r2 = "kalmuke", "kalmuka lingvo"
	elseif s == "xh" then
		r1, r2 = "kose", "kosa lingvo"
	elseif s == "xvn" then
		r1, r2 = "vandale", "vandala lingvo"
	else
		r1 = mw.language.fetchLanguageName( s, "eo" )
		if r1 then
			r1 = r1:gsub( "a$", "e")
			r2 = r1:gsub( "e$", "a lingvo" )
		end
	end
	return r1, r2
end

-- gets the accusative and name according to a language code using mw.language.fetchLanguageName
local function getAccusative(s)
	-- Gets an accusative and name using the Lua function mw.language.fetchLanguageName.
	local r1, r2
	if s == "ady" then
		r1, r2 = "adigean lingvon", "adigea lingvo"
	elseif s == "arc" then
		r1, r2 = "aramean lingvon", "aramea lingvo"
	elseif s == "ast" then
		r1, r2 = "asturian lingvon", "asturia lingvo"
	elseif s == "bal" then
		r1, r2 = "baluĉan lingvon", "baluĉa lingvo"
	elseif s == "bar" then
		r1, r2 = "bavaran lingvon", "bavara lingvo"
	elseif s == "bs" then
		r1, r2 = "bosnan lingvon", "bosna lingvo"
	elseif s == "my" then
		r1, r2 = "birman lingvon", "birma lingvo"
	elseif s == "ceb" then
		r1, r2 = "Cebuon", "cebua lingvo"
	elseif s == "ch" then
		r1, r2 = "ĉamoran lingvon", "ĉamora lingvo"
	elseif s == "chg" then
		r1, r2 = "ĉagatajan lingvon", "ĉagataja lingvo"
	elseif s == "ckt" then
		r1, r2 = "ĉukĉan lingvon", "ĉukĉa lingvo"
	elseif s == "crh" then
		r1, r2 = "krime-tataran lingvon", "krime-tatara lingvo"
	elseif s == "csb" then
		r1, r2 = "kaŝuban lingvon", "kaŝuba lingvo"
	elseif s == "cv" then
		r1, r2 = "ĉuvaŝan lingvon", "ĉuvaŝa lingvo"
	elseif s == "dz" then
		r1, r2 = "dzonkan lingvon", "dzonka lingvo"
	elseif s == "egy" then
		r1, r2 = "egiptan lingvon", "egipta lingvo"
	elseif s == "ell" then
		r1, r2 = "novgrekan lingvon", "novgreka lingvo"
	elseif s == "eo" then
		r1, r2 = "Esperanton", "esperanto"
	elseif s == "ett" then
		r1, r2 = "etruskan lingvon", "etruska lingvo"
	elseif s == "frr" then
		r1, r2 = "nordfrisan lingvon", "nordfrisa lingvo"
	elseif s == "fy" then
		r1, r2 = "okcidentfrisan lingvon", "okcidentfrisa lingvo"
	elseif s == "gd" then
		r1, r2 = "skotgaelan lingvon", "skotgaela lingvo"
	elseif s == "gil" then
		r1, r2 = "kiribatan lingvon", "kiribata lingvo"
	elseif s == "grc" then
		r1, r2 = "antikvan grekan lingvon", "antikva greka lingvo"
	elseif s == "gv" then
		r1, r2 = "manksan lingvon", "manksa lingvo"
	elseif s == "hi" then
		r1, r2 = "hindian lingvon", "hindia lingvo"
	elseif s == "hsb" then
		r1, r2 = "suprasoraban lingvon", "suprasoraba lingvo"
	elseif s == "inh" then
		r1, r2 = "inguŝan lingvon", "inguŝa lingvo"
	elseif s == "io" then
		r1, r2 = "Idon", "ido"
	elseif s == "jbo" then
		r1, r2 = "Loĵbanon", "loĵbano"
	elseif s == "kg" then
		r1, r2 = "kongan lingvon", "konga lingvo"
	elseif s == "kjh" then
		r1, r2 = "ĥakasan lingvon", "ĥakasa lingvo"
	elseif s == "kw" then
		r1, r2 = "kornvalan lingvon", "kornvala lingvo"
	elseif s == "la" then
		r1, r2 = "Latinon", "latino"
	elseif s == "lld" then
		r1, r2 = "ladinan lingvon", "ladina lingvo"
	elseif s == "lua" then
		r1, r2 = "luban lingvon", "luba lingvo"
	elseif s == "mnc" then
		r1, r2 = "manĉuran lingvon", "manĉura lingvo"
	elseif s == "mni" then
		r1, r2 = "manipuran lingvon", "manipura lingvo"
	elseif s == "nb" then
		r1, r2 = "bukmolan lingvon", "bukmola lingvo"
	elseif s == "non" then
		r1, r2 = "norenan lingvon", "norena lingvo"
	elseif s == "nr" then
		r1, r2 = "sud-ndebelan lingvon", "sud-ndebela lingvo"
	elseif s == "nso" then
		r1, r2 = "pedan lingvon", "peda lingvo"
	elseif s == "os" then
		r1, r2 = "osetan lingvon", "oseta lingvo"
	elseif s == "pap" then
		r1, r2 = "papiamenton", "papiamento"
	elseif s == "pi" then
		r1, r2 = "Palion", "palio"
	elseif s == "pms" then
		r1, r2 = "piemontan lingvon", "piemonta lingvo"
		elseif s == "ps" then
		r1, r2 = "paŝtunan lingvon", "paŝtuna lingvo"
	elseif s == "rup" then
		r1, r2 = "arumanan lingvon", "arumana lingvo"
	elseif s == "sa" or s == "san" then
		r1, r2 = "Sanskriton", "sanskrito"
	elseif s == "sah" then
		r1, r2 = "jakutan lingvon", "jakuta lingvo"
	elseif s == "sco" then
		r1, r2 = "skotan lingvon", "skota lingvo"
	elseif s == "slo" then
		r1, r2 = "slovianskan lingvon", "slovianska lingvo"
	elseif s == "stq" then
		r1, r2 = "saterfrisan lingvon", "saterfrisa lingvo"
	elseif s == "sw" then
		r1, r2 = "svahilan lingvon", "svahila lingvo"
	elseif s == "szl" then
		r1, r2 = "silezia-polan lingvon", "silezia-pola lingvo"
	elseif s == "tlh" then
		r1, r2 = "klingonan lingvon", "klingona lingvo"
	elseif s == "tpi" then
		r1, r2 = "tokpisinon", "tokpisino"
	elseif s == "tyv" then
		r1, r2 = "tuvan lingvon", "tuva lingvo"
	elseif s == "tzl" then
		r1, r2 = "talosan lingvon", "talosa lingvo"
	elseif s == "udm" then
		r1, r2 = "udmurtan lingvon", "udmurta lingvo"
	elseif s == "ur" then
		r1, r2 = "Urduon", "urduo"
	elseif s == "vo" then
		r1, r2 = "Volapukon", "volapuko"
	elseif s == "wa" then
		r1, r2 = "valonan lingvon", "valona lingvo"
	elseif s == "xal" then
		r1, r2 = "kalmukan lingvon", "kalmuka lingvo"
	elseif s == "xh" then
		r1, r2 = "kosan lingvon", "kosa lingvo"
	elseif s == "xvn" then
		r1, r2 = "vandalan lingvon", "vandala lingvo"
	else
		local r = mw.language.fetchLanguageName( s, "eo" )
		if r then
			r1 = r:gsub( "a$", "an lingvon")
			r2 = r:gsub( "a$", "a lingvo" )
		end
	end
	return r1, r2
end

-- gets the flag according to a language code from [[Modulo:Lingvonomo/listo/flagoj]]
local function getFlags(s)
	-- Gets an flag from the flag data page.
	local languageData = mw.loadData('Modulo:Lingvonomo/listo/flagoj')
	for language, aliases in pairs(languageData) do
		if (s==language) then
			local adverb = aliases[1]
			-- local name = aliases[2]
			return adverb, name
		end
	end
end

-- template - parses the {{Lang}} template with two parameters:
-- l - language code and t - text
local function template (l, t)
	local frame = mw.getCurrentFrame()
	local r = frame:expandTemplate{
		   title = 'Lang',
		   args = {
	   			l,
	   			t
	   			}
		   }
	return r
end

-- image tests, if a text could be the name of an image
local function image (t)
	local text = mw.ustring.lower(t)  -- it changes letters into lower case letters
	local ending = mw.ustring.sub(text,-4,-1)
	if (ending ==".gif") or (ending == ".jpg") or (ending == ".png") or (ending == ".svg") then
		local error = false
		return t, error
	else
		local ending = mw.ustring.sub(text,-5,-1)
		if (ending==".jpeg") then
			local error = false
			return t, error
		else
			local r = message("noFlag","flag")
			local error = true
			return r, error
		end
	end
	local r = message("noFlag","flag")
	local error = true
	return r, error
end

-- testweight analyzes if the given value in w is a valid value of the CSS feature font-weight
local function testweight (w)
	local text = mw.ustring.lower(w) .. ""
	if (text=="normal") or (text=="bold") or (text=="bolder") or (text=="lighter")
	or (text=="100") or (text=="200") or (text=="300") or (text=="400") or (text=="500")
	or (text=="600") or (text=="700") or (text=="800") or (text=="900") then
		return w
	else
		return "normal"
	end
end

-- Export
--local p = {}
-- main functions:
-- language - creates a link to a language article and an adverb like text
-- has only one needed parameter, the code of the language
-- it is used for the templates {{Ar}} until {{Zh}}
function _language (args)

	code = args[1]
	-- it analyzes, if the required parameter is wrong or not
	r=analyze (code, "language")
	if (r~="") then return r -- if r is some other than an empty string, it returns the message
	-- and finishes the function
	end
	-- optional parameters
	color = args['koloro'] or args['color']
	background = args['fono'] or args['background']
	size = args['grando'] or args['size']
	weight = args['pezo'] or args['weight']
	accusative = args['akuzativo'] or args['accusative'] -- it is in this function only
	if (color ==nil) or (color == "") then
		c = "color:grey;"
	elseif (color == "defaŭlta") or (color == "normala" ) then
		c = ""
	else
		c = "color:" .. color .. ";"
	end
	if (background~=nil) and (background~="") then
		b = "background-color:" .. background .. ";"
	else
		b = ""
	end
	if (size~=nil) and (size~="") then
		s = "font-size:" .. size .. ";"
	else
		s = ""
	end
	if (weight~=nil) and (weight~="") then
		w = "font-weight:" .. testweight(weight) .. ";"
	else
		w = ""
	end

	code = mw.ustring.lower(code)

	-- if accusative has one of the following values, get the accusative. else the adverb
	if (accusative == "jes") or (accusative=="yes") then
		text, name = getAccusative(code)
	else
		text, name = getLanguages(code)
	end

	if (text ~= "") and (name ~="") then
--	if (adverb~=nil) and (name ~=nil) then
		local linktext = text
		if (c~="") or (b~="") or (s~="") or (w~="") then
			r = "[[" .. name .. '|<span style="' .. c .. b .. s .. w .. '">' .. linktext .. "</span>]]"
		else
			r = "[[" .. name .. '|' .. linktext .. "]]"
		end
	else r = "<span class='error'>La lingva kodo '".. code .. "' ne estas subtenata de la Lua-funkcio 'mw.language.fetchLanguageName'. - en la funkcio: language()</span>"
	end
	return r
end

-- flag - puts an image and creates a link to a language article and an adverb like text
-- has only one needed parameter, the code of the language
-- it is used for the templates {{Flag-ar}} until {{Flag-zh}}
function _flag (args)

	code = args[1]
	-- it analyzes, if the required parameter is wrong or not
	r=analyze (code, "flag")
	if (r~="") then return r -- if r is some other than an empty string, it returns the message
	-- and finishes the function
	end
	-- optional parameter
	color = args['koloro'] or args['color']
	background = args['fono'] or args['background']
	size = args['grando'] or args['size']
	weight = args['pezo'] or args['weight']
	if (color ~=nil) and (color ~= "") then
		c = "color:" .. color .. ";"
	else
		c = ""
	end
	if (background~=nil) and (background~="") then
		b = "background-color:" .. background .. ";"
	else
		b = ""
	end
	if (size~=nil) and (size~="") then
		s = "font-size:" .. size .. ";"
	else
		s = ""
	end
	if (weight~=nil) and (weight~="") then
		w = "font-weight:" .. testweight(weight) .. ";"
	else
		w = ""
	end

	code = mw.ustring.lower(code)

	local adverb, name = getLanguages(code)
	local flag = getFlags(code)

	if (adverb ~= "") and (name ~="") then
--	if (adverb~=nil) and (name ~=nil) then
		if (flag~=nil) then
			local i, error = image(flag) -- test if the text from the page [[Modulo:Lingvonomo/listo/flagoj]] is an image or not
			if (error == false) then
				r = "[[Dosiero:" .. flag .. "|20px|border]]&nbsp;"
			elseif (error == true) then
				r = i
			end
		else
			r = message("noFlag","flag") -- '<span class="error">La paĝo [[Modulo:Lingvonomo/listo/flagoj]] ne enhavas taŭgan flagon.</span>'
		end
		local linktext = adverb
		local l = name:gsub( " lingvo", "" )
		r = r .. '<span style="cursor:help;font-family:monospace;font-weight:bold;font-size:small" title="Lingvo: ' .. l .. '">'
		if (c~="") or (b~="") or (s~="") or (w~="") then
			r = r .. "[[" .. name .. '|<span style="' .. c .. b .. s .. w .. '">' .. linktext .. "</span>]]"
		else
			r = r .. "[[" .. name .. '|' .. linktext .. "]]"
		end
		r = r .. "</span>"
	else r = "<span class='error'>La lingva kodo '".. code .. "' ne estas subtenata de la Lua-funkcio 'mw.language.fetchLanguageName'. - en la funkcio: flag()</span>"
	end
	return r
end

-- lang - creates a link to a language article and an adverb like text
-- has two needed parameters, the code of the language and the text
function _lang (args)

	code = args[1]
	text = args[2]
	-- it analyzes, if the required parameters are wrong or not
	r=analyze2 (code, text, "lang")
	if (r~="") then return r -- if r is some other than an empty string, it returns the message
	-- and finishes the function
	end
	-- optional parameter
	color = args['koloro'] or args['color']
	background = args['fono'] or args['background']
	size = args['grando'] or args['size']
	weight = args['pezo'] or args['weight']
	italic = args['kursiva'] or args['italic'] or ""
	link = args['ligilo'] or args['link'] or ""
	if (color ~=nil) and (color ~= "") then
		c = "color:" .. color .. ";"
	else
		c = ""
	end
	if (background~=nil) and (background~="") then
		b = "background-color:" .. background .. ";"
	else
		b = ""
	end
	if (size~=nil) and (size~="") then
		s = "font-size:" .. size .. ";"
	else
		s = ""
	end
	if (weight~=nil) and (weight~="") and (s~="") then
		w = "font-weight:" .. testweight(weight) .. ";"
	elseif (weight==nil) or (weight=="") and (s~="") then
		w = "font-weight: normal;"
	else
		w = ""
	end
	-- html tags for the font-size, because this is used for both links
	if (s~="") or (w~="") then
		link1 = '<b style="'
		link2 = '">'
		link3 = "</b>"
	else
		link1 = ""
		link2 = ""
		link3 = ""
	end

	code = mw.ustring.lower(code)

	local adverb, name = getLanguages(code)

	if (adverb ~= "") and (name ~="") then
--	if (adverb~=nil) and (name ~=nil) then
		local linktext = adverb
		local i = ""
		if italic == "yes" or italic == "jes" or italic == "" then
			i = "''"
		end
		-- esceptaj lingvokodoj, kie kursiveco ne taŭgas
		if code == "am" or code == "ar" or code == "arc" or code == "bal" or code == "bn" or code == "bo" or code == "dz" or code == "fa" or code == "gu" or code == "he" or
		code == "hi" or code == "ja" or code == "km" or code == "kn" or code == "ko" or  code == "ml" or code == "mni" or code == "mr" or code == "my" or code == "ne" or
		code == "pa" or code == "pi" or code == "ps" or code == "sa" or code == "san" or code == "sd" or code == "si" or code == "ta" or code == "te" or code == "th" or
		code == "ur" or code == "zh" then
			i = ""
		end
		l = template (code, text) -- invoke the {{Lang}} template
		if text ~= "&nbsp;" then

			if (c~="") or (b~="") or (s~="") then
				if link ~= "no" and link ~= "ne" then
					r = link1 .. s .. w .. link2 .. "[[" .. name .. '|' .. linktext .. ']]&nbsp;<span style="' .. c .. b .. '">' .. i .. l .. i .. "</span>" .. link3
				else
					r = link1 .. s .. w .. link2 .. linktext .. '&nbsp;<span style="' .. c .. b .. '">' .. i .. l .. i .. "</span>" .. link3
				end
			else
				if link ~= "no" and link ~="ne" then
					r = "[[" .. name .. '|' .. linktext .. "]]&nbsp;" .. i .. l .. i
				else
					r = linktext .. "&nbsp;" .. i .. l .. i
				end
			end
		else
			if (c~="") or (b~="") or (s~="") then
				if link ~= "no" and link ~= "ne" then
					r = link1 .. s .. w .. link2 .. "[[" .. name .. '|' .. linktext .. ']]&nbsp;' .. link3
				else
					r = link1 .. s .. w .. link2 .. linktext .. '&nbsp;'   .. link3
				end
			else
				if link ~= "no" and link ~="ne" then
					r = "[[" .. name .. '|' .. linktext .. "]]&nbsp;"
				else
					r = linktext .. "&nbsp;"
				end
			end
		end
		-- translitaracioj por kelkaj lingvoj. aldonoj eblas.
		if code == "zh" then
			local pinjin = args['p'] or args['pinjino']
			if pinjin ~= "" and pinjin ~= nil then
				r = r .. "; [[pinjino|pinjine]]: " .. pinjin
			end
			local t = args['t']
			if t ~= "" and t ~= nil then
				r = r .. "; " .. t
			end
		elseif code == "ja" then
			local h = args['h'] or args['t']
			if h ~= "" and h ~= nil then
				if text == "&nbsp;" then
					r = r .. h
				else
					r = r .. "; " .. h
				end
			end
		elseif code == "ko" then
			local r2 = args['r'] or args['t']
			if r2 ~= "" and r2 ~= nil then
				if text == "&nbsp;" then
					r = r .. r2
				else
					r = r .. "; " .. r2
				end
			end
		elseif code == "am" or code == "ar" or code == "arc" or code == "bal" or code == "bn" or code == "bo" or code == "dz" or code == "fa" or code == "gu" or code == "he" or
		code == "hi" or code == "km" or code == "kn" or code == "ml" or code == "mni" or code == "mr" or code == "my" or code == "ne" or
		code == "pa" or code == "ps" or code == "sa" or code == "san" or code == "sd" or code == "si" or code == "ta" or code == "te" or code == "th" or
		code == "ur" then
			local t = args['t']
			if t ~= "" and t ~= nil then
				if text == "&nbsp;" then
					r = r .. t
				else
					r = r .. "; " .. t
				end
			end
		end
	else r = "<span class='error'>La lingva kodo '".. code .. "' ne estas subtenata de la Lua-funkcio 'mw.language.fetchLanguageName'. - en la funkcio: lang()</span>"
	end
	return r
end

-- exist analyzes if a code is a language code in mw.language.fetchLanguageName
function _exist (args)

	code = args[1]
	-- it analyzes, if the required parameter is wrong or not
	r=analyze (code, "exist")
	if (r~="") then return r -- if r is some other than an empty string, it returns the message
	-- and finishes the function
	end

	local text, name = getLanguages(code)
	if (text~="") and (name~="") then
		return true
	else
		return false
	end

end

-- list returns all langugage from the function mw.language.fetchLanguageNames in a wikitable
function _list (args)
	local r = '{| class="wikitable sortable"\n'
	r = r .. "|-\n" .. "! Kodo !! Nomo\n" -- head of the table
	local languages = mw.language.fetchLanguageNames("eo","all")
	local a = {}
	local number = 0
	for n in pairs(languages) do
		a[#a + 1] = n
	end
	number = #a
	table.sort(a)
	r = r .. "|-\n" .. '! colspan="2" |  nombro: ' .. number .. "\n"
	for index, code in pairs(a) do
		local name = ""
		for c, n in pairs(languages) do
			if (c == code) then
				name = n
				break
			end
		end
		r = r .. "|-\n" .. "| " .. code .. " || " .. name .. "\n"
	end
	r = r .. "|}\n"
	r = r .. "nombro: " .. number
	return r
end

local function makeWrapper(funcName)
	-- Processes external arguments and sends them to the alia functions.
	return function (frame)
		-- If called via #invoke, use the args passed into the invoking
		-- template, or the args passed to #invoke if any exist. Otherwise
		-- assume args are being passed directly in from the debug console
		-- or from another Lua modulo.
		local origArgs
		if frame == mw.getCurrentFrame() then
			origArgs = frame:getParent().args
			for k, v in pairs(frame.args) do
				origArgs = frame.args
				break
			end
		else
			origArgs = frame
		end
		-- Trim whitespace and remove blank arguments.
		local args = {}
		for k, v in pairs(origArgs) do
			if type(v) == 'string' then
				v = mw.text.trim(v)
			end
			if v ~= '' then
				args[k] = v
			end
		end
		-- the parameters have to work not only using #invoke, but also in templates
		local templateArgs = frame:getParent().args
		args.color = templateArgs.koloro or args.koloro or args.color
		args.background = templateArgs.fono or args.fono or args.background
		args.size = templateArgs.grando or args.grando or args.size
		args.weight = templateArgs.pezo or args.pezo or args.weight
		args.accusative = templateArgs.akuzativo or args.akuzativo or args.accusative
		args.italic = templateArgs.kursiva or args.kursiva or args.italic
		args.link = templateArgs.ligilo or args.ligilo or args.link
		args.p = templateArgs.p or templateArgs.pinjino or args.p or args.pinjin
		args.t = templateArgs.t or args.t
		--return p[funcName](processLanguageArgs(args)) -- passes two tables to func: an array of language names, and a table of named arguments.
		return funcName( args )
	end
end

return {
	language = makeWrapper( _language ),
	flag = makeWrapper( _flag ),
	lang = makeWrapper( _lang ),
	exist = makeWrapper( _exist ),
	list = makeWrapper( _list )
}