Module:User:Victar/term cognates

Hello, you have come here looking for the meaning of the word Module:User:Victar/term cognates. In DICTIOUS you will not only get to know all the dictionary meanings for the word Module:User:Victar/term cognates, but we will also tell you about its etymology, its characteristics and you will know how to say Module:User:Victar/term cognates in singular and plural. Everything you need to know about the word Module:User:Victar/term cognates you have here. The definition of the word Module:User:Victar/term cognates will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofModule:User:Victar/term cognates, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.


local export = {}

function export.getCognates(lang, term)
	local page = mw.title.new(require("Module:links").getLinkPage(term, lang))
	local content = page:getContent()
	
	if not content then
		return ""
	end
	
	local _, index = mw.ustring.find(content, "\n==" .. lang:getCanonicalName() .. "==", nil, true)
	if not index then
		_, index = mw.ustring.find(content, "^==" .. require("Module:utilities").pattern_escape(lang:getCanonicalName()) .. "==", nil, false)
	end
	if not index then
		error("Language not found: " .. lang:getCanonicalName() .. ".")
	end
	_, next_lang = mw.ustring.find(content, "\n==+==", index, false)
	_, index = mw.ustring.find(content, "\n(====?)Descendants%1", index, false)
	if (not index) or (next_lang and next_lang < index) then
		error("Cognates not found")
	end
		
	local cognates = mw.ustring.match(content, "^\*\s*\{{\w*\|(\w*\|\w*).*")
	
	cognates = mw.getCurrentFrame():preprocess(cognates)
	
	cognates = mw.text.trim(cognates)
	
	return cognates
	
end

return export