Module:pollasena-roots: Difference between revisions

No edit summary
Tag: Reverted
No edit summary
Tag: Reverted
Line 113: Line 113:
local function parse_args(parent_args, dest_code, ancestor_codes)
local function parse_args(parent_args, dest_code, ancestor_codes)
local param_mods = m_param_utils.construct_param_mods({{group = {"link", "q", "l"}}})
local param_mods = m_param_utils.construct_param_mods({{group = {"link", "q", "l"}}})
local dest_lang = m_lang.getByCode(dest_code)
local dest_lang = m_lang.getByCode(dest_code)
local etymologies = {}
local etymologies = {}


-- iterate in stable order
-- Parse all terms once
for _, ancestor in ipairs(ancestor_codes) do
local parsed = m_param_utils.parse_term_with_inline_modifiers_and_separate_params({
params = {},  -- generic, handled per ancestor below
param_mods = param_mods,
raw_args = parent_args,
termarg = 1,
})
local all_terms = parsed.terms
 
-- Loop through ancestors in order
for i, ancestor in ipairs(ancestor_codes) do
local code = ancestor.code
local code = ancestor.code
local lang_options = ancestor.options or {}
local options = ancestor.options or {}
 
local ancestor_lang = m_lang.getByCode(code)
local ancestor_lang = m_lang.getByCode(code)


local ancestor_params = {
-- Select the correct term(s) for this ancestor
[1] = {
local terms = {}
required = not lang_options.optional,
if i == 1 then
list = lang_options.roots,
-- first ancestor takes the first term
default = lang_options.default,
if all_terms[1] then terms = { all_terms[1] } end
},
else
}
-- subsequent ancestors take remaining terms
 
for j = i, #all_terms do
if lang_options.roots then
table.insert(terms, all_terms[j])
ancestor_params[1].allow_holes = true
end
end
end


local parsed = m_param_utils.parse_term_with_inline_modifiers_and_separate_params({
-- Ensure at least one term exists
params = ancestor_params,
param_mods = param_mods,
raw_args = parent_args,
termarg = 1,
lang = ancestor_lang,
})
 
local terms = parsed.terms
 
-- ensure at least one term exists
if not terms[1] then
if not terms[1] then
terms[1] = { lang = ancestor_lang }
terms[1] = { lang = ancestor_lang }
end
end


-- Generate etymology step
local etymology = m_etym.format_derived({
local etymology = m_etym.format_derived({
lang = dest_lang,
lang = dest_lang,
Line 165: Line 163:
end
end


-- Concatenate multiple etymology steps into a readable string
local function concat_etymologies(parent_args, etymologies)
local function concat_etymologies(parent_args, etymologies)
local capital = parent_args.nocap and "f" or "F"
local capital = parent_args.nocap and "f" or "F"
return capital .. "rom " .. table.concat(etymologies, ", from ") .. "."
return capital .. "rom " .. table.concat(etymologies, ", from ") .. "."
end
end


function export.qsc(frame)
function export.qsc(frame)
local parent_args = frame:getParent().args
local parent_args = frame:getParent().args
local dest_lang = m_lang.getByCode("qsc")
 
local ancestor_codes = {
local ancestor_codes = {
{code = "sekh", options = {default = "asʰilavən"}},
{ code = "sekh", options = { default = "asʰilavən" } },
{code = "wasc", options = {optional = true, roots = true, default = "asł-ila"}},
{ code = "wasc", options = { optional = true, roots = true, default = "asł-ila" } },
}
}
 
local evolution = parse_args(parent_args, "qsc", ancestor_codes)
local etymologies = parse_args(parent_args, "qsc", ancestor_codes)
return concat_etymologies(parent_args, etymologies)
return concat_etymologies(parent_args, evolution)
end
end