မေႃႇၵျူး:request-forum

လုၵ်ႉတီႈ ဝိၵ်ႇသျိၼ်ႇၼရီႇ မႃး

Documentation for this module may be created at မေႃႇၵျူး:request-forum/doc

local export = {}

export.SiniticScripts = {
	["Bopo"] = true, -- Zhuyin
	["Hani"] = true, -- Han
	["Hans"] = true, -- Han (simplified)
	["Hant"] = true, -- Han (traditional)
	["Jpan"] = true, -- Japanese (general)
	["Hira"] = true, -- Hiragana
	["Kana"] = true, -- Katakana
	["Kore"] = true, -- Korean (general)
	["Hang"] = true, -- Hangul
	["Jurc"] = true, -- Jurchen
	["Kitl"] = true, -- Khitan large script
	["Kits"] = true, -- Khitan small script
	["Nshu"] = true, -- Nüshu
	["Shui"] = true, -- Sui
	["Tang"] = true, -- Tangut
}

-- Languages (sometimes) written with other scripts, which should always use the CJK page regardless.
export.additionalCJK = {
	["bca"] = true, -- Central Bai
	["bfc"] = true, -- Northern Bai
	["bfs"] = true, -- Southern Bai
	["cmn"] = true, -- Mandarin
	["dng"] = true, -- Dungan
	["ja"] = true, -- Japanese
	["jpx-pro"] = true, -- Proto-Japonic
	["ko"] = true, -- Korean
	["lay"] = true, -- Lama Bai
	["ltc"] = true, -- Middle Chinese
	["nan"] = true, -- Min Nan
	["qfa-kor-pro"] = true, -- Proto-Koreanic
	["yue"] = true, -- Cantonese
	["zh"] = true, -- Chinese
}

local function family_is_italic(family)
	while true do
		if not family then
			return false
		end
		local code = family:getCode()
		if code == "itc" then
			return true
		elseif code == "qfa-not" then -- careful, qfa-not is its own parent
			return false
		else
			family = family:getFamily()
		end
	end
end

local function lang_is_italic(lang)
	-- First convert to non-etymological.
	lang = require("Module:languages").getNonEtymological(lang)
	if not lang then
		return nil
	end
	local typ = lang:getType()
	if typ == "etymology language" then
		-- This shouldn't happen.
		return false
	elseif typ == "family" then
		-- Some etymology languages have families as their nearest non-etymological ancestor.
		return family_is_italic(lang)
	elseif lang:getCode() == "itc-pro" then
		return true
	else
		-- Some languages (e.g. some Creoles) have multiple ancestors; check them all.
		local ancestors = lang:getAncestors()
		for _, ancestor in ipairs(ancestors) do
			if family_is_italic(ancestor:getFamily()) then
				return true
			end
		end
		return false
	end
end	
	
local function subforum(frame, type)
	local lang_code = frame.args[1]
	local lang
	local namespace = frame.args[2]

	 -- RFDs of articles in "abnormal" namespaces go straight to [[WT:RFDO]] without having their language code checked.
	 -- This branch is only used by [[Template:rfd]] because the other RFD templates ([[Template:rfd-sense]], [[Template:rfd-redundant]]) semantically presuppose the target to be a lingual element.
	if type == "deletion" and namespace ~= nil and namespace ~= "" and namespace ~= "Citations" and namespace ~= "Reconstruction" and namespace ~= "Transwiki" then
		return "Wiktionary:Requests for " .. type .. "/Others"
	else
		lang = require("Module:languages").getByCode(lang_code, true) -- print error if invalid code
	end
	if namespace == "Reconstruction" then
		-- There is no 'Requests for verification/Reconstruction'; everything vectors to RFDR.
		return "Wiktionary:Requests for deletion/Reconstruction"
	elseif lang_code == "en" then
		return "Wiktionary:Requests for " .. type .. "/English"
	elseif export.additionalCJK[lang_code] or export.SiniticScripts[lang:findBestScript(frame:getParent():preprocess("{{FULLPAGENAME}}")):getCode()] then
		return "Wiktionary:Requests for " .. type .. "/CJK"
	elseif lang_is_italic(lang) then
		return "Wiktionary:Requests for " .. type .. "/Italic"
	else
		return "Wiktionary:Requests for " .. type .. "/Non-English"
	end
end

function export.rfv(frame)
	return subforum(frame, "verification")
end

function export.rfd(frame)
	return subforum(frame, "deletion")
end

return export