Module:pollasena-roots: Difference between revisions

No edit summary
No edit summary
Line 1: Line 1:
local m_put = require("Module:parse utilities")
local m_put = require("Module:parse utilities")
local m_families = require("Module:families")
local m_families = require("Module:families")
local m_languages = require("Module:languages")
local m_lang = require("Module:languages")
local m_param = require("Module:parameters")
local m_param = require("Module:parameters")
local m_param_utils = require("Module:parameter utilities")
local m_param_utils = require("Module:parameter utilities")
local m_etym = require("Module:etymology")
local m_etym = require("Module:etymology")
local m_links = require("Module:links")


local gsub = mw.ustring.gsub
local gsub = mw.ustring.gsub
Line 13: Line 14:


local export = {}
local export = {}
local function getLanguage(code)
return require("Module:languages").getByCode(code)
end


local function ncategories(categories)
local function ncategories(categories)
Line 35: Line 32:
end
end
local data = {term = term, alt = alt or term, lang = lang, to_wikt = natlang}
local data = {term = term, alt = alt or term, lang = lang, to_wikt = natlang}
return require('Module:links').full_link(data, "term")
return m_links.full_link(data, "term")
end
end


Line 114: Line 111:
end
end


local function parse_etym_args(parent_args, base_params, dest_code)
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 terms, args = m_param_utils.parse_term_with_inline_modifiers_and_separate_params({
local dest_lang = m_lang.getByCode(dest_code)
params = base_params,
local ancestor_lang, etymology
param_mods = param_mods,
raw_args = parent_args,
local ancestor_params, terms, args, etymologies = {}, {}, {}, {}
termarg = 1,
for ancestor_code, lang_options in pairs(ancestor_codes) do
lang = function(args)
ancestor_params = {
return args[sourcearg][#args[sourcearg]]
["nocat"] = {type = "boolean"},
end,
["nocap"] = {type = "boolean"},
sc = "sc",
[1] = {
})
required = not lang_options.optional,
-- If term param 3= is empty, there will be no terms in terms.terms. To facilitate further code and for
list = lang_options.roots,
-- compatibility,, insert one. It will display as <small>[Term?]</small>.
},
if not terms.terms[1] then
terms.terms[1] = {
lang = args[sourcearg][#args[sourcearg]],
sc = args.sc,
}
}
if lang_options.roots then
params[1].allow_holes = true
end
ancestor_lang = m_lang.getByCode(ancestor_code)
terms, arg = m_param_utils.parse_term_with_inline_modifiers_and_separate_params({
params = ancestor_params,
param_mods = param_mods,
raw_args = parent_args,
termarg = 1,
lang = ancestor_lang,
sc = "sc.default",
})
if not terms.terms[1] then
terms.terms[1] = {
lang = ancestor_lang,
}
end
terms = terms.terms
etymology = m_etym.format_derived({
lang = dest_lang,
sources = ancestor_lang,
terms = terms[ancestor_code],
nocat = args.nocat,
template_name = "derived",
})
table.insert(etymologies, etymology)
end
end
 
return terms.terms, args
return etymologies
end
end


local function concat_etymologies(parent_args, etymologies)


local function parse_args(parent_args, dest_code, ancestor_codes)
local capital = parent_args.nocap and "f" or "F"
local params = {
["nocat"] = {type = "boolean"},
["nocap"] = {type = "boolean"},
}
for i, lang_options in ipairs(ancestor_codes) do
params[i] = {
required = not lang_options.optional,
}
end
return parse_etym_args(parent_args, params, dest_code)
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 = {
["sekh"] = {},
["sekh"] = {},
["wasc"] = {optional = true}
["wasc"] = {optional = true, roots = true}
}
}
local terms, args = parse_args(parent_args, "qsc", ancestor_codes)
local evolution = parse_args(parent_args, "qsc", ancestor_codes)
local capital = args.nocap and "f" or "F"
m_etym.format_derived {
lang = args[1],
sources = args[2],
terms = terms,
sort_key = args.sort,
nocat = args.nocat,
sourceconj = args.sourceconj,
conj = args.conj,
template_name = "derived",
force_cat = force_cat,
}
return capital .. "rom " .. table.concat(evolution, ", from ") .. "."
return concat_etymologies(parent_args, evolution)
end
end