local export = {}
local lang_objects = mw.loadData("Modul:lang/data")

local function ucFirst(str)
	return mw.ustring.gsub(str, "^%l", mw.ustring.upper)
end

function export.hasLanguage(arg)
        return true
end

function export.getLanguage(code)
	local lang_obj = lang_objects[code] or {name = "ukjent språk"}
	local name = lang_obj.name
	return name
end

function export.getLanguageUCFirst(code)
	return ucFirst(export.getLanguage(code))
end

function export.getScriptCodes(code)
	local lang_obj = lang_objects[code.args[1]] or {script = {}}
	local scripts = lang_obj.scripts or {}
	return scripts
end

function export.getMainScriptCode(code)
	local main = export.getScriptCodes(code)[1] or ""
	if main=="Latn" then  main = "" end           --default value
	return main
end

function export.getEntryName(code, text)
	local lang_obj = lang_objects[code] or {code = "xx"}
	local entry_name_rules = lang_obj.entry_name or {from = {}, to = {}}
	
	for i, from in ipairs(entry_name_rules.from) do
		local to = entry_name_rules.to[i] or ""
		text = mw.ustring.gsub(text, from, to)
	end

	return text	
end

return export