Difference between revisions 18626593 and 18626594 on frwiktionary

local export = {}

-- Detect the script based on the characters of a string
function export.detect_script(text, lang)
	local scripts = lang:getScripts()
	
	-- Try to match every script against the text,
	-- and return the one with the most matching characters.
	local bestcount = 0
	local bestscript = nil
	
	for i, script in ipairs(scripts) do
		local count = script:countCharacters(text)
		
		if count > bestcount then
			bestcount = count
			bestscript = script
		end
	end
	
	if bestscript then
		-- TODO: return the object itself, not the code
		return bestscript:getCode()
	end
	
	-- No matching script was found. Return "None".
	return "None" --require("Module:scripts").getScriptByCode("None"require("Module:debug").track("detect_script")
	return require("Module:scripts").findBestScript(text, lang):getcode()
end

-- Format the categories with the appropriate sort key
function export.format_categories(categories, lang, sort_key, sort_base)
	NAMESPACE = NAMESPACE or mw.title.getCurrentTitle().nsText
	
	if NAMESPACE == "" or NAMESPACE == "Appendix" then
(contracted; show full)		i = i + 1
		cat = args[i]
	end
	
	return export.format_categories(categories, lang, sort_key)
end

return export