Module:pollasena-roots: Difference between revisions
No edit summary |
No edit summary Tag: Manual revert |
||
| (23 intermediate revisions by the same user not shown) | |||
| 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_lang = require("Module:languages") | |||
local m_param = require("Module:parameters") | |||
local m_param_utils = require("Module:parameter utilities") | |||
local m_etym = require("Module:etymology") | |||
local m_links = require("Module:links") | |||
local gsub = mw.ustring.gsub | local gsub = mw.ustring.gsub | ||
| Line 27: | 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 | return m_links.full_link(data, "term") | ||
end | end | ||
| Line 34: | Line 39: | ||
local a = 0 | local a = 0 | ||
if frame.args[" | if frame.args["offset"] or (frame.args["old"] or frame.args["older"]) then | ||
local offset = frame.args["old"] and 1 or frame.args["older"] and 2 or tonumber(frame.args["offset"]) | |||
local offset = tonumber(frame.args["offset"]) | |||
for i=1,offset do | for i=1,offset do | ||
| Line 102: | Line 103: | ||
end | end | ||
if i~=1 and links[i-1] == "-" then | if i~=1 and links[i-1] == "-" then alts[i] = links[i]:gsub("^%*","") end | ||
if i~=1 and links[i-1] ~= " " then links[i] = links[i]:gsub("%|%*%-"," | --if i~=1 and links[i-1] ~= " " then links[i] = links[i]:gsub("(%|?)%*%-","%1-") end | ||
--if i~=1 and alts[i-1]:match("%-$") then links[i] = links[i]:gsub("%|%*","|") end | --if i~=1 and alts[i-1]:match("%-$") then links[i] = links[i]:gsub("%|%*","|") end | ||
end | end | ||
| Line 110: | Line 111: | ||
end | end | ||
local function parse_args(parent_args, dest_code, ancestor_codes) | |||
local param_mods = m_param_utils.construct_param_mods({{group = {"link", "q", "l"}}}) | |||
local dest_lang = m_lang.getByCode(dest_code) | |||
local etymologies = {} | |||
-- iterate in stable order | |||
for _, ancestor in ipairs(ancestor_codes) do | |||
local code = ancestor.code | |||
local lang_options = ancestor.options or {} | |||
local ancestor_lang = m_lang.getByCode(code) | |||
local ancestor_params = { | |||
[1] = { | |||
required = not lang_options.optional, | |||
list = lang_options.roots, | |||
default = lang_options.default, | |||
}, | |||
} | |||
if lang_options.roots then | |||
ancestor_params[1].allow_holes = true | |||
end | |||
local parsed = 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, | |||
}) | |||
local terms = parsed.terms | |||
-- ensure at least one term exists | |||
if not terms[1] then | |||
terms[1] = { lang = ancestor_lang } | |||
end | |||
local etymology = m_etym.format_derived({ | |||
lang = dest_lang, | |||
sources = { ancestor_lang }, | |||
terms = terms, | |||
nocat = parent_args.nocat, | |||
template_name = "derived", | |||
}) | |||
table.insert(etymologies, etymology) | |||
end | |||
return etymologies | |||
end | |||
local function concat_etymologies(parent_args, etymologies) | |||
local capital = parent_args.nocap and "f" or "F" | |||
return capital .. "rom " .. table.concat(etymologies, ", from ") .. "." | |||
end | |||
function export.qsc(frame) | |||
local parent_args = frame:getParent().args | |||
local dest_lang = m_lang.getByCode("qsc") | |||
local ancestor_codes = { | |||
["sekh"] = {default = "asʰilavən"}, | |||
["wasc"] = {optional = true, roots = true, default = "asł-ila"} | |||
} | |||
local evolution = parse_args(parent_args, "qsc", ancestor_codes) | |||
return concat_etymologies(parent_args, evolution) | |||
end | |||
function export.lyti(frame) | |||
local parent_args = frame:getParent().args | |||
local source_code = parent_args.source | |||
local ancestor_codes = { | |||
["lyti-mid"] = {optional = not parent_args.mid}, | |||
["lyti-old"] = {optional = not parent_args.old}, | |||
[source_code] = {}, | |||
} | |||
local terms, args = parse_args(parent_args, "lyti", ancestor_codes) | |||
end | |||
return export | return export | ||