وحدة:alternative forms
يمكن إنشاء صفحة توثيق الوحدة في وحدة:alternative forms/شرح
local export = {}
local m_link = require('Module:links')
local m_languages = require("Module:languages")
function export.create(frame)
NAMESPACE = mw.title.getCurrentTitle().nsText
local args = frame:getParent().args
local lang = args[1] or (NAMESPACE == "Template" and "und") or error("The first parameter (language code) is missing.")
local sc = args["sc"]; if sc == "" then sc = nil end
sc = sc and require("Module:scripts").getByCode(sc)
lang = m_languages.getByCode(lang) or error("The language code \"" .. lang .. "\" is not valid.")
local terms = {}
local pNumber = 2
local pValue = ''
while true do
pValue = args[pNumber]
if not pValue or pValue == '' then
pNumber = pNumber + 1
break
else
table.insert(terms, pValue)
pNumber = pNumber + 1
end
end
local links = {}
local term
for i=1, #terms do
term = terms[i]
table.insert(links, m_link.full_link(term, nil, lang, sc, nil, nil, {}, false))
end
local dialect_page = 'Module:'.. lang:getCode() ..':Dialects'
if mw.title.new(dialect_page).exists then
dialect_info = require(dialect_page)
else
dialect_info = false
end
local dialects = {}
local which_arg = ''
local current_dialect = ''
local current_info = {}
local dialect_display = ''
local dialect_link = ''
local dialect_final = ''
local addDialect = function(dialect)
if dialect_info and dialect_info.data[dialect] then
current_info = dialect_info.data[dialect]
dialect_link = current_info.link
dialect_display = current_info.display or dialect
if dialect_link then
dialect = '[[w:'..dialect_link..'|'..dialect_display..']]'
else
dialect = dialect_display
end
end
table.insert(dialects, dialect)
end
while true do
pValue = args[pNumber]
if not pValue or pValue == '' then
break
else
addDialect(pValue)
end
pNumber = pNumber + 1
end
if args['dial'] then
addDialect(args['dial'])
end
if args['dial1'] then
addDialect(args['dial1'])
end
pNumber = 2
while true do
which_arg = 'dial' .. pNumber
if not args[which_arg] or args[which_arg] == '' then
break
else
addDialect(args[which_arg])
end
pNumber = pNumber + 1
end
local final = ''
if #dialects > 0 then
final = table.concat(links, ', ').." ''"..table.concat(dialects, ", ").."''"
else
final = table.concat(links, ', ')
end
return final
end
return export