Module:scripts/templates

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

This module provides access to Module:scripts from templates, so that they can make use of the information stored there.

Exported functions

exists

{{#invoke:scripts/templates|exists|script code}}

Check whether a script code exists and is valid. It will return "1" if the script code exists, and the empty string "" if it does not.

This is rarely needed, because a script error will result when someone uses a code that is not valid, so you do not need this just to check for errors. However, in case you need to decide different actions based on whether a certain parameter is a script code or something else, this function can be useful.

getByCode

{{#invoke:scripts/templates|getByCode|script code|item to look up|index}}

Queries information about a script code.

  • The script code should be one of the codes that is defined in Module:scripts data. If it is missing or does not exist, the result will be a script error.
  • The item is the name of one of the pieces of data that is stored for a script, such as getCanonicalName or getCategoryName. If no item has been provided, the result will be a script error.
  • The index is optional, and is used for items that are lists, such as getOtherNames. It selects which item in the list to return. On items that are single strings, like getCanonicalName, it has no effect. If no index is given, the default will be 1 (the first subitem). If an index is given that is higher than the number of items in the list, the result will be an empty string.

For example, to request the default (canonical) name of the script whose code is Latn:

{{#invoke:scripts/templates|getByCode|Latn|getCanonicalName}}
  • Result: Latin

To request its second name, if any:

{{#invoke:scripts/templates|getByCode|Latn|getOtherNames|1}}
  • Result: Roman

See also


local export = {}

function export.exists(frame)
	return require("Module:scripts").getByCode(
		require("Module:parameters").process(frame.args, {
			 = {required = true}
		})
	) and "1" or ""
end

function export.getByCode(frame)
	return require("Module:language-like").templateGetByCode(
		require("Module:parameters").process(frame.args, {
			 = {required = true, type = "script"},
			 = {required = true},
			 = {}
		}),
		function(itemname)
			if itemname == "countCharacters" then
				local text = args or ""
				return args:countCharacters(text)
			end
		end
	)
end

function export.getByCanonicalName(frame)
	local sc = require("Module:scripts").getByCanonicalName(
		require("Module:parameters").process(frame.args, {
			 = {required = true}
		})
	)
	return sc and sc:getCode() or "None"
end

return export