Module:descendants: Difference between revisions

Jump to navigation Jump to search
ਕੋਈ ਸੋਧ ਸਾਰ ਨਹੀਂ
mNo edit summary
No edit summary
Line 41: Line 41:
return out
return out
end
function export.tree(frame)
local args = getArgs(frame)
local out = ""
local current_lang
local terms = {}
for i, term in ipairs(args) do --ryn:term1|term2|term3|rad:term1|term2 ...
local lang_change = mw.ustring.match(term, "^([^%:%<]+)%:")
local lang_change_arged = mw.ustring.match(term, "^(.+%>)%:")
if i == 1 and not (lang_change or lang_change_arged) then error("Language code needs to be specified in the first parameter as xyz(<bor>):term₁") end
if lang_change or lang_change_arged then
if lang_change then
current_lang = m_languages.get_by_code(lang_change)
term = mw.ustring.gsub(term, "^[^%:]+%:%s*", "")
elseif lang_change_arged then
current_lang = m_languages.get_by_code(mw.ustring.match(lang_change_arged, "^[^%<]+"))
term = mw.ustring.gsub(term, "^.+%>%:%s*", "")
end
if terms[current_lang.code] == nil then terms[current_lang.code] = {} end
end
if lang_change_arged then
for lang_arg in mw.ustring.gmatch(lang_change_arged, "%<([^%>]+)%>") do
terms[current_lang.code][lang_arg] = true
end
end
table.insert(terms[current_lang.code], term)
end
mw.logObject(terms)
end
end


Line 48: Line 79:
Debug console test string:
Debug console test string:
=p.descendant(mw.getCurrentFrame():newChild{title="whatever",args={"rad"}})
=p.descendant(mw.getCurrentFrame():newChild{title="whatever",args={"rad"}})
=p.tree(mw.getCurrentFrame():newChild{title="whatever",args={"rad:hello", "hi"}})
]]--
]]--

Navigation menu