This module is responsible for automating the display of Swadesh lists.
See {{Swadesh list auto}}
for how to use this module on Swadesh list pages.
The data submodules should return a table of words indexed by their index on the 207-word Swadesh list. Indexes may be left out at will. The values should be a list of terms (explained below).
For example:
m = {{term = "I"}} m = {{term = "you"}}
A term is a table with the following keys (all of which are technically optional, but at least either term
or tr
must be provided in practice:
term
alt
tr
ts
id
{{senseid}}
or {{etymid}}
).ipa
notes
nolink
true
to disable the link to the term.In addition, the returned table may also have a key nativename
that contains the name of that language in that language.
See the submodule links below for more examples.
local export = {}
local m_links = require("Module:links")
local m_ipa = require("Module:IPA")
local English = {
"] (<span style=\"font-variant:small-caps;\">1sg</span>)",
"] (<span style=\"font-variant:small-caps;\">2sg</span>)",
"], ], ] (<span style=\"font-variant:small-caps;\">3sg</span>)",
"] (<span style=\"font-variant:small-caps;\">1pl</span>)",
"] (<span style=\"font-variant:small-caps;\">2pl</span>)",
"] (<span style=\"font-variant:small-caps;\">3pl</span>)",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"] (adult male)",
"] (human being)",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"] (of a tree)",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"] (noun)",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"] (organ)",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ] (as in a bed)",
"to ]",
"to ]",
"to ] (intransitive)",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"to ]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"to ]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"] (as a knife)",
"] (as a knife)",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]",
"]"
}
--array - list of 207 objects in this form {gloss=term}
local data = {}
function export.python_dictionary(frame)
local args = frame:getParent().args
local dataurl = args
if args then dataurl = dataurl .. '/' .. args end
local data = require("Module:Swadesh/data/" .. dataurl)
local lang = require("Module:languages").getByCode(args.lang, "lang", "allow etym")
local res = "{'name': '" .. lang:getCanonicalName()
if data ~= nil then res = res .. ' (' .. data .. ')' end
res = res .. "',"
for word = 1, #English do
res = res .. "'" .. word .. "': ["
if data ~= nil then
for _, termdata in ipairs(data) do
local translit = (lang:transliterate(termdata.alt or termdata.term))
res = res .. '{'
if termdata.term then res = res .. "'term': '" .. termdata.term:gsub("'", "'") .. "', " end
if termdata.alt then res = res .. "'alt': '" .. termdata.alt:gsub("'", "'") .. "', " end
if termdata.tr or translit then res = res .. "'translit': '" .. (termdata.tr or translit):gsub("'", "'") .. "', " end
if termdata.ts then res = res .. "'transcript': '" .. termdata.ts:gsub("'", "'") .. "', " end
if termdata.id then res = res .. "'id': '" .. termdata.id:gsub("'", "'") .. "', " end
if termdata.ipa then res = res .. "'ipa': '" .. termdata.ipa:gsub("'", "'") .. "', " end
if termdata.nolink then res = res .. "'nolink': '" .. termdata.nolink:gsub("'", "'") .. "', " end
if termdata.notes then res = res .. "'notes': '" .. termdata.notes:gsub("'", "'") .. "', " end
res = res .. '},'
end
end
res = res .. "],"
end
res = res .. "}"
return "<pre>" .. require("Module:string/nowiki")(res) .. "</pre>"
end
function export.show(frame)
local parent_args = frame:getParent().args
local data = {}
local langs = {}
local res = mw.html.create("table"):addClass("wikitable sortable")
local headers = res:tag("tr")
for _, text in ipairs { "№", "English" } do
headers:tag("th"):node(text)
end
local params = {
= {list = true, disallow_holes = true},
= {list = true, allow_holes = true},
= {type = "boolean"},
= {type = "boolean"},
= {type = "number"},
= {type = "number"},
}
local args = require("Module:parameters").process(parent_args, params, nil, "Swadesh", "show")
local from = args.from or 1
local to = args.to or #English
for i, arg in ipairs(args) do
local lang = arg
local header = arg
local lang_obj = require("Module:languages").getByCode(lang, i, "allow etym")
langs = lang_obj
local var = args
if var then
arg = arg .. "/" .. var
end
local data_module = require("Module:Swadesh/data/" .. arg)
data = data_module
local header = lang_obj:getCanonicalName()
local header_in_data = data_module
if header_in_data ~= nil and args.translit then
header = header .. " (" .. header_in_data .. ")"
end
local nativename = data_module
if nativename ~= nil then
header = header .. "<br><small>" .. m_links.full_link{lang = lang_obj, alt = nativename} .. "</small>"
end
local count = 0
for k, v in pairs(data_module) do
if (type(k) == "number") then count = count + 1 end
end
header = header .. "<br><small><sup>]</sup></small>"
headers:tag("th"):node(header)
end
local show_ipa = #args < 2 and not args.translit
if show_ipa then
show_ipa = args.ipa
-- do not display IPA by default for reconstructed languages
if not show_ipa then
show_ipa = not langs:hasType("reconstructed")
end
if show_ipa then
local has_ipa = false
for word = from, to do
if data then
for _, termdata in ipairs(data) do
if termdata.ipa then
has_ipa = true
break
end
end
end
if has_ipa then break end
end
show_ipa = has_ipa
end
if show_ipa then
local key = ""
if mw.loadData("Module:IPA/data").langs_with_infopages:getCode()] then
key = "<br><small>(:getCanonicalName() .. " pronunciation|key]])</small>"
end
headers:tag("th"):node("IPA" .. key)
end
end
for word = from, to do
local row = mw.html.create("tr")
row:tag("td"):node(word)
row:tag("td"):node(English)
for lang, arg in ipairs(args) do
local res = ""
local count = 0
local terms = data
local lang_obj = langs
if terms then
for _, termdata in ipairs(terms) do
if count ~= 0 then res = res .. ", " end
local term = termdata.term
if args then
res = res .. '<span class="swadesh-translit">'
local alt = termdata.ts or termdata.tr or (lang_obj:transliterate(termdata.alt or term)) or term
or (termdata.ipa and '<span class="IPA">' .. termdata.ipa .. "</span>")
or "?"
if not termdata.nolink and term ~= nil and term ~= "" then
res = res .. m_links.language_link{lang = lang_obj, term = term or "?",
alt = alt}
else
res = res .. alt
end
else
res = res .. '<span class="swadesh-term">'
if termdata.nolink == nil then
res = res .. m_links.full_link{lang = lang_obj, term = term, alt = termdata.alt, tr = termdata.tr, ts = termdata.ts, id = termdata.id}
else
res = res .. term
end
end
local notes = termdata.notes
if notes then
if #args < 2 then res = res .. " (''<span class=\"swadesh-note\">" .. notes .. "</span>'')"
else res = res .. '<abbr title = "' .. notes .. ">*</abbr>" end
end
res = res .. "</span>"
count = count + 1
end
end
row:tag("td"):node(res)
end
if show_ipa then
local ipas = ""
local count = 0
if data then
for _, termdata in ipairs(data) do
if count ~= 0 then
ipas = ipas .. ", "
end
if termdata.ipa then
ipas = ipas .. '<span class="IPA">' .. termdata.ipa .. "</span>"
count = count + 1
end
end
end
row:tag("td"):node(ipas)
end
res:node(row)
end
return res;
end
return export