Modul:a

Wiktionary saytından

Bu modulun sənədləşdirmə səhifəsi Modul:a/doc səhifəsində yaradıla bilər

local export = {}

function export.show(frame)
	data = mw.loadData("Module:a/data")
	
	local args = frame.getParent and frame:getParent().args or frame
	
	if (not args[1] or args[1] == "") and mw.title.getCurrentTitle().nsText == "Template" then
		return '<span class="ib-brac"><span class="qualifier-brac">(</span></span>' .. 
			'<span class="ib-content"><span class="qualifier-content">{{{1}}}' ..
			'</span></span><span class="ib-brac"><span class="qualifier-brac">)</span></span>'
	end
	
	local params = {
		[1] = {required = true, list = true}
	}
	local inputs = require("Module:parameters").process(args, params)
	
	local accents = {}
	
	for _, accent in ipairs(inputs[1]) do
		if data[accent] then
			if data[accent].link then
				table.insert(accents, "[[w:" .. data[accent].link .. "|" ..
					(data[accent].display or data[accent].link) .. "]]")
			elseif data[accent].display then
				table.insert(accents, data[accent].display)
			end
		else
			table.insert(accents, accent)
		end
	end
	
	return '<span class="ib-brac"><span class="qualifier-brac">(</span></span>' ..
		'<span class="ib-content"><span class="qualifier-content">' .. table.concat(accents, ", ") ..
		'</span></span><span class="ib-brac"><span class="qualifier-brac">)</span></span>'
end

function export.checkusage()
	if mw.title.getCurrentTitle().nsText ~= "" then
		return ""
	end
	
	local content = mw.title.getCurrentTitle():getContent()
	local length = mw.ustring.len(content)
	
	local iterate_find = function(pattern)
		local index = 1
		return function()
			index = mw.ustring.find(content, pattern, index+5)
			return index
		end
	end
	
	local indices = {}
	for index in iterate_find("===+ *Pronunciation *===+") do
		local next_hyphens = mw.ustring.find(content, "\n%-%-%-%-", index) or length
		local next_equals = mw.ustring.find(content, "\n==+[^\n]+==+", index) or length
		table.insert(indices, {index, math.min(next_hyphens, next_equals)})
	end
	
	for index in iterate_find("{{a|") do
		local valid = false
		for _,locations in ipairs(indices) do
			if locations[1] < index and index < locations[2] then
				valid = true
			end
		end
		if not valid then
			return "[[Category:usage of a in wrong position]]"
		end
	end
	
	return ""
end

return export