Module:lo-headword: difference between revisions

From Wiktionary, the free dictionary
Jump to navigation Jump to search
Content deleted Content added
No edit summary
let automatic transliteration be added by Module:links; prevents linking of translit in ເງິນຕາ
Line 39: Line 39:
local head = args["head"] or PAGENAME
local head = args["head"] or PAGENAME
local tr = args["tr"] or require("Module:lo-translit").tr(head)
local tr = args["tr"]
local data = {lang = lang, pos_category = poscat, categories = {}, heads = {head}, translits = {tr}, inflections = {}}
local data = {lang = lang, pos_category = poscat, categories = {}, heads = {head}, translits = {tr}, inflections = {}}

Revision as of 03:33, 14 May 2017

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

local export = {}
local pos_functions = {}
local links = require('Module:links')
local gsub = mw.ustring.gsub

local lang = require("Module:languages").getByCode("lo")
local script = require('Module:scripts').getByCode("Laoo")
local PAGENAME = mw.title.getCurrentTitle().text

function export.alt(frame)

	local args = frame:getParent().args
	local dated = args['d'] or PAGENAME:gsub('ໜ','ຫນ'):gsub('ໝ','ຫມ'):gsub('ຫຼ','ຫລ'):gsub('ວຍ','ວຽ'):gsub('ອຍ','ອຽ'):gsub('າຍ','າຽ')
	local datedTerms = (dated and mw.text.split(dated, ',', true) or {})
	local obsolete = args['o'] or nil
	local obsoleteTerms = (obsolete and mw.text.split(obsolete, ',', true) or {})

	local altForms = { ['dated'] = datedTerms, ['obsolete'] = obsoleteTerms }

	local output = '<ul>'
	for _,term in ipairs(altForms.dated) do
		if term ~= PAGENAME then
			output = output .. '<li>(<i>dated</i>) ' .. links.full_link({lang = lang, term = term, sc = script}) .. '</li>'
		end
	end
	for _,term in ipairs(altForms.obsolete) do
		output = output .. '<li>(<i>obsolete</i>) ' .. links.full_link({lang = lang, term = term, sc = script}) .. '</li>'
	end
	output = output .. '</ul>'

	return output

end

function export.show(frame)

	local args = frame:getParent().args
	local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
 
	local head = args["head"] or PAGENAME
	local tr = args["tr"]
	
	local data = {lang = lang, pos_category = poscat, categories = {}, heads = {head}, translits = {tr}, inflections = {}}
	
	if pos_functions[poscat] then
		pos_functions[poscat](args, data)
	end
 
	return require("Module:headword").full_headword(data)

end

pos_functions["nouns"] = function(args, data)

	local classifiers = {label = "classifier", accel = "classifier-of"}

	if args[1] then
		for _,par in ipairs(args) do
			if par == "*" then
				table.insert(classifiers, PAGENAME) -- shorthand
				table.insert(data.categories, "Lao classifiers")
				table.insert(data.categories, "Lao nouns classified by " .. PAGENAME)
			else
				table.insert(classifiers, par)
				table.insert(data.categories, "Lao nouns classified by " .. par)
			end
		end
		table.insert(data.inflections, classifiers)
	end

end

pos_functions["verbs"] = function(args, data)

	local par1 = args[1]; if par1 == "" then par1 = nil end
	local par2 = args[2]; if par2 == "" then par2 = nil end
	local abstract_forms = {label = "abstract noun", accel = "abstract-noun-form-of"}

	if par1 ~= "-" then
		if not par1 then
			table.insert(abstract_forms, "ການ" .. PAGENAME)
		else
			if par1 == "~" then
				table.insert(abstract_forms, "ການ" .. PAGENAME)
				table.insert(abstract_forms, "ຄວາມ" .. PAGENAME)
			else
				table.insert(abstract_forms, par1)
				table.insert(abstract_forms, par2)
			end
		end
		table.insert(data.inflections, abstract_forms)
	end

end

pos_functions["adjectives"] = function(args, data)

	local par1 = args[1]; if par1 == "" then par1 = nil end
	local par2 = args[2]; if par2 == "" then par2 = nil end
	local abstract_forms = {label = "abstract noun", accel = "abstract-noun-form-of"}

	if par1 ~= "-" then
		if not par1 then
			table.insert(abstract_forms, "ຄວາມ" .. PAGENAME)
		else
			if par1 == "~" then
				table.insert(abstract_forms, "ຄວາມ" .. PAGENAME)
				table.insert(abstract_forms, "ການ" .. PAGENAME)
			else
				table.insert(abstract_forms, par1)
				table.insert(abstract_forms, par2)
			end
		end
		table.insert(data.inflections, abstract_forms)
	end

end

-- same logic
pos_functions["adverbs"] = pos_functions["adjectives"]
-- same logic
pos_functions["proper nouns"] = pos_functions["nouns"]

return export