local export = {}
local filters = {}
function export.show(frame)
local args = frame.args
local filter = filters[args[1]]
local families = require("Module:families/data")
local languages = require("Module:languages/data/all")
local stats = {}
for code, _ in pairs(families) do
stats[code] = { langs = {}, subfams = {} }
end
for code, data in pairs(languages) do
local fdata = stats[data[3]]
if fdata then
table.insert(fdata.langs, code)
end
end
for code, data in pairs(families) do
local fdata = stats[data[3]]
if fdata then
table.insert(fdata.subfams, code)
end
end
local codes = {}
for code, _ in pairs(families) do
table.insert(codes, code)
end
table.sort(codes)
local rows = {}
for i, code in ipairs(codes) do
local data = families[code]
local rt = nil
if data.otherNames then
local i = 1
rt = {}
while data.otherNames[i] do
table.insert(rt, data.otherNames[i])
i = i + 1
end
end
if (not filter) or filter(code, data, args) then
local catname = (data[1]:find("[Bb]ahasa-bahasa") and "" or "Bahasa-bahasa ") .. data[1]
catname = catname:sub(1, 1):upper() .. catname:sub(2)
table.insert(rows, string.format(
' id="%s"\n' ..
'| <code>%s</code>\n' ..
'| [[:Kategori:%s|%s]]\n' ..
'| %s\n' ..
'| %s\n' ..
'| %u\n' ..
'| %u\n',
code, code,
catname, data[1],
(data[3] ~= nil) and ('[[#' .. data[3] .. '|' .. families[data[3]][1] .. ']]') or '',
rt and table.concat(rt, ", ") or " ",
#stats[code].subfams,
#stats[code].langs
))
end
end
return
"{| class=\"wikitable sortable\"\n" ..
"! Kod\n" ..
"! Nama berkanun\n" ..
"! Keluarga bahasa induk\n" ..
"! Nama lain\n" ..
"! Subkeluarga\n" ..
"! Bahasa-bahasa\n" ..
"|-" .. table.concat(rows, "\n|-") .. "\n|}"
end
filters["three-letter code"] = function (code, data, args)
local firstletter = args[2]
return data[3] ~= "qfa-not" and code:find("^" .. (firstletter or "[a-z]") .. "[a-z][a-z]$") ~= nil
end
filters["exceptional"] = function (code, data, args)
return data[3] ~= "qfa-not" and code:find("-") ~= nil
end
filters["special"] = function (code, data, args)
return data[3] == "qfa-not"
end
return export