This module page is experimental.
The idea is to create a regional table template for Kazakh that can automatically "fetch" the Latin and Arabic spellings, instead of needing it to be entered. DO NOT USE THIS MODULE, IT IS NOT STABLE OR FUNCTIONAL YET.

This template was made to work with its sister templates Module:kk-convert and Template:kk-alt both of which are also experimental, and are not ready for general use.


local export = {}

-- A list of functions that do the work that is specific to each part of speech.
local pos_functions = {}

local lang = require("Module:languages").getByCode("kk")
local m_links = require("Module:links")
-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
	local args = frame:getParent().args
	PAGENAME = mw.title.getCurrentTitle().text
	local Array = require "Module:array"
	local head = args["head"]; if head == "" then head = nil end
	local function track(page)
	require("Module:debug").track("kk-headword/alt/" .. page)
	return true
end
	-- The part of speech. This is also the name of the category that entries go in.
	local poscat = frame.args[1] or error("Part of speech has not been specified. Please pass parameter 1 to the module invocation.")
	
	-- Detect the script
	local sc = lang:findBestScript(PAGENAME)
	local tr = nil
	
	-- Generate or retrieve the transliteration, depending on the script.
	if sc == "Cyrl" then
		local m_translit = require("Module:kk-translit")
		tr = m_translit.tr(PAGENAME)
	elseif sc == "Arab" then
		tr = args["tr"]; if tr == "" then tr = nil end
	end
	
	local data = {lang = lang, sc = sc, 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 plural = args["pl"]; if plural == "" then plural = nil end
	
	if plural then
		table.insert(data.inflections, {label = "nominative plural", plural})
	end
end 
function export.alt(frame)
	local args = frame:getParent().args
	local currentScript = lang:findBestScript(PAGENAME)
	local currentScriptCode = currentScript:getCode()
	local availableScripts = lang:getScripts()
	local CyrlForm = currentScriptCode == "Cyrl" and PAGENAME or args["Cyrl"] or error("No Cyrillic-script form detected.")
	local scriptCode
	local translit = require("Module:kk-convert").tr
	local m_labels = require("Module:labels")
	
	local terms
	local first
	local output = {[1] = ""}
	local output = Array('<div class="NavFrame" style="max-width:40em"><div class="NavHead" style="background:#d9ebff">Alternative scripts</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"] }

		if scriptCode ~= "Cyrl" then
			local auto = translit(CyrlForm, scriptCode)
			if #terms == 0 then
				terms[1] = auto
			elseif auto == "" then
				-- Helpless - skip script.
			elseif terms[1] ~= auto then
				mw.addWarning("Expected "..auto.." for "..scriptCode.." but given "..terms[1]);
				output:insert("[[Category:Kazakh terms with inconsistent transliterations]]")
			end end 
		if terms[1] ~= "" then
			first = true
			for _,term in ipairs(terms) do
				if term ~= nil and term ~= PAGENAME then
					if first then
						first = false
						output:insert("<li>")
					else
						output:insert(" or ")
					end
					output:insert(m_links.full_link({lang = lang, sc = script, term = term, tr = "-"}))
				end
			end
			if not first then
				output:insert(" ")
				output:insert(m_labels.show_labels {
					labels = { script:getDisplayForm() },
					lang = lang
				} .. "</li>")
			end
		end
	end
	output:insert("</ul></div></div>")

	return output:concat()

end
-- The main entry point.
function export.show(frame)
	local tracking_categories = {}
	
	local iparams = {
		[1] = {required = true},
		["def"] = {}, -- default value
	}

	local iargs = require("Module:parameters").process(frame.args, iparams)
	local poscat = iargs[1]

	local params = {
		["head"] = {list = true},
		["tr"] = {list = true, allow_holes = true},
		["sc"] = {},
		["id"] = {},
		["sort"] = {},
		["suff"] = {type = "boolean"},
	}

	if pos_functions[poscat] then
		for key, val in pairs(pos_functions[poscat].params) do
			params[key] = val
		end
	end
	
    local parargs = frame:getParent().args
	local args = require("Module:parameters").process(parargs, params)
	local heads = args["head"]
	if #heads == 0 and mw.title.getCurrentTitle().nsText == "Template" then
		heads = {iargs["def"]}
	end
	local data = {
		lang = lang,
		sc = require("Module:scripts").getByCode(args["sc"], "sc"),
		pos_category = poscat,
		categories = {},
		heads = heads,
		translits = args["tr"],
		inflections = {},
		id = args["id"],
		sort_key = args["sort"],
		categories = {},
		sccat = true,
	}
	
	if args["suff"] then
		data.pos_category = "suffixes"
		
		if suffix_categories[poscat] then
			local singular_poscat = poscat:gsub("s$", "")
			table.insert(data.categories, langname .. " " .. singular_poscat .. "-forming suffixes")
		else
			error("No category exists for suffixes forming " .. poscat .. ".")
		end
	end
end
return export