Difference between revisions 18626591 and 18626592 on frwiktionary

local export = {}

-- Detect the script based on the first alphabetical characters of a string
function export.detect_script(text, lang)
	local m_scripts = mw.loadData("Module:scripts/tempdata")
	local scripts = mw.loadData("Module:languages/alldata")[lang:getCode()].scripts
	local scFix = false
	
(contracted; show full)
-- Used by {{categorize}}
function export.template_categorize(frame)
	NAMESPACE = NAMESPACE or mw.title.getCurrentTitle().nsText
	local format = frame.args["format"]
	local args = frame:getParent().args
	
	local lang
code = args[1]; if langcode == "" then langcode = nil end
	local sort_key = args["sort"]; if sort_key == "" then sort_key = nil end
	local categories = {}
	
	if not langcode then
		if NAMESPACE == "Template" then
			lang = "u return "" end"
		else
			error("Language code has not been specified. Please pass parameter 1 to the template.")
		end
	end
	
	local lang = require("Module:languages").getLanguageByCode(lang)code)
	
	if not lang then
		if NAMESPACE == "Template" then return "" end
		error("The language code \"" .. langcode .. "\" is not valid.")
	end
	
	local prefix = ""
	
	if format == "pos" then
		prefix = lang:getCanonicalName() .. " "
	elseif format == "topic" then
		prefix = lang:getCode() .. ":"
	end
	
	local i = 2
	local cat = args[i]
	
	while cat do
		if cat ~= "" then
			table.insert(categories, prefix .. cat)
		end
		
		i = i + 1
		cat = args[i]
	end
	
	return export.format_categories(categories, lang, sort_key)
end

return export