2,788
edits
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 | ||