Module:pollasena-roots: Difference between revisions
Jump to navigation
Jump to search
This module implemented inherited templates for Pollasena languages:
No edit summary |
No edit summary |
||
(46 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 | local m_families = require("Module:families") | ||
local gsub = mw.ustring.gsub | local gsub = mw.ustring.gsub | ||
local PAGENAME = gsub(mw.title.getCurrentTitle().text, "%s", " ") | local PAGENAME = gsub(mw.title.getCurrentTitle().text, "%s", " ") | ||
local NAMESPACE = mw.title.getCurrentTitle().nsText | |||
local match = mw.ustring.match | local match = mw.ustring.match | ||
local gmatch = mw.ustring.gmatch | local gmatch = mw.ustring.gmatch | ||
local export = {} | local export = {} | ||
Line 17: | Line 16: | ||
end | end | ||
return table.concat(out_categories, "") | return NAMESPACE == "Template" and "" or table.concat(out_categories, "") | ||
end | end | ||
local function link(term,alt) | 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 | |||
term = (lang:getType() == "reconstructed" and "*" or "") .. term | |||
local data = {term = term, alt = alt, lang = lang, nocont = natlang} | |||
return require('Module:links').full_link(data) | |||
end | end | ||
function export.getLink(frame) | function export.getLink(frame) | ||
local a = | local params = {} | ||
local a = 0 | |||
[ | |||
[ | if frame.args["older"] then | ||
params[1] = {} | |||
params[2] = {list = true} | |||
a = 2 | |||
else | |||
params[1] = {list = true} | |||
a = 1 | |||
end | |||
local args = require("Module:parameters").process(frame:getParent().args, params) | 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 links = {}; local categories = {}; local alts = {}; | ||
-- WIP | -- WIP | ||
for i, item in ipairs(args[a]) do | for i, item in ipairs(args[a]) do | ||
Line 46: | Line 59: | ||
error(msg .. ": " .. orig_param .. "= " .. table.concat(run)) | error(msg .. ": " .. orig_param .. "= " .. table.concat(run)) | ||
end | end | ||
local term = run[1] | local term = run[1]:gsub("%*","") | ||
for j = 2, #run - 1, 2 do | for j = 2, #run - 1, 2 do | ||
Line 54: | Line 67: | ||
if item:match("><") then | if item:match("><") then | ||
if prefix == "a" then | if prefix == "a" then | ||
table.insert(links, link(term, arg)) | table.insert(links, link(proto, term, arg)) | ||
table.insert(alts, arg) | |||
elseif prefix == "c" then | elseif prefix == "c" then | ||
table.insert(categories, " | table.insert(categories, lang:getCanonicalName() .. " terms from " .. proto:getCanonicalName() .. " *" .. arg) | ||
table.insert(alts, term) | |||
end | end | ||
elseif prefix == "a" then | elseif prefix == "a" then | ||
table.insert(links, link(term, arg)) | table.insert(links, link(proto, term, arg)) | ||
table.insert(categories, " | table.insert(categories, lang:getCanonicalName() .. " terms from " .. proto:getCanonicalName() .. " *" .. term) | ||
table.insert(alts, arg) | |||
elseif prefix == "c" then | elseif prefix == "c" then | ||
table.insert(links, link(term)) | table.insert(links, link(proto, term)) | ||
table.insert(categories, " | table.insert(categories, lang:getCanonicalName() .. " terms from " .. proto:getCanonicalName() .. " *" .. arg) | ||
table.insert(alts, term) | |||
end | end | ||
end | end | ||
else | else | ||
table.insert(links, link(args[a][i])) | table.insert(links, link(proto, args[a][i])) | ||
table.insert(categories, " | table.insert(categories, lang:getCanonicalName() .. " terms from " .. proto:getCanonicalName() .. " *" .. args[a][i]) | ||
table.insert(alts, args[a][i]) | |||
end | end | ||
if links[i-1] == "-" then links[i] = links[i]:gsub("%|%*","|") end | if i~=1 and links[i-1] == "-" then links[i] = links[i]:gsub("%|%*","|") end | ||
if i~=1 and links[i-1] ~= " " then links[i] = links[i]:gsub("%|%*%-","|-") end | |||
--if i~=1 and alts[i-1]:match("%-$") then links[i] = links[i]:gsub("%|%*","|") end | |||
end | end | ||
Revision as of 22:30, 30 January 2024
- The following documentation is located at Module:pollasena-roots/doc.[edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
This module implemented inherited templates for Pollasena languages:
{{qsc-inh}}
, {{gwax-wasc}}
. It was generalized to also include other non-Pollasena languages: {{guim-inh}}
.
local m_put = require("Module:parse utilities")
local m_families = require("Module:families")
local gsub = mw.ustring.gsub
local PAGENAME = gsub(mw.title.getCurrentTitle().text, "%s", " ")
local NAMESPACE = mw.title.getCurrentTitle().nsText
local match = mw.ustring.match
local gmatch = mw.ustring.gmatch
local export = {}
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
term = (lang:getType() == "reconstructed" and "*" or "") .. term
local data = {term = term, alt = alt, lang = lang, nocont = natlang}
return require('Module:links').full_link(data)
end
function export.getLink(frame)
local params = {}
local a = 0
if frame.args["older"] then
params[1] = {}
params[2] = {list = true}
a = 2
else
params[1] = {list = true}
a = 1
end
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 links[i] = links[i]:gsub("%|%*","|") end
if i~=1 and links[i-1] ~= " " then links[i] = links[i]:gsub("%|%*%-","|-") end
--if i~=1 and alts[i-1]:match("%-$") then links[i] = links[i]:gsub("%|%*","|") end
end
return table.concat(links) .. ncategories(categories)
end
return export