Module:languages: Difference between revisions

From Laenkea
Jump to navigation Jump to search
No edit summary
No edit summary
Line 2: Line 2:
local languages = {
local languages = {
-- Proto-Laenkean
-- Proto-Laenkean
lae_pro = {name = "Proto-Laenkean", code = "lae-pro"},
["lae-pro"] = {name = "Proto-Laenkean", code = "lae-pro"},
-- Balavic
-- Balavic
bal = {name = "Balavic", code = "bal"},
["bal"] = {name = "Balavic", code = "bal"},
-- Kilitic
-- Kilitic
kil = {name = "Kilitic", code = "kil"},
["kil"] = {name = "Kilitic", code = "kil"},
-- Laefevian
-- Laefevian
lfv_pro = {name = "Proto-Laefevic", code = "lfv-pro"},
["lfv-pro"] = {name = "Proto-Laefevic", code = "lfv-pro"},
lfv = {name = "Lafevian", code = "lfv"},
["lfv"] = {name = "Lafevian", code = "lfv"},
-- Radestrian
-- Radestrian
rad_pro = {name = "Proto-Radic", code = "rad-pro"},
["rad-pro"] = {name = "Proto-Radic", code = "rad-pro"},
rad = {name = "Radestrian", code = "rad"},
["rad"] = {name = "Radestrian", code = "rad"},
-- Riyan
-- Riyan
ryn_o = {name = "Old Riyan", code = "ryn-o"},
["ryn-o"] = {name = "Old Riyan", code = "ryn-o"},
ryn_m = {name = "Middle Riyan", code = "ryn-m"},
["ryn-m"] = {name = "Middle Riyan", code = "ryn-m"},
ryn = {name = "Riyan", code = "ryn"}
["ryn"] = {name = "Riyan", code = "ryn"}
}
}


function export.getByCode(frame)
function export.get_by_code(code)
if type(code) ~= "string" then
error("Language code must be a string")
end
local l = languages[code]
if l == nil then
error("No such language code")
end
return l
end
 
function export.get_field_by_code(code, field)
if type(field) ~= "string" then
error("Desired field must be a string")
end
local l = export.get_by_code(code)
return l[field]
end
 
function export.GetByCode(frame)
local code = frame.args[1]
local code = frame.args[1]
local want = frame.args[2]
local field = frame.args[2]
return languages[code][want]
if type(field) == "string" then
return export.get_field_by_code(code, field)
end
return export.get_by_code(code)
end
end


return export
return export

Revision as of 11:29, 5 August 2023

local export = {}
local languages = {
	-- Proto-Laenkean
	["lae-pro"] = {name = "Proto-Laenkean", code = "lae-pro"},
	-- Balavic
	["bal"] = {name = "Balavic", code = "bal"},
	-- Kilitic
	["kil"] = {name = "Kilitic", code = "kil"},
	-- Laefevian
	["lfv-pro"] = {name = "Proto-Laefevic", code = "lfv-pro"},
	["lfv"] = {name = "Lafevian", code = "lfv"},
	-- Radestrian
	["rad-pro"] = {name = "Proto-Radic", code = "rad-pro"},
	["rad"] = {name = "Radestrian", code = "rad"},
	-- Riyan
	["ryn-o"] = {name = "Old Riyan", code = "ryn-o"},
	["ryn-m"] = {name = "Middle Riyan", code = "ryn-m"},
	["ryn"] = {name = "Riyan", code = "ryn"}
}

function export.get_by_code(code)
	if type(code) ~= "string" then
		error("Language code must be a string")
	end
	local l = languages[code]
	if l == nil then
		error("No such language code")
	end
	return l
end

function export.get_field_by_code(code, field)
	if type(field) ~= "string" then
		error("Desired field must be a string")
	end
	local l = export.get_by_code(code)
	return l[field]
end

function export.GetByCode(frame)
	local code = frame.args[1]
	local field = frame.args[2]
	if type(field) == "string" then
		return export.get_field_by_code(code, field)
	end
	return export.get_by_code(code)
end

return export