Jump to content

Module:jinsiga iyo tirada

Ka Wiktionary

Documentation for this module may be created at Module:jinsiga iyo tirada/doc

--[=[
	Sawirkan waxa uu abuuraa qaab yoolka ah ee jinsiga iyo tirada.
    Waxaa badasha faahfaahinta jinsiga qaab Wiki / HTML ah.
	
	Faahfaahinta jinsiga A waxaa ku qoran liiska mid ka mid ah waxyaabaha hoos ku qoran,
    kala hyphens. Tusaale ahaan: "c", "n", "f-p", "m-ah-p"
]=]--

local export = {}

local codes = {}

-- Liiska dhan "qaybo" suurto gal ah in faahfaahinta ah waxaa la samayn karaa ka mid ah.

codes["?"] = '<abbr title="gender incomplete">?</abbr>'

-- Jinsi
codes["m"] = '<abbr title="masculine gender">m</abbr>'
codes["f"] = '<abbr title="feminine gender">f</abbr>'
codes["n"] = '<abbr title="neuter gender">n</abbr>'
codes["c"] = '<abbr title="common gender">c</abbr>'

-- Isreebreebka dheeraad ah
codes["an"] = '<abbr title="animate">anim</abbr>'
codes["in"] = '<abbr title="inanimate">inan</abbr>'
codes["pr"] = '<abbr title="personal">pers</abbr>'

-- Lambarada
codes["s"] = '<abbr title="singular number">sg</abbr>'
codes["d"] = '<abbr title="dual number">du</abbr>'
codes["p"] = '<abbr title="plural number">pl</abbr>'

-- Isreebreebka fal
codes["impf"] = '<abbr title="imperfective aspect">impf</abbr>'
codes["pf"] = '<abbr title="perfective aspect">pf</abbr>'

-- Kitaabka of liiska qaab in la beddeli kara ka jaantus ah.
function export.show_list(frame)
	local args = frame.args
	local lang = args["lang"]; if lang == "" then lang = nil end
	local list = {}
	local i = 1
	
	while args[i] and args[i] ~= "" do
		table.insert(list, args[i])
		i = i + 1
	end
	
	return export.format_list(list, lang)
end

-- Qaabka hal ama jinsi dheeraad ah tilmaamaha gaarka u ah, oo ah qaab miis ka sooca ah.
function export.format_list(list, lang)
	local is_nounclass = nil
	
	-- Badan faahfaahinta kasta oo qaab.
	for key, spec in ipairs(list) do
		local nc
		list[key], nc = export.format_specification(spec, lang)
		
		-- Hubi in shay sooc ka jira oo dhan ka mid ah fasalada magac, ama midkoodna yihiin.
		if is_nounclass == nil then
			is_nounclass = nc
		elseif is_nounclass ~= nc then
			error("Fasalada magac iyo jinsi ma lagu qasi karaa. Fadlan isticmaal mid ama ka kale.")
		end
	end
	
	if is_nounclass then
		-- Xeerasha baaraandegi wada Add la dhimi
		return "<span class=\"gender\">class " .. table.concat(list, "/") .. "</span>"
	else
		-- Xeerasha baaraandegi wada dar leh hakadka
		return "<span class=\"gender\">" .. table.concat(list, ", ") .. "</span>"
	end
end

-- Qaabka-qaybo sub ee hal faahfaahinta jinsiga ah.
function export.format_specification(spec, lang)
	local categories = ""
	local ret = ""
	local is_nounclass = false
	
	-- Haddii faahfaahinta ku bilaabataa cX, markaas waa faahfaahinta fasalka magac ah.
	if spec:find("^[1-9]") or spec:find("^c[^-]") then
		is_nounclass = true
		code = spec:gsub("^c", "")
		
		if code == "?" then
			ret = "<abbr class=\"noun-class\" title=\"noun class missing\">?</abbr>"
		else
			ret = "<abbr class=\"noun-class\" title=\"noun class " .. code .. "\">" .. code .. "</abbr>"
		end
	else
		-- Ku daatay qaybo iyo iterate qayb kasta, u beddelaya qaab bandhigay ay
		local parts = mw.text.split(spec, "-")
		
		for key, code in ipairs(parts) do
			-- Is this code valid?
			if codes[code] then
				parts[key] = codes[code]
			else
				error("The gender specification \"" .. spec .. "\" is not valid.")
			end
		end
		
		-- Xeerasha baaraandegi wada dar leh meelaha aan burbureyso
		ret = table.concat(parts, "&nbsp;")
	end
	
	-- Ma jeegag dheeraad ah qaar ka mid ah haddii afka ah la siiyey
	if lang then
		-- Tani ma jinsiga ah aan dhamaystirnayn?
		if spec:find("?") then
			local m_utilities = require("Module:utilities")
			categories = m_utilities.format_categories({lang:getCanonicalName() .. "la jinsiga dhamaystirnayn"}, nil)
		end
		
		-- Check if the specification is valid
		--elseif langinfo.genders then
		--	local valid_genders = {}
		--	for _, g in ipairs(langinfo.genders) do valid_genders[g] = true end
		--	
		--	if not valid_genders[spec] then
		--		local valid_string = {}
		--		for i, g in ipairs(langinfo.genders) do valid_string[i] = g end
		--		error("The gender specification \"" .. spec .. "\" is not valid for " .. langinfo.names[1] .. ". Valid are: " .. table.concat(valid_string, ", "))
		--	end
		--end
	end
	
	return ret .. categories, is_nounclass
end

return export