Modulo:script utilities

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

La documentazione per questo modulo può essere creata in Modulo:script utilities/man

local export = {}

-- Used by ]
function export.lang_t(frame)
	params = {
		 = {},
		 = { allow_empty = true, default = "" },
		 = {},
		 = {},
		 = {},
	}
	
	local args = require("Modulo:parameters").process(frame:getParent().args, params)
	local NAMESPACE = mw.title.getCurrentTitle().nsText
	
	local lang = args or (NAMESPACE == "Template" and "und") or error("Language code has not been specified. Please pass parameter 1 to the template.")
	lang = require("Modulo:languages").getByCode(lang) or require("Modulo:languages").err(lang, 1)
	
	local text = args
	
	local sc = args
	sc = (sc and (require("Modulo:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")) or nil)
	
	local face = args
	
	return export.tag_text(text, lang, sc, face, class)
end

-- Wrap text in the appropriate HTML tags with language and script class.
function export.tag_text(text, lang, sc, face, class)
	if not sc then
		sc = require("Modulo:scripts").findBestScript(text, lang)
	end

	if sc:getCode() == "Imag" then
		face = nil
	end

	local function class_attr(classes)
		table.insert(classes, 1, sc:getCode())
		if class and class ~= '' then
			table.insert(classes, class)
		end
		return 'class="' .. table.concat(classes, ' ') .. '"'
	end
	local function tag_attr(...)
		return class_attr({...}) .. ' ' .. 'lang="' .. lang:getCode() .. '"'
	end

	-- Add a script wrapper
	if face == "term" then
		return '<i ' .. tag_attr('mention') .. '>' .. text .. '</i>'
	elseif face == "head" then
		return '<strong ' .. tag_attr('headword') .. '>' .. text .. '</strong>'
	elseif face == "hypothetical" then
		return '<span class="hypothetical-star">*</span><i ' .. tag_attr('hypothetical') .. '>' .. text .. '</i>'
	elseif face == "bold" then
		return '<b ' .. tag_attr() .. '>' .. text .. '</b>'
	elseif face == nil then
		return '<span ' .. tag_attr() .. '>' .. text .. '</span>'
	else
		error("Invalid script face \"" .. face .. "\".")
	end
end

-- Add a notice to request the native script of a word
function export.request_script(lang, sc)
	local scripts = lang.getScripts and lang:getScripts() or error('The language "' .. lang:getCode() .. '" does not have the method getScripts. It may be unwritten.')
	
	-- By default, request for "native" script
	local cat_script = "native"
	local disp_script = "script"
	
	-- If the script was not specified, and the language has only one script, use that.
	if not sc and #scripts == 1 then
		sc = scripts
	end
	
	-- Is the script known?
	if sc then
		-- If the script is Latin, return nothing.
		if is_Latin_script(sc) then
			return ""
		end
		
		if sc:getCode() ~= scripts:getCode() then
			disp_script = sc:getCanonicalName()
		end
		
		-- The category needs to be specific to script only if there is chance
		-- of ambiguity. This occurs when lang=und, or when the language has
		-- multiple scripts.
		if lang:getCode() == "und" or scripts then
			cat_script = sc:getCanonicalName()
		end
	else
		-- The script is not known.
		-- Does the language have at least one non-Latin script in its list?
		local has_nonlatin = false
		
		for i, val in ipairs(scripts) do
			if not is_Latin_script(val) then
				has_nonlatin = true
				break
			end
		end
		
		-- If there are non-Latin scripts, return nothing.
		if not has_nonlatin then
			return ""
		end
	end
	
	local category = ""
	
	if mw.title.getCurrentTitle().nsText ~= "Template" then
		category = "]"
	end
	
	return "<small></small>" .. category
end

function export.template_rfscript(frame)
	local args = frame.args
	local lang = args or error("The first parameter (language code) has not been given")
	local sc = args; if sc == "" then sc = nil end
	lang = require("Modulo:languages").getByCode(lang) or error("The language code \"" .. lang .. "\" is not valid.")
	sc = (sc and (require("Modulo:scripts").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")) or nil)
	
	local ret = export.request_script(lang, sc)
	
	if ret == "" then
		error("This language is written in the Latin alphabet. It does not need a native script.")
	else
		return ret
	end
end

function is_Latin_script(sc)
	return (sc:getCode():find("Latn", nil, true)) or sc:getCode() == "Latinx"
end

return export