Module:accel/ar

From Wiktionary, the free dictionary
Jump to navigation Jump to search

This module contains new entry creation rules for Arabic; see WT:ACCEL for an overview, and Module:accel for information on creating new rules.


return {generate = function (params, entry)
	-- special handling for verb forms
	local verb_spec = params.form:match("^verb%-form%-(.*)$")
	if verb_spec then
		entry.override = "\n===Verb===\n{{ar-verb form|" .. verb_spec .. "}}"
		return
	end
	-- special handling for verbal nouns
	local vn_form = params.form:match("^vn%-(.*)$")
	if vn_form then
		entry.pos_header = "Noun"
		local gender
		local target = params.target
		if target:find("ة$") then
			gender = "|f"
		elseif not target:find("ا$") and not target:find("ى$") and not target:find("اء$") then
			gender = "|m"
		else
			-- FIXME: Apparently nouns in -ا or -ى or -اء can be either masculine or feminine.
			gender = ""
		end
		local tr = params.transliteration and "|tr=" .. tr or ""
		entry.head = "{{ar-noun|" .. target .. gender .. tr .. "}}"
		local origin_tr = params.origin_transliteration
		origin_tr = origin_tr and "|tr=" .. origin_tr or ""
		entry.pronunc = "* {{ar-IPA|" .. target .. "}}"
		entry.def = ("{{ar-verbal noun of|%s%s|form=%s}}"):format(params.origin, origin_tr, vn_form)
		entry.declension = "{{ar-decl-noun|" .. target .. "}}"
		return
	end
	-- special handling for active and passive participles
	local part_type, part_form = params.form:match("^([ap]p)%-(.*)$")
	if part_type then
		entry.pos_header = "Participle"
		local parts = {}
		local tr1 = params.targets[1].translit
		table.insert(parts, ("{{ar-%s-participle|%s|%s%s"):format(part_type == "ap" and "act" or "pass",
			params.targets[1].term, part_form, tr and "|tr=" .. tr or ""))
		for i = 2, #params.targets do
			local target = params.targets[i]
			table.insert(parts, ("|head%s=%s"):format(i, target.term))
			if target.translit then
				table.insert(parts, ("|tr%s=%s"):format(i, target.translit))
			end
		end
		table.insert(parts, "}}")
		entry.head = table.concat(parts)
		parts = {}
		table.insert(parts, ("{{%s participle of|ar|"):format(part_type == "ap" and "active" or "passive"))
		local origins = {}
		for _, origin in ipairs(params.origins) do
			local term = origin.term
			local tr = origin.translit
			if tr then
				table.insert(origins, ("%s<tr:%s>"):format(term, tr))
			else
				table.insert(origins, term)
			end
		end
		table.insert(parts, table.concat(origins, ","))
		table.insert(parts, "}}")
		entry.def = table.concat(parts)
		return
	end
end}