વિભાગ:ભાષાઓ/ઢાંચાઓ
This module provides access to Module:ભાષાઓ from templates, so that they can make use of the information stored there.
Exported functions
[ફેરફાર કરો]exists
[ફેરફાર કરો]{{#invoke:ભાષાઓ/ઢાંચાઓ|exists|(ભાષા સંકેત)}}
Check whether a language code exists and is valid. It will return "1" if the language 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 language code or something else, this function can be useful.
getByCode
[ફેરફાર કરો]{{#invoke:ભાષાઓ/ઢાંચાઓ|getByCode|(ભાષા સંકેત)|(item to look up)|(index)}}
Queries information about a language code.
- The language code should be one of the codes that is defined in Module:ભાષાઓ 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 functions of a language object, such as
getCanonicalName
orgetScripts
. 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
getAllNames
orgetScripts
. It selects which item in the list to return. On items that are single strings, likegetFamily
, it has no effect. 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 language whose code is en
:
{{#invoke:ભાષાઓ/ઢાંચાઓ|getByCode|en|સહુનામમળ}}
- Result:
અંગ્રેજી
To request its second name, if any:
{{#invoke:ભાષાઓ/ઢાંચાઓ|getByCode|en|સહુનામમળ|2}}
- Result:
To request its family:
{{#invoke:ભાષાઓ/ઢાંચાઓ|getByCode|en|પરિવાર}}
- Result:
Lua error in વિભાગ:ભાષાઓ at line 37: attempt to call field 'getByCode' (a nil value).
See also
[ફેરફાર કરો]- Module:JSON આંકડા — for exporting all the data at once
local export = {}
function export.exists(frame)
local args = frame.args
local lang = args[1] or error("Language code has not been specified. Please pass parameter 1 to the module invocation.")
lang = require("Module:ભાષાઓ").getByCode(lang)
if lang then
return "1"
else
return ""
end
end
-- Used by the following JS:
-- * [[WT:ACCEL]]
-- * [[WT:EDIT]]
-- * [[WT:NEC]]
function export.getByCode(frame)
local args = frame.args
local langcode = args[1] or error("Language code has not been specified. Please pass parameter 1 to the module invocation.")
local itemname = args[2] or error("Type of information to look up has not been specified. Please pass parameter 2 to the module invocation.")
local lang = require("Module:ભાષાઓ").getByCode(langcode)
if not lang then
error("The language code '" .. langcode .. "' is not valid.")
end
-- The item that the caller wanted to look up
if itemname == "સહુનામમળ" then
local index = args[3]; if index == "" then index = nil end
index = tonumber(index or error("Please specify the numeric index of the desired name."))
return lang:getAllNames()[index] or ""
elseif itemname == "પરિવારમળ" or itemname == "પરિવાર" then
if itemname == "પરિવાર" then
frame:expandTemplate{title = 'User:CodeCat/getFamily tracking', args = {} }
end
return lang:getFamily():getCode()
elseif itemname == "લિપિમળ" or itemname == "લિપિ" then
if itemname == "લિપિ" then
frame:expandTemplate{title = 'User:CodeCat/scriptsN tracking', args = {} }
end
local index = args[3]; if index == "" then index = nil end
index = tonumber(index or error("Please specify the numeric index of the desired script."))
local scripts = lang:getScripts()
if scripts[index] then
return scripts[index]:getCode()
else
return ""
end
elseif itemname == "લિપ્યંતરણ" then
local text = args[3]; if text == "" then text = nil end
local sc = args[4]; if sc == "" then sc = nil end
sc = (sc and (require("Module:લિપિઓ").getByCode(sc) or error("The script code \"" .. sc .. "\" is not valid.")) or nil)
return lang:transliterate(text, sc) or ""
elseif lang[itemname] then
local ret = lang[itemname](lang)
if type(ret) == "string" then
return ret
else
error("The function \"" .. itemname .. "\" did not return a string value.")
end
else
error("Requested invalid item name \"" .. itemname .. "\".")
end
end
function export.getByCanonicalName(frame)
local args = frame.args
local langname = args[1] or error("Language name has not been specified. Please pass parameter 1 to the module invocation.")
local lang = require("Module:ભાષાઓ").getByCanonicalName(langname)
if lang then
return lang:getCode()
else
return ""
end
end
return export