Module:descendants: Difference between revisions

ਕੋਈ ਸੋਧ ਸਾਰ ਨਹੀਂ
No edit summary
No edit summary
 
(7 intermediate revisions by the same user not shown)
Line 21: Line 21:
local see_desc = args["see"]
local see_desc = args["see"]
local noname = args["noname"]
local noname = args["noname"]
local nocat = args["nocat"]
local lostcap = args["lost"] or "lost"
local lostcap = args["lost"] or "lost"
if not nocat then out = out .. "[[Category:Terms with " .. lang.name .. " descendants|" .. mw.title.getCurrentTitle().subpageText .. "]]" end
if borrowed then out = "<span class=\"desc-arrow\" title=\"borrowed\">→</span>" .. out end
if borrowed then out = "<span class=\"desc-arrow\" title=\"borrowed\">→</span>" .. out end
if not noname then out = out .. lang.name .. ":&nbsp;" end
if not noname then out = out .. lang.name .. ":&nbsp;" end
Line 38: Line 40:
gloss = term_args.t,
gloss = term_args.t,
pos = term_args.pos,
pos = term_args.pos,
nolink = term_args.nolink,
hypo = term_args.hypo or term_args.hypothetical,
nobold = true,
nobold = true,
})
})
Line 69: Line 73:
ancestors[lang] = {}
ancestors[lang] = {}
-- process ad hoc ancestors
if mw.ustring.find(lang, "[%>%_]") then
local ancestor_path = ""
for piece, delim in mw.ustring.gmatch(lang, "([^%>%_]+)([%>%_])") do
ancestor_path = ancestor_path .. piece
table.insert(ancestors[lang], ancestor_path)
ancestor_path = ancestor_path .. delim
end
if #ancestor_path < 1 then
-- process ad hoc ancestors
local function de_arrow(code)
local ancestor_path = ""
return mw.ustring.gsub(code, "^%>", "")
for piece, delim in mw.ustring.gmatch(lang, "([^%>%_]+)([%>%_])") do
ancestor_path = ancestor_path .. piece
if mw.ustring.match(lang, "^%>") then
ancestor_path = ">" .. ancestor_path
end
table.insert(ancestors[lang], ancestor_path)
ancestor_path = ancestor_path .. delim
end
end
else -- if ad hoc ancestors unspecified, i.e. the code does not contain the path symbols > or _
if mw.ustring.find(lang, "[0-9]+$") then
if mw.ustring.find(lang, "[0-9]+$") then
Line 87: Line 93:
if mw.ustring.find(test, "[^0-9]" .. index .. "$") then -- matches existing historical doublets with identical, e.g. rad-o2, if rad2 is present
if mw.ustring.find(test, "[^0-9]" .. index .. "$") then -- matches existing historical doublets with identical, e.g. rad-o2, if rad2 is present
local test_temp = mw.ustring.gsub(test, index .. "$", "") -- get base
local test_temp = mw.ustring.gsub(test, index .. "$", "") -- get base
if m_languages.get_by_code(de_arrow(lang_temp)).lineage[test_temp] then
if m_languages.get_by_code(lang_temp).lineage[test_temp] then
table.insert(ancestors[lang], test)
table.insert(ancestors[lang], test)
end
end
elseif m_languages.get_by_code(de_arrow(lang_temp)).lineage[test] and not m_table.contains(list, test .. index) then -- if test is still an ancestor to current language, e.g. rad-o, if rad2 is present, and checks if rad-o2 is not present
elseif m_languages.get_by_code(lang_temp).lineage[test] and not m_table.contains(list, test .. index) then -- if test is still an ancestor to current language, e.g. rad-o, if rad2 is present, and checks if rad-o2 is not present
mismatch_check(lang_temp, test)
mismatch_check(lang_temp, test)
table.insert(ancestors[lang], test)
table.insert(ancestors[lang], test)
Line 97: Line 103:
else
else
for _, test in ipairs(list) do
for _, test in ipairs(list) do
if m_languages.get_by_code(de_arrow(lang)).lineage[test] then
if m_languages.get_by_code(lang).lineage[test] then
mismatch_check(lang, test)
mismatch_check(lang, test)
table.insert(ancestors[lang], test)
table.insert(ancestors[lang], test)
Line 151: Line 157:
if lang_change then
if lang_change then
term = mw.ustring.sub(term, mw.ustring.len(lang_change) + 2)
term = mw.ustring.sub(term, mw.ustring.len(lang_change) + 2)
local auto_ancestor, auto_bor = mw.ustring.sub(lang_change, 1, 1) == "_", mw.ustring.sub(lang_change, 1, 2) == ">>"
if auto_ancestor or auto_bor then
if code == nil then error("No preceding language code specified") end
if auto_bor then lang_change = mw.ustring.sub(lang_change, 2) end
lang_change = code .. lang_change
end
local lang_args = {}
local lang_args = {}
Line 184: Line 197:
for lang, lang_args in pairs(terms) do
for lang, lang_args in pairs(terms) do
table.insert(lang_args, 1, lang)
table.insert(lang_args, 1, lang)
lang_args["nocat"] = args["nocat"]
items[lang] = export.descendant(lang_args)
items[lang] = export.descendant(lang_args)
end
end