|
|
| (11 intermediate revisions by the same user not shown) |
| Line 17: |
Line 17: |
|
| |
|
| local wasc_suffixes = m_table.listToSet { | | local wasc_suffixes = m_table.listToSet { |
| "-ati", "-cosc", "-e", "-ekan", "-i", "-ila", | | "-ati", "-cosc", "-e", "-ekan", "-i", "-ila", "-kan", |
| "-kan", "-la", "-osc", "-otl", "-que", "-scati", "-si"
| | "-la", "-osc", "-otl", "-que", "-scati", "-si", "-tl", |
| } | | } |
|
| |
| local function ncategories(categories)
| |
| local out_categories = {}
| |
| for key, cat in ipairs(categories) do
| |
| out_categories[key] = "[[Category:" .. cat .. "]]"
| |
| end
| |
|
| |
| return NAMESPACE == "Template" and "" or table.concat(out_categories, "")
| |
| end
| |
|
| |
| local function link(lang, term, alt)
| |
| local natlang = lang:getWikidataItem() or false
| |
| -- true if the language declaration has a wikidata item, a marginal amount of conlangs have it
| |
|
| |
| if lang:hasType("reconstructed") and not term:match("^%*") then
| |
| term = "*" .. term
| |
| end
| |
| local data = {term = term, alt = alt or term, lang = lang, to_wikt = natlang}
| |
| return m_links.full_link(data, "term")
| |
| end
| |
|
| |
| function export.getLink(frame)
| |
| local params = {}
| |
| local a = 0
| |
|
| |
| 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"])
| |
|
| |
| for i=1,offset do
| |
| params[i] = {}
| |
| end
| |
| params[offset+1] = {list = true}
| |
| a = offset + 1
| |
| else
| |
| params[1] = {list = true}
| |
| a = 1
| |
| end
| |
|
| |
| -- exceptions
| |
| params["and"], params["see"] = {}, {}
| |
|
| |
| local args = require("Module:parameters").process(frame:getParent().args, params)
| |
|
| |
| local fam, lang = m_families.getByCode(frame.args[1]), require("Module:languages").getByCode(frame.args[2])
| |
| local proto = fam:getProtoLanguage()
| |
|
| |
| local links = {}; local categories = {}; local alts = {};
| |
| -- WIP
| |
| for i, item in ipairs(args[a]) do
| |
| if item == "+" then
| |
| table.insert(links," ")
| |
| elseif item == "-" then
| |
| table.insert(links, item)
| |
| elseif item:find("<") and not item:find("^[^<]*<[a-z]*[^a-z:]") then
| |
| local run = m_put.parse_balanced_segment_run(item, "<", ">")
| |
| local orig_param = a + i - 1
| |
| local function parse_err(msg)
| |
| error(msg .. ": " .. orig_param .. "= " .. table.concat(run))
| |
| end
| |
| local term = run[1]:gsub("%*","")
| |
|
| |
| for j = 2, #run - 1, 2 do
| |
| local modtext = run[j]:match("^<(.*)>$")
| |
| local prefix, arg = modtext:match("^([a-z]+):(.*)$")
| |
|
| |
| if item:match("><") then
| |
| if prefix == "a" then
| |
| table.insert(links, link(proto, term, arg))
| |
| table.insert(alts, arg)
| |
| elseif prefix == "c" then
| |
| table.insert(categories, lang:getCanonicalName() .. " terms from " .. proto:getCanonicalName() .. " *" .. arg)
| |
| table.insert(alts, term)
| |
| end
| |
| elseif prefix == "a" then
| |
| table.insert(links, link(proto, term, arg))
| |
| table.insert(categories, lang:getCanonicalName() .. " terms from " .. proto:getCanonicalName() .. " *" .. term)
| |
| table.insert(alts, arg)
| |
| elseif prefix == "c" then
| |
| table.insert(links, link(proto, term))
| |
| table.insert(categories, lang:getCanonicalName() .. " terms from " .. proto:getCanonicalName() .. " *" .. arg)
| |
| table.insert(alts, term)
| |
| end
| |
| end
| |
| else
| |
| table.insert(links, link(proto, args[a][i]))
| |
| table.insert(categories, lang:getCanonicalName() .. " terms from " .. proto:getCanonicalName() .. " *" .. args[a][i])
| |
| table.insert(alts, args[a][i])
| |
| end
| |
|
| |
| 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("(%|?)%*%-","%1-") end
| |
| --if i~=1 and alts[i-1]:match("%-$") then links[i] = links[i]:gsub("%|%*","|") end
| |
| end
| |
|
| |
| return table.concat(links) .. ncategories(categories)
| |
| end
| |
|
| |
|
| local function get_single_args(args, index) | | local function get_single_args(args, index) |
| Line 217: |
Line 121: |
| separator = item.term | | separator = item.term |
| elseif item.term then | | elseif item.term then |
| if root_index > 1 and match(last_term, "%-$") then -- no asterisk after hyphen | | if root_index > 1 and last_term ~= "+" then -- only subsequent asterisks afer space |
| if not item.alt then | | item.alt = gsub(item.alt or item.term, "^%*", "") |
| item.alt = item.term:gsub("^%*", "")
| |
| else
| |
| item.alt = item.alt:gsub("^%*", "")
| |
| end
| |
| end | | end |
| table.insert(terms, item) | | table.insert(terms, item) |
| | | |
| local cat_term = args.c[root_index] or item.term | | local function one_asterisk(str) |
| cat_term = "*" .. gsub(cat_term, "^*+", "") -- ensure only one asterisk
| | return "*" .. gsub(str, "^*+", "") |
| | end |
| | |
| | local cat_term = one_asterisk(args.c[root_index] or item.term) |
| if code == "wasc" then -- Wascotl root and suffix handling | | if code == "wasc" then -- Wascotl root and suffix handling |
| local suffix = match(cat_term, "^*[%w']+(%-[%w']+)$") | | local suffix = match(cat_term, "^*[%w']+(%-[%w']+)$") |
| | | |
| if wasc_suffixes[suffix] then | | if wasc_suffixes[suffix] then |
| cat_term = gsub(cat_term, suffix, "-") | | cat_term = gsub(cat_term, suffix, "-") |
| end | | end |
| end | | end |
| | | |
| table.insert(cats, dest_lang:getCanonicalName() .. " terms from " .. ancestor_lang:getCanonicalName() .. " " .. cat_term) | | table.insert(cats, dest_lang:getCanonicalName() .. " terms derived from the " .. ancestor_lang:getCanonicalName() .. " root " .. cat_term) |
| | | |
| root_index = root_index + 1 | | root_index = root_index + 1 |
| Line 278: |
Line 181: |
| nocat = args.nocat, | | nocat = args.nocat, |
| conj = lang_options.roots and separator or nil, | | conj = lang_options.roots and separator or nil, |
| nocap = args.mid or args.old | | nocap = args.mid or args.old or args.nocap, |
| } | | } |
| else | | else |
| Line 288: |
Line 191: |
| conj = lang_options.roots and separator or nil, | | conj = lang_options.roots and separator or nil, |
| } | | } |
| | etymology = "from " .. etymology |
| end | | end |
| | | |
| Line 310: |
Line 214: |
| end | | end |
| | | |
| local categories = {} | | local categories = m_utils.format_categories(cats, dest_lang) |
| if not parent_args.nocat then
| |
| categories = m_utils.format_categories(cats, dest_lang)
| |
| end
| |
| | | |
| return etymologies, args, categories | | return etymologies, args, parent_args.nocat and "" or categories |
| end | | end |
|
| |
|
| return export | | return export |