Module:pollasena-roots

From Linguifex
Revision as of 16:06, 3 May 2023 by Sware (talk | contribs)
Jump to navigation Jump to search

This module implemented inherited templates for Pollasena languages: {{qsc-inh}}, {{gwax-wasc}}, {{gwax-nen}}, {{lnen-inh}}, {{noan-inh}}, {{ravk-inh}}, {{hceo-inh}}, {{urka-inh}}, {{maat-inh}}, {{uche-inh}}, {{maaz-inh}}. It was generalized to also include other non-Pollasena languages: {{guim-inh}}.
local m_put = require("Module:parse utilities")
local m_table = require("Module:table")

local gsub = mw.ustring.gsub
local PAGENAME = gsub(mw.title.getCurrentTitle().text, "%s", " ")
local match = mw.ustring.match
local gmatch = mw.ustring.gmatch

local lang = require("Module:languages").getByCode("socl")

local export = {}

local function ncategories(categories)
	local out_categories = {}
	for key, cat in ipairs(categories) do
		out_categories[key] = "[[Category:" .. cat .. "]]"
	end

	return table.concat(out_categories, "")
end

local function link(term,alt)
	return "[[Contionary:*" .. term .. "|*" .. (alt or term) .. "]]"	
end

function export.getLink(frame)
	local a = 2
	local params = {
		[1] = {},
		[a] = {list = true}, -- Wascotl
	}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	local param_mods = {"a", "c"}
	local param_mod_set = m_table.listToSet(param_mods)
	local links = {}; local categories = {}
	local term = ""
	-- WIP
	for i, item in ipairs(args[a]) do
		if item == " " or 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, "<", ">")
			
			term = run[1]

			for j = 2, #run - 1, 2 do
				local modtext = run[j]:match("^<(.*)>$")
				local prefix, arg = modtext:match("^([a-z]+):(.*)$")
				
				alt = prefix == "a" and arg or nil
				cat = prefix == "c" and arg or nil
				
				table.insert(links, link(term, alt))
				table.insert(categories, "Soc'ul' terms inherited from Wascotl *" .. (cat or term))
			end
		end
	end
	
	return table.concat(links) .. ncategories(categories)
end


return export