Module:languages: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
local export = {} | local export = {} | ||
function export.get_by_code(code) | function export.get_by_code(code) | ||
Line 28: | Line 5: | ||
error("Language code must be string. Got " .. type(code)) | error("Language code must be string. Got " .. type(code)) | ||
end | end | ||
local l = | local l = require("Module:languages/data")[code] | ||
if l == nil then | if l == nil then | ||
error("No such language code") | error("No such language code") |
Revision as of 07:22, 6 August 2023
local export = {}
function export.get_by_code(code)
if type(code) ~= "string" then
error("Language code must be string. Got " .. type(code))
end
local l = require("Module:languages/data")[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