Modulus:translations2
Documentation for this module may be created at Modulus:translations2/doc
-- Module:translations
-- Imported from en.wiktionary
-- 2016-06-04 -- V2 -- last modified by YaganZ
-- Extended version for la.wiktionary
local m_links = require("Module:links")
local export = {}
local interwiki_langs = {
["nds-de"] = "nds",
["nds-nl"] = "nds",
["pdt"] = "nds",
}
-- The main entry point.
-- This is the only function that can be invoked from a template.
function export.show(frame)
local params = {
[1] = {required = true, default = "und"},
[2] = {},
[3] = {list = true},
["alt"] = {},
["sc"] = {},
["tr"] = {},
}
local args = require("Module:parameters").process(frame:getParent().args, params)
local terminfo = {
lang = require("Module:languages").getByCode(args[1]) or error("The language code \"" .. args[1] .. "\" is not valid."),
sc = (args["sc"] and (require("Module:scripts").getByCode(args["sc"]) or error("The script code \"" .. args["sc"] .. "\" is not valid.")) or nil),
term = args[2] or (mw.title.getCurrentTitle().nsText == "Template" and "term") or nil,
alt = args["alt"],
genders = args[3],
tr = args["tr"],
interwiki = frame.args["interwiki"],
override = frame.args["override"],
}
-- Translations must be for mainspace languages
if terminfo.lang:getType() == "reconstructed" or terminfo.lang:getType() == "appendix-constructed" 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.
-- Check for overriding link target.
if terminfo.term then
local wmlangs = {}
if interwiki_langs[terminfo.lang:getCode()] then
wmlangs = {require("Module:wikimedia languages").getByCode(interwiki_langs[terminfo.lang:getCode()])}
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 terminfo.interwiki then
terminfo.interwiki =
"<span class=\"" .. terminfo.interwiki .. "\"> [[:" ..
wmlangs[1]:getCode() .. ":" ..
terminfo.lang:makeEntryName(terminfo.term) ..
"|(" .. wmlangs[1]:getCode() .. ")]]</span>"
end
if terminfo.override ~= "" then
terminfo.alt = terminfo.term
terminfo.term = terminfo.override
end
end
if terminfo.lang and terminfo.lang:getCode() == 'yue' and terminfo.tr then
terminfo.tr = mw.ustring.gsub(terminfo.tr, '([1-9])','<sup>%1</sup>')
terminfo.tr = mw.ustring.gsub(terminfo.tr, '[-*]','⁻')
end
return m_links.full_link(terminfo, nil, true)
end
return export