Documentation for this module may be created at વિભાગ:Wikidata Infobox/i18n/doc

-- On wikis that don't use the Translations namespace, replace this module
-- with something akin to [[en:Module:Wikidata_Infobox/i18n]].
local p = {}

--- Loops over fallback languages. Returns translated message if the given message
--- is available in one of these languages. Returns English message otherwise.
--- @param msgKey "editlink-alttext"|"newitem"|"noid"|"search-depicted"|"taxon-depicted"|"search"|"noclaims"
--- @param fallbacklangs string[]: list of language codes
--- @return string message, string msgLang
function p.i18n( msgKey, fallbacklangs )
	local titlebase = 'Translations:Template:Wikidata Infobox/i18n/msg-'..msgKey..'/'

	local msgLang = 'en'
	for _, lang in ipairs( fallbacklangs ) do
		if mw.title.new( titlebase..lang ).exists then
			msgLang = lang
			break
		end
	end

	local message = mw.getCurrentFrame():expandTemplate{ title = titlebase..msgLang }
	return message, msgLang
end

return p