Module:languages: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 2: | Line 2: | ||
function export.get_by_code(code) | function export.get_by_code(code) | ||
local lang = export.find_by_code(code) | |||
if lang == nil then error("No such language (" .. code .. ")") end | |||
return lang | |||
end | |||
function export.find_by_code(code) | |||
if type(code) ~= "string" then | if type(code) ~= "string" then | ||
error("Language code must be string. Got " .. type(code)) | error("Language code must be string. Got " .. type(code)) | ||
end | end | ||
return mw.loadData("Module:languages/data")[code] | |||
end | end | ||
function export.get_by_canonical_name(name) | function export.get_by_canonical_name(name) | ||
local | local lang = export.find_by_canonical_name(name) | ||
if | if lang == nil then error("No such language (" .. name .. ")") end | ||
return lang | |||
end | |||
return export. | |||
function export.find_by_canonical_name(name) | |||
local code = mw.loadData("Module:languages/canonical names")[name] | |||
if code == nil then return nil end | |||
return export.find_by_code(code) | |||
end | end | ||
Revision as of 07:55, 6 August 2023
local export = {}
function export.get_by_code(code)
local lang = export.find_by_code(code)
if lang == nil then error("No such language (" .. code .. ")") end
return lang
end
function export.find_by_code(code)
if type(code) ~= "string" then
error("Language code must be string. Got " .. type(code))
end
return mw.loadData("Module:languages/data")[code]
end
function export.get_by_canonical_name(name)
local lang = export.find_by_canonical_name(name)
if lang == nil then error("No such language (" .. name .. ")") end
return lang
end
function export.find_by_canonical_name(name)
local code = mw.loadData("Module:languages/canonical names")[name]
if code == nil then return nil end
return export.find_by_code(code)
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