local m_data = mw.loadData("Module:requests/data")
local request_namespaces = m_data.request_namespaces
local Sinitic_scripts = m_data.Sinitic_scripts

local export = {}

local function subforum(lang_code, type)
	local namespace = mw.title.getCurrentTitle().namespace

	 -- RFDs of articles in nonstandard 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 not request_namespaces[namespace] then
		return "Wiktionary:Requests for " .. type .. "/Others"
	elseif namespace == "Reconstruction" then
		-- There is no 'Requests for verification/Reconstruction'; everything vectors to RFDR.
		return "Wiktionary:Requests for deletion/Reconstruction"
	end
	local lang = require("Module:languages").getByCode(lang_code, 1) -- print error if invalid code
	if lang:inFamily("gmw-ang") and not lang:inFamily("crp") and lang:getFullCode() ~= "ang" then
		return "Wiktionary:Requests for " .. type .. "/English"
	elseif lang:inFamily("jpx", "qfa-kor", "sit-sba") or Sinitic_scripts[lang:findBestScript(mw.title.getCurrentTitle().subpageText):getCode()] then
		return "Wiktionary:Requests for " .. type .. "/CJK"
	elseif lang:inFamily("itc") then
		return "Wiktionary:Requests for " .. type .. "/Italic"
	else
		return "Wiktionary:Requests for " .. type .. "/Non-English"
	end
end

function export.rfv(frame)
	return subforum(frame.args[1], "verification")
end

function export.rfd(frame)
	return subforum(frame.args[1], "deletion")
end

return export