Modul:cat-utils

Vikilug‘atdan olingan

Bu modul uchun Modul:cat-utils/doc nomli hujjat sahifasini yaratishingiz mumkin

local p = {}

function p.format_categories(categories, langcode, sort_key)
	local out_categories = {}
	for key, cat in ipairs(categories) do
		out_categories[key] = "[[Turkum:" .. cat .. 
			(langcode and "/" .. langcode or "") ..
			(sort_key and "|" .. sort_key or "") .. "]]"  
	end
	
	return table.concat(out_categories, "")
end

-- Used by {{Category}}
function p.categorize(frame)
    local NAMESPACE = mw.title.getCurrentTitle().nsText
    if (NAMESPACE ~= '') and (NAMESPACE ~= 'Turkum') then
    	return ''	
    end
    
	local args = frame:getParent().args
	local langcode = args['lang']
	if langcode == "" then 
		langcode = nil 
	end
	local sort_key = args["sort"]; 
	if sort_key == "" then 
		sort_key = nil 
	end
	local i = 1
	local cat = args[1]
	local categories = {}
	while cat do
		if cat ~= "" then
			table.insert(categories, cat)
		end
		i = i + 1
		cat = args[i]
	end
	if table.getn(categories) == 0 then
		table.insert(categories, 'Turkumlashtirish kerak')
		sort_key = nil
	end
	return p.format_categories(categories, langcode, sort_key)
end


return p