Modul:list of languages
A modult a Modul:list of languages/doc lapon tudod dokumentálni
local m_families = mw.loadData("Module:families/data")
local m_lang = require("Module:languages")
local export = {}
local filters = {}
function export.count(frame)
return require("Module:table").size(mw.loadData("Module:languages/alldata"))
end
function export._show(filter_name, arg2, ids)
local filter = filters[filter_name]
ids = not ids or ids == ""
local fun = require("Module:fun")
local deepcopy = require("Module:table").deepcopy
local function copy(t)
return deepcopy(t, true) -- omit metatables
end
local m_languages
local use_filter = false
-- Choose a data module.
if filter_name == "two-letter code" then
m_languages = mw.loadData("Module:languages/data2")
if arg2 then
use_filter = true
end
elseif filter_name == "three-letter code" then
if arg2 and arg2:find("^[a-z]$") then
m_languages = mw.loadData("Module:languages/data3/" .. arg2)
else
m_languages = mw.loadData("Module:languages/alldata")
end
elseif filter_name == "exceptional" then
m_languages = mw.loadData("Module:languages/datax")
else
m_languages = mw.loadData("Module:languages/alldata")
use_filter = true
end
-- Select language codes to display.
local data_tables = {}
if use_filter then
filter = filter(arg2)
data_tables = fun.filter(filter, m_languages)
else
data_tables = m_languages
end
-- Now go over each code, and create table rows for those that are selected
local rows = {}
local row_i = 1
local function link_script(script)
return "[[Wikiszótár:Írásrendszerek listája#" .. script .. "|<code>" .. script .. "</code>]]"
end
for code, data in require("Module:table").sortedPairs(data_tables) do
local langObj = m_lang.makeObject(code, data)
local canonicalName, category = langObj:getCanonicalName(), langObj:getCategoryName()
local family, scripts = data[3], data.scripts
local row = {
"\n|-", (ids and " id=\"" .. code .. "\" |" or ""),
"\n|", "<code>", code, "</code>",
"\n| [[:Category:", category, "|", canonicalName, "]]",
"\n|", (family and family ~= "qfa-und" and ("[[Wiktionary:Nyelvcsaládok listája#%s|%s]]"):format(family, m_families[family] and m_families[family].canonicalName or ("<code>" .. family .. "</code>")) or ""),
"\n|"
}
if scripts and scripts[1] ~= "None" then
table.insert(
row,
table.concat(
fun.map(
link_script,
scripts),
", "))
end
table.insert(row, "\n|")
if data.otherNames then
table.insert(row, table.concat(copy(data.otherNames), ", "))
end
table.insert(row,
"\n| " .. (data.sort_key and "Igen" or "") ..
"\n| " .. (data.entry_name and "Igen" or "")
)
rows[row_i] = table.concat(row)
row_i = row_i + 1
end
return table.concat {
[[
{| class="wikitable sortable mw-datatable"
! Kód
! Kanonikus név
! Nyelvcsalád
! style="width: 12em" | Írásrendszerek
! Más nevek
! Saját rendezés?
! Mellékjelek ki?]], table.concat(rows), "\n|}"
}
end
function export.show(frame)
return export._show(frame.args[1], frame.args[2], frame.args["ids"])
end
-- Filter functions
-- They receive parameter 2 as argument and generate a new function.
-- This function returns true or false depending on whether a given code
-- should be included in the table or not.
-- They're used to build shorter sublists.
-- The arguments are in the order "data, code" because the filter function in
-- [[Module:fun]] supplies arguments to it in the order value, key.
filters["two-letter code"] = function (firstletter)
local pattern = "^" .. (firstletter or "[a-z]") .. "[a-z]$"
return function (data, code)
return code:find(pattern) ~= nil
end
end
filters["type"] = function (type)
return function (data, code)
return data.type == type
end
end
filters["subst"] = function (arg2)
return function (data, code)
return data.sort_key or data.entry_name
end
end
filters["special"] = function (arg2)
return function (data, code)
return data.family == "qfa-not"
end
end
--
function export.show_etym(frame)
local m_languages = mw.loadData("Module:languages/alldata")
local m_etym_data = require('Module:etymology_languages/data') -- this probably HAS to be a require here
local codes_list = {}
local items = {}
for code, data in pairs(m_etym_data) do
if not codes_list[data] then
codes_list[data] = {}
table.insert(items, data)
end
table.insert(codes_list[data], code)
end
table.sort(items, function (apple, orange)
return apple.canonicalName < orange.canonicalName
end)
local function make_parent_link(code)
if m_languages[code] then
return ('[[Wiktionary:List of languages#%s|%s]]'):format(code, m_languages[code][1])
elseif m_families[code] then
return ('[[Wiktionary:List of families#%s|%s family]]'):format(code, m_families[code].canonicalName)
elseif m_etym_data[code] then
return ('[[Wiktionary:List of languages/special#%s|%s]]'):format(code, m_etym_data[code].canonicalName)
elseif code then
return '<code>' .. code .. '</code>'
else
return '[missing]'
end
end
local rows = {}
for i, data in ipairs(items) do
local codes = codes_list[data]
table.sort(codes)
for i, code in ipairs(codes) do
codes[i] = '<code id="' .. code .. '">' .. code .. '</code>'
end
table.insert(rows,
' \n' ..
'| ' .. table.concat(codes, ", ") .. '\n' ..
'| [[:Category:Terms derived from ' .. data.canonicalName .. '|' .. data.canonicalName .. ']]\n' ..
'| ' .. (data.otherNames and table.concat(data.otherNames, ", ") or "") .. '\n' ..
'| ' .. make_parent_link(data.parent)
)
end
return
"{| class=\"wikitable sortable mw-datatable\"\n" ..
"! Codes\n" ..
"! Canonical name\n" ..
"! Other names\n" ..
"! Parent\n" ..
"|-" .. table.concat(rows, "\n|-") .. "\n|}"
end
return export