Lua error at line 36: table index is nil
local m_families = mw.loadData('Module:families/data')
local m_languages = mw.loadData('Module:languages/data/all')
local m_etym_languages = require('Module:etymology languages/data')
local etym_othercodes = {}
local export = {}
local function build_tree()
local tree = {}
for code, data in pairs(m_families) do
if data.family then
if not tree then
tree = {}
end
if code ~= data.family then
table.insert(tree, code)
end
end
end
for code, data in pairs(m_languages) do
if data.family then
if not tree then
tree = {}
end
if code ~= data.family then
table.insert(tree, code)
end
end
end
for code, data in pairs(m_etym_languages) do
if not etym_othercodes then
etym_othercodes = { code }
if not tree then
tree = {}
end
if code ~= data.parent then
table.insert(tree, code)
end
else
table.insert(etym_othercodes, code)
end
end
for _, list in pairs(etym_othercodes) do
table.sort(list)
end
return tree
end
local type_map = {
= 0;
= 1;
= 2;
= 2;
= 3;
}
local function make_list(code, tree, with_parents, depth)
local result = {}
local stars = '*'
depth = depth or -1
local function format_family(code)
local catname = m_families.canonicalName
if not catname:find("anguages$") then
catname = catname .. ' languages'
end
return ("] (<code>%s</code>)"):format(catname, catname, code)
end
local function format_lang(code)
local data = m_languages
local catname = data
if not catname:find("anguage$") then
catname = catname .. ' language'
end
return ("%s]%s (<code>%s</code>)"):format(
(data.type == "reconstructed") and "*" or
((data.type == "appendix-constructed") and "''" or ""),
catname, data,
(data.type == "appendix-constructed") and "''" or "",
code
)
end
local function format_etym_lang(code)
local codes = {}
for _, code in ipairs(etym_othercodes]) do
table.insert(codes, ("<code>%s</code>"):format(code))
end
return ("<small>%s (%s)</small>"):format(
m_etym_languages.canonicalName,
table.concat(codes, ", ")
)
end
local function add_item(code)
if m_families then
table.insert(result, stars .. ' ' .. format_family(code))
elseif m_languages then
table.insert(result, stars .. ' ' .. format_lang(code))
elseif m_etym_languages then
table.insert(result, stars .. ' ' .. format_etym_lang(code))
end
if tree then
local oldstars = stars
stars = stars .. '*'
table.sort(tree, function (apple, orange)
local appl_lang = m_languages or m_etym_languages
local orng_lang = m_languages or m_etym_languages
local appl_type = (m_etym_languages and "etymology") or (appl_lang and appl_lang.type) or "family"
local orng_type = (m_etym_languages and "etymology") or (orng_lang and orng_lang.type) or "family"
local appl_name = appl_lang and appl_lang.canonicalName or m_families.canonicalName
local orng_name = orng_lang and orng_lang.canonicalName or m_families.canonicalName
if type_map < type_map then
return true
elseif type_map > type_map then
return false
else
return appl_name < orng_name
end
end)
if depth ~= 0 then
depth = depth - 1
for i, item in ipairs(tree) do
add_item(item)
end
depth = depth + 1
end
stars = oldstars
end
end
if with_parents then
local fcode =
(m_families and m_families.family) or
(m_languages and m_languages.family) or
(m_etym_languages and m_etym_languages.parent) or
error("Not a valid language or family code")
local dcode, depth, itnum = fcode, 0, 0
while (dcode ~= "qfa-und") and (dcode ~= "qfa-not") do
dcode = m_families.family
depth = depth + 1
stars = stars .. "*"
end
while itnum < depth do
table.insert(result, 1, stars:sub(1, depth - itnum) .. ' ' .. format_family(fcode))
fcode = m_families.family
itnum = itnum + 1
end
end
add_item(code)
return table.concat(result, "\n")
end
function export.show(frame)
local tree = build_tree()
local root = frame.args or "qfa-not"
local depth = frame.args.depth and tonumber(frame.args.depth)
return make_list(root, tree, frame.args.with_parents, depth)
end
return export