Module:languages: Difference between revisions

ਕੋਈ ਸੋਧ ਸਾਰ ਨਹੀਂ
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
local l = mw.loadData("Module:languages/data")[code]
return mw.loadData("Module:languages/data")[code]
if l == nil then
error("No such language code")
end
return l
end
end


function export.get_by_canonical_name(name)
function export.get_by_canonical_name(name)
local c = mw.loadData("Module:languages/canonical names")[name]
local lang = export.find_by_canonical_name(name)
if c == nil then
if lang == nil then error("No such language (" .. name .. ")") end
error("No such language name")
return lang
end
end
return export.get_by_code(c)
 
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