ข้ามไปเนื้อหา

มอดูล:Pi-headword

จาก วิกิตำรา

เอกสารการใช้งานสำหรับมอดูลนี้อาจสร้างขึ้นที่ มอดูล:Pi-headword/doc

local export = {}
local pos_functions = {}
local links = require('Module:links')
local labels = require('Module:labels')

local lang = require('Module:languages').getByCode('Pi')
local PAGENAME = mw.title.getCurrentTitle().text
local currentScript = require('Module:scripts').findBestScript(PAGENAME, lang)

--[[ ไม่ใช้
local translit = require('Module:Pi-Latn-translit').tr
--]]

function export.alt(frame)

	local args = frame:getParent().args

	local currentScriptCode = currentScript:getCode()
	local availableScripts = lang:getScripts()
	local scriptCode

	local terms
	local first
	local output = '<div class="NavFrame" style="max-width:40em"><div class="NavHead" style="background:#d9ebff">รูปแบบอื่น</div><div class="NavContent" style="text-align:left"><ul>'
	for _,script in ipairs(availableScripts) do
		scriptCode = script:getCode()
		terms = { args[scriptCode], args[scriptCode..'2'], args[scriptCode..'3'] }

		output = output .. '<li>'
		--[=[ ไม่ใช้
		latinForm = currentScriptCode == 'Latn' and PAGENAME or args['Latn'] or error('No Latin-script form detected.')
		if scriptCode ~= 'Latn' then
			if #terms == 0 then
				terms[1] = translit(latinForm, scriptCode)
			elseif terms[1] ~= translit(latinForm, scriptCode) then
				output = output .. '[[Category:Pali terms with inconsistent transliterations]]'
			end
		end
		--]=]

		first = true
		for _,term in ipairs(terms) do
			if term ~= nil and term ~= PAGENAME then
				if first then
					output = output .. links.full_link({lang = lang, sc = script, term = term})
					first = false
				else
					output = output .. ' หรือ ' .. links.full_link({lang = lang, sc = script, term = term})
				end
			end
		end
		if scriptCode ~= currentScriptCode then
			output = output .. ' ' .. labels.show_labels({ script:getCategoryName() }, lang) .. '</li>'
		end
	
	end
	output = output .. '</ul></div></div>'

	return output

end

function export.show(frame)
	local args = require('Module:parameters').process(frame:getParent().args,{
		[1] = {default = '?'},
		['head'] = {},
	})
	local poscat = frame.args[1] or error('Part of speech has not been specified. Please pass parameter 1 to the module invocation.')
	-- หมวดหมู่เป็นภาษาไทย
	local poscat_th = require('Module:utilities').translate_term(poscat)
	
	local data = {lang = lang, sc = currentScript, pos_category = poscat_th, categories = {poscat_th .. 'ภาษาบาลีใน' .. currentScript:getCategoryName()}, heads = {args['head'] or PAGENAME}, genders = {}, inflections = {}}
	
	if poscat_th == 'คำนาม' or poscat_th == 'คำวิสามานยนาม' or poscat_th == 'คำสรรพนาม' or poscat_th == 'คำคุณศัพท์' then
		table.insert(data.genders, args[1])
	end
	
    if poscat_th == 'คำกริยา' then
        table.insert(data.inflections, {label = 'ธาตุ', args[1]})
    end
	
	return require('Module:headword').full_headword(data)
end

return export