વિભાગ:શબ્દોત્પત્તિ ભાષા
This module provides the functionality of the template {{વ્યુત્પત્તિ}}
. It has a separate data module, Module:શબ્દોત્પત્તિ ભાષા/આંકડા, which stores information for etymology-only language codes.
local export = {}
function export.show(frame)
local args = frame:getParent().args
NAMESPACE = mw.title.getCurrentTitle().nsText
local source = args[1] or (NAMESPACE == "ઢાંચો" and "અનિર્ધારિત") or error("Parameter 1 (source language/family code) has not been specified.")
local lang = args[2]; if lang == "" then lang = nil end
local sort_key = args["ક્રમ"]; if sort_key == "" then sort_key = nil end
-- Empty language means Gujarati, but "-" means no language. Yes, confusing...
if not lang then
lang = "gu"
elseif lang == "-" then
lang = nil
end
if lang then
lang = require("Module:ભાષાઓ").getLanguageByCode(lang) or error("ભાષા સંકેત \"" .. lang .. "\" યોગ્ય નથી।")
end
return format(source, lang, sort_key)
end
function format(source, lang, sort_key)
local info = get_info(source)
-- Add the categories, but only if there is a current language
local categories = ""
if lang then
local m_utilities = require("Module:ઉપયોગીતા")
categories = {}
if lang:getCode() == source then
categories = m_utilities.format_categories({lang:getCanonicalName() .. " બે વાર લીધા શબ્દો"}, lang, sort_key)
else
categories = m_utilities.format_categories({info.cat_name .. "\ વ્યુત્પત્તિ ધરાવતા " .. lang:getCanonicalName() .. " \ શબ્દો"}, lang, sort_key)
end
end
return "<span class=\"વ્યુત્પત્તિ\">" .. info.display .. categories .. "</span>"
end
function get_info(source)
-- What type of code is the source?
if source == "અનિર્ધારિત" then
return {
display = "અનિર્ધારિત",
cat_name = "બીજી ભાષાઓ"}
end
-- Is it a normal language code?
local source_info = require("Module:ભાષાઓ").getLanguageByCode(source)
if source_info then
return {
display = "[[w:" .. source_info:getCategoryName() .. "|" .. source_info:getCanonicalName() .. "]]",
cat_name = source_info:getCanonicalName()}
end
-- Is it a family code?
source_info = require("Module:પરિવારો").getFamilyByCode(source)
if source_info then
return {
display = "[[w:" .. source_info:getCategoryName() .. "|" .. source_info:getCanonicalName() .. "]]",
cat_name = source_info:getCategoryName()}
end
-- Is it an etymology-only code?
source_info = mw.loadData("Module:શબ્દોત્પત્તિ ભાષા/આંકડા")[source]
if source_info then
return {
display = "[[w:" .. (source_info.wikipedia_article or source_info.names[1]) .. "|" .. source_info.names[1] .. "]]",
cat_name = source_info.names[1]}
end
-- Code doesn't exist; show an error
error("સ્રોત ભાષા/પરિવાર સંકેત \"" .. source .. "\" યોગ્ય નથી।.")
end
-- Look up an item from the table of language data, and return it.
-- This function allows templates to access this data.
-- Returns an empty string if the item does not exist.
function export.lookup_etym_language(frame)
local languages = mw.loadData("Module:શબ્દોત્પત્તિ ભાષા/આંકડા")
local args = frame.args
local lang = args[1] or error("Language code has not been specified. Please pass parameter 1 to the module invocation.")
local langinfo = languages[lang] or error("ભાષા સંકેત \"" .. lang .. "\" યોગ્ય નથી।")
-- The item that the caller wanted to look up
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 item = langinfo[itemname] or ""
if type(item) == "table" then
return item[tonumber(args[3] or 1)] or ""
else
return item or ""
end
end
function export.etym_language_exists(frame)
local languages = mw.loadData("Module:શબ્દોત્પત્તિ ભાષા/આંકડા")
local args = frame.args
local lang = args[1] or error("Language code has not been specified. Please pass parameter 1 to the module invocation.")
if languages[lang] then
return "૧"
else
return ""
end
end
return export