Module:cognates: Difference between revisions

ਕੋਈ ਸੋਧ ਸਾਰ ਨਹੀਂ
No edit summary
No edit summary
 
(14 intermediate revisions by the same user not shown)
Line 8: Line 8:
local args = getArgs(frame)
local args = getArgs(frame)
local links = {}
local links = {}
local nat = m_languages.find_by_code(args[1] or "") ~= nil and m_languages.get_by_code(args[1])
local nat = m_languages.find_by_code(args[1] or "")
local params = {
local params = {
nocap = false,
nocap = false,
nocat = false,
nopre = false,
}
}
for lang, entry in pairs(args) do
local langs = {}
for lang, _ in pairs(args) do
if type(lang) == "string" then
if type(lang) == "string" then
if m_languages.find_by_code(lang) then
if m_languages.find_by_code(lang) then
local term, data = m_inline.parse(entry)
table.insert(langs, lang)
local cat = ""
data[1], data[2] = lang, term
local link = frame:expandTemplate{title = "m+", args = data}
if nat then
link = link .. "[[Category:" .. nat.name .. " terms with " .. lang.name .. " cognates]]"
end
table.insert(links, link)
elseif params[lang] ~= nil then --check for parameters
elseif params[lang] ~= nil then --check for parameters
params[lang] = true
params[lang] = true
Line 32: Line 29:
end
end
local text = ((params.nocap and "c") or "C") .. "ognate with "
table.sort(langs, function(a, b)
a = m_languages.get_by_code(a)
b = m_languages.get_by_code(b)
if nat == nil then
return a.name < b.name
end
a_test = m_languages.stage_at_split(nat, a)
b_test = m_languages.stage_at_split(nat, b)
if a_test == b_test then
return a.name < b.name
else
return a_test > b_test
end
end
)
for _, lang in ipairs(langs) do
local term, data = m_inline.parse(args[lang])
data[1], data[2], data["nobold"] = lang, term, true
local pre = data["pre"]
if pre then
pre = pre .. " "
data["pre"] = nil
end
local link = (pre or "") .. frame:expandTemplate{title = "m+", args = data}
if nat and params.nocat == false then link = link .. "[[Category:" .. nat.name .. " terms with " .. m_languages.get_by_code(lang).name .. " cognates|" .. mw.title.getCurrentTitle().subpageText .. "]]" end
table.insert(links, link)
end
local text = ((not params.nopre) and ((params.nocap and "c") or "C") .. "ognate with ") or ""
for i, link in ipairs(links) do
for i, link in ipairs(links) do