Module:xal-headword

From Wiktionary, the free dictionary
Jump to navigation Jump to search

This module needs documentation.
Please document this module by describing its purpose and usage on the documentation page.

local export = {}

local lang = require("Module:languages").getByCode("xal")
local m_scripts = require("Module:scripts")
local sc = m_scripts.getByCode('Cyrl')
	
local params = {
	["head"] = {},
	["cat"] = {list = true},
	[1] = {list = true}
}
	
local function clearscript(inflections, args)
	if #args[1] < 1 then
		return 
	end
	
	m_links = require("Module:links")

	local xwo_sc = m_scripts.getByCode('Mong')
	local xwo_lang = require("Module:languages").getByCode("xwo")
	
	local spelling = {label = "Clear script spelling", sc = xwo_sc, enable_auto_translit=true}
	
	for i, arg in ipairs(args[1]) do
		table.insert(spelling, {term = arg, lang = xwo_lang, sc = xwo_sc})
	end
	
	table.insert(inflections, spelling)
end

local function categorize(cats)
	if cats == nil then
		return nil
	end
	local categories = {}
	for i, arg in ipairs(cats) do
		table.insert(categories, lang:getCanonicalName() .. " " .. arg)
	end
	return categories
end

function export.basic(frame)
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	
	local inflections = {}
	local categories = categorize(args["cat"])
	
	clearscript(inflections, args)
	
	local data = {lang = lang, sc = sc, heads = {args["head"]}, genders = nil, inflections = inflections, pos_category = frame.args[1], categories = categories, sort_key = nil}
	return require("Module:headword").full_headword(data)
end

function export.noun(frame)

	params["pl"] = {list = true}
	
	local args = require("Module:parameters").process(frame:getParent().args, params)
	

	
	local inflections = {}
	
	local categories = categorize(args["cat"])
	
	clearscript(inflections, args)
	
	if #args["pl"] > 0 then
		local plurals = {label = "plural"}
		for i, pl in ipairs(args["pl"]) do
			table.insert(plurals, pl)
		end
		table.insert(inflections, plurals)
	end

	
	local data = {lang = lang, sc = sc, heads = {args["head"]}, genders = nil, inflections = inflections, pos_category = "nouns", categories = categories, sort_key = nil}
	return require("Module:headword").full_headword(data)
end

return export