Modul:lang
Dokumentation for dette modul kan oprettes på Modul:lang/dok
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.getLanguage(frame)
local new_args = export._getParameters(frame.args, { 'code_or_name' });
local code_or_name = new_args['code_or_name'] or '';
local lowercase_code_or_name = mw.ustring.lower(code_or_name)
local lang_obj = lang_objects[lowercase_code_or_name] or {name = "ukendt sprog"}
local name = lang_obj.name
return name
end
-- hvis feltet "upper" er defineret i lang/data, bruges det præferentielt.
function export.getLanguageUCFirst(frame)
local new_args = export._getParameters(frame.args, { 'code_or_name' });
local code_or_name = new_args['code_or_name'] or '';
local lowercase_code_or_name = mw.ustring.lower(code_or_name)
local lang_obj = lang_objects[lowercase_code_or_name] or {name = "ukendt sprog"}
local name = lang_obj.name
return lang_obj.upper or mw.ustring.gsub(name, "^%l", mw.ustring.upper)
end
function export.hasLanguage(frame)
local new_args = export._getParameters(frame.args, { 'code_or_name' });
local code_or_name = new_args['code_or_name'] or '';
local lowercase_code_or_name = mw.ustring.lower(code_or_name)
local lang_obj = lang_objects[lowercase_code_or_name] or {code = "xx"}
local has_language = (lang_obj.code ~= "xx")
return has_language
end
function export._getParameters(frame_args, arg_list)
local new_args = {};
local index = 1;
local value;
for _, arg in ipairs(arg_list) do
value = frame_args[arg]
if value == nil then
value = frame_args[index];
index = index + 1;
end
new_args[arg] = value;
end
return new_args;
end
return export