Module:User:MewBot
Appearance
- The following documentation is located at Module:User:MewBot/documentation. [edit]
- Useful links: subpage list • links • transclusions • testcases • user page • user talk page • userspace
This is a support module used to run certain functions of the bot User:MewBot.
local export = {}
function export.getLanguageData(frame)
local iparams = {
["first"] = {type = "number"},
["last"] = {type = "number"},
["getsize"] = {type = "boolean"},
}
local iargs = require("Module:parameters").process(frame.args, iparams)
local m_languages = require("Module:languages")
local ret = {}
local index = 0
for code, data in pairs(require("Module:languages/data/all")) do
index = index + 1
if (not iargs.first or index >= iargs.first) and (not iargs.last or index <= iargs.last) then
local lang = m_languages.makeObject(code, data, true):toJSON("returnTable")
-- Remove blank aliases/varieties/otherNames/ancestors
for _, to_remove in ipairs { "aliases", "varieties", "otherNames", "ancestors"} do
if lang[to_remove] and not lang[to_remove][1] then
lang[to_remove] = nil
end
end
-- For full languages, "full" is always or almost always the same as the lang code; if so, remove it.
if lang.full == lang.code then
lang.full = nil
end
-- For full languages, "type" should always contain "language" and "full"; remove them.
local hacked_types = {}
for _, typ in ipairs(lang.type) do
if typ ~= "language" and typ ~= "full" then
table.insert(hacked_types, typ)
end
end
lang.type = hacked_types
table.insert(ret, require("Module:JSON").toJSON(lang, {compress = true}))
end
end
local retval = "[" .. table.concat(ret, ", ") .. "]"
if iargs.getsize then
return tostring(mw.ustring.len(retval))
else
return retval
end
end
function export.getFamilyData(frame)
local m_families = require("Module:families")
local ret = {}
for code, data in pairs(require("Module:families/data")) do
local fam = m_families.makeObject(code, data, true)
table.insert(ret, fam:toJSON())
end
return "[" .. table.concat(ret, ", ") .. "]"
end
function export.getScriptData(frame)
local m_scripts = require("Module:scripts")
local ret = {}
for code, data in pairs(require("Module:scripts/data")) do
local sc = m_scripts.makeObject(code, data, true)
table.insert(ret, sc:toJSON())
end
return "[" .. table.concat(ret, ", ") .. "]"
end
function export.getEtymLanguageData(frame)
local m_languages = require("Module:languages")
local ret = {}
for code, data in pairs(require("Module:etymology languages/data")) do
local etymlang = m_languages.makeObject(code, data, true, "dont canonicalize aliases")
table.insert(ret, etymlang:toJSON())
end
return "[" .. table.concat(ret, ", ") .. "]"
end
function export.getAliasData(frame)
local m_languages_data = require("Module:languages/data")
return require("Module:JSON").toJSON(m_languages_data.aliases)
end
return export