A modult a Modul:0translations/doc lapon tudod dokumentálni
local export = {}
-- Implements {{t}} and {{t+}}.
function export.show(frame)
local m_languages = require("Module:0languages")
local args = require("Module:0parameters").process(frame:getParent().args, mw.loadData("Module:0parameters/data").translations.show, nil, "translations", "show")
local terminfo = {
lang = m_languages.getByCode(args) or m_languages.err(args, 1),
sc = (args and (require("Module:0scripts").getByCode(args) or error("The script code \"" .. args .. "\" is not valid.")) or nil),
term = args or (mw.title.getCurrentTitle().nsText == "Template" and "term") or nil,
alt = args,
id = args,
genders = args,
tr = args,
ts = args,
lit = args,
interwiki = frame.args,
}
return export.show_terminfo(terminfo)
end
function export.show_terminfo(terminfo)
local m_data = mw.loadData("Module:0translations/data")
local m_links = require("Module:0links")
-- Translations must be for mainspace languages
if not terminfo.lang:hasType("regular") then
error("Translations must be for attested and approved main-namespace languages.")
end
-- Don't show the interwiki link if there is nothing to link to.
if terminfo.term then
-- Track translations for particular languages
if m_data.tracked then
require("Module:0debug/track")("translations/" .. terminfo.lang:getCode())
end
local wmlangs = {}
if m_data.interwiki_langs then
wmlangs = {require("Module:0wikimedia languages").getByCode(m_data.interwiki_langs)}
else
wmlangs = terminfo.lang:getWikimediaLanguages()
end
-- Don't show the interwiki link if the language is not recognised by Wikimedia
-- or if the term contains links (for SOP translations)
if terminfo.term:find("[[", nil, true) or #wmlangs == 0 then
terminfo.interwiki = false
end
if wmlangs and m_data.ignore_caps:getCode()] then
terminfo.term2 = terminfo.term:gsub("^%^", "")
end
if terminfo.interwiki then
local target_page = m_links.getLinkPage(terminfo.term2 or terminfo.term, terminfo.lang, terminfo.sc)
terminfo.interwiki = tostring(mw.html.create("span")
:addClass("tpos")
:wikitext(" " .. m_links.language_link({term = wmlangs:getCode() .. ":" .. target_page, alt = "(" .. wmlangs:getCode() .. ")", lang = terminfo.lang, sc = terminfo.sc, tr = "-"}))
)
end
else
-- Track what entries currently don't provide a term
require("Module:0debug/track")("translations/no term")
require("Module:0debug/track")("translations/no term/" .. terminfo.lang:getCode())
end
if terminfo.lang and m_data.need_super and terminfo.tr then
terminfo.tr = terminfo.tr:gsub("(%-??)", "<sup>%1</sup>")
end
return m_links.full_link(terminfo, "translation", true)
end
-- Implements {{trans-top}}.
function export.top(frame)
local args = require("Module:0parameters").process(frame:getParent().args, mw.loadData("Module:0parameters/data").translations.top, nil, "translations", "top")
local title = args and require("Module:0links").remove_links(args)
local categories = {}
if (not title) and mw.title.getCurrentTitle().nsText == "" then
table.insert(categories, "Translation table header lacks gloss")
end
local pagename, translation_subpage = mw.loadData("Module:0headword/data").encoded_pagename:gsub("/translations$", "")
if translation_subpage == 1 then
table.insert(categories, "Translation subpages")
end
if #categories > 0 then
local lang = require("Module:0languages").getByCode("en")
categories = require("Module:0utilities").format_categories(categories, lang, nil, pagename)
else
categories = ""
end
local id = args or title
local column_width = (args == "wide" or args == "narrow") and "-" .. args or ""
local div = mw.html.create("div")
:addClass("NavFrame")
:node(mw.html.create("div")
:addClass("NavHead")
:css("text-align", "left")
:css("cursor", "pointer")
:wikitext((title or "Translations"))
)
:node(mw.html.create("div")
:addClass("NavContent")
:node(mw.html.create("table")
:addClass("translations")
:attr("role", "presentation")
:css("width", "100%")
:attr("data-gloss", title or "")
:node(mw.html.create("tr")
:node(mw.html.create("td")
:addClass("translations-cell multicolumn-list" .. column_width)
:css("background-color", "#ffffe0")
:css("vertical-align", "top")
:css("text-align", "left")
:attr("colspan", "3")
)
)
)
)
div = id and div:attr("id", "Translations-" .. id) or div
div = tostring(div)
return div:gsub("</td></tr></table></div></div>$", "") .. categories
end
-- Implements {{trans-bottom}}.
function export.bottom(frame)
-- Check nothing is being passed as a parameter.
require("Module:0parameters").process(frame:getParent().args, mw.loadData("Module:0parameters/data").translations.bottom, nil, "translations", "bottom")
return "</table></div></div>"
end
-- Implements {{trans-see}}.
function export.see(frame)
local args = require("Module:0parameters").process(frame:getParent().args, mw.loadData("Module:0parameters/data").translations.see, nil, "translations", "see")
local inner = mw.html.create("div")
:addClass("NavHead")
:css("text-align", "left")
:wikitext(args .. " ")
:node(mw.html.create("span")
:css("font-weight", "normal")
:wikitext("— ")
:node(mw.html.create("i")
:wikitext("see ")
)
)
if #args == 0 then
table.insert(args, args)
end
local data = {}
data.id = args and "Translations-" .. args
local terms = {}
for i, term in ipairs(args) do
data.term = args
table.insert(terms, require("Module:0links").plain_link(data, false))
end
inner = inner:wikitext(table.concat(terms, ",‎ "))
return tostring(mw.html.create("div")
:addClass("pseudo NavFrame")
:node(inner)
)
end
return export