Modulus:translations
Appearance
Purpose
[+/-]This module is used for the translation templates{{t}}
and{{t+}}
.It contains a single function which is invoked by these templates. See their documentation for more information.
-- Module:translations
-- Imported from en.wiktionary
-- 2018-11-14 -- V3 -- last modified by YaganZ
-- Extended version for la.wiktionary
localm_links=require("Module:links")
localexport={}
localinterwiki_langs={
["ckb"]="ku",
["kmr"]="ku",
["lki"]="ku",
["nds-de"]="nds",
["nds-nl"]="nds",
["pdt"]="nds",
["sdh"]="ku",
}
localignore_caps={
["ko"]=true,
}
localtracked={
["se"]=true,
}
-- The main entry point.
-- This is the only function that can be invoked from a template.
functionexport.show(frame)
localparams={
[1]={required=true,default="und"},
[2]={},
[3]={list=true},
["alt"]={},
["id"]={},
["sc"]={},
["tr"]={},
["ts"]={},
["lit"]={},
}
localargs=require("Module:parameters").process(frame:getParent().args,params)
localterminfo={
lang=require("Module:languages").getByCode(args[1])orrequire("Module:languages").err(args[1],1),
sc=(args["sc"]and(require("Module:scripts").getByCode(args["sc"])orerror("The script code\ ""..args["sc"].."\ "is not valid. "))ornil),
term=args[2]or(mw.title.getCurrentTitle().nsText=="Template"and"term")ornil,
alt=args["alt"],
id=args["id"],
genders=args[3],
tr=args["tr"],
ts=args["ts"],
lit=args["lit"],
interwiki=frame.args["interwiki"],
override=frame.args["override"],
}
-- Translations must be for mainspace languages
ifterminfo.lang:getType()=="reconstructed"orterminfo.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.
ifterminfo.termthen
-- Track translations for particular languages
iftracked[terminfo.lang:getCode()]then
require("Module:debug").track("translations/"..terminfo.lang:getCode())
end
localwmlangs={}
ifinterwiki_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)
ifterminfo.term:find("[[",nil,true)or#wmlangs==0then
terminfo.interwiki=false
end
ifwmlangs[1]andignore_caps[wmlangs[1]:getCode()]then
terminfo.term2=mw.ustring.gsub(terminfo.term,"^%^","")
end
ifterminfo.interwikithen
terminfo.interwiki=
"<span class=\ ""..terminfo.interwiki.."\ "> [[: "..
wmlangs[1]:getCode()..":"..
terminfo.lang:makeEntryName(terminfo.term2orterminfo.term)..
"|("..wmlangs[1]:getCode()..")]]</span>"
end
-- Check for overriding link target.
ifterminfo.override~=""then
terminfo.alt=terminfo.term
terminfo.term=terminfo.override
end
else
-- Track what entries currently don't provide a term
require("Module:debug").track("translations/no term")
require("Module:debug").track("translations/no term/"..terminfo.lang:getCode())
end
ifterminfo.langandterminfo.lang:getCode()=='yue'andterminfo.trthen
terminfo.tr=mw.ustring.gsub(terminfo.tr,'([1-9-])','<sup>%1</sup>')
end
returnm_links.full_link(terminfo,"translation",true)
end
returnexport