More actions
Module:Vrix/doc
A V'rix universal translator for the wiki!
This module implements the templates {{vencode}}, {{vdecode}}, {{vlencode}}, {{vldecode}}, {{vrencode}}, {{vrdecode}}, and {{verror}}.
Pages Using This
Through the above macros this module is used in a large number of pages across the wiki, i.e. any page where sectors, npcs, missions, or items which may be in V'rix appear.
- {{Item}}
- {{Item/AmmoRow}}
- {{Item/DropRow}}
- {{MissionDesc}}
- {{NPC infobox}}
- {{StationInfoBox}}
Usage
These functions should generally be used via the shortcut templates listed above, the examples below show the direct module calls.
Normal Encode/Decode
The normal encode and decode functions always link to Category:V'rix.
Acts like a "spoiler" tag and does not show the translation unless you hover over it, the original message specified is what is shown. This is the default behavior if spoiler is not specified.
{{#invoke:Vrix|encode|message=Servants of the Ancients}}
producesServants of the Ancients
{{#invoke:Vrix|encode|message=Servants of the Ancients|spoiler=yes}}
producesServants of the Ancients
{{#invoke:Vrix|decode|message=S2RV1NTS4FTH21NC32NTS}}
producesS2RV1NTS4FTH21NC32NTS
{{#invoke:Vrix|decode|message=S2RV1NTS4FTH21NC32NTS|spoiler=yes}}
producesS2RV1NTS4FTH21NC32NTS
spoiler=no, Translation is NOT a spoiler, so show it
Translation is shown, with original text in the tooltip.
{{#invoke:Vrix|encode|message=Servants of the Ancients|spoiler=no}}
producesS2RV1NTS4FTH21NC32NTS
{{#invoke:Vrix|decode|message=S2RV1NTS4FTH21NC32NTS|spoiler=no}}
producesSERVANTSOFTHEANCIENTS
Link Encode/Decode
The link encode/decode functions always link to the V'rix text (so in the encode case, they link to the result of the encoding, and in the decode case they link to the message specified).
Acts like a "spoiler" tag and does not show the translation unless you hover over it, the original message specified is what is shown. This is the default behavior if spoiler is not specified.
{{#invoke:Vrix|link_encode|message=Amah's Anger}}
producesAmah's Anger
{{#invoke:Vrix|link_encode|message=Amah's Anger|spoiler=yes}}
producesAmah's Anger
{{#invoke:Vrix|link_decode|message=1M1HSW3LL}}
produces1M1HSW3LL
{{#invoke:Vrix|link_decode|message=1M1HSW3LL|spoiler=yes}}
produces1M1HSW3LL
spoiler=no, Translation is NOT a spoiler, so show it
{{#invoke:Vrix|link_encode|message=Amah's Anger|spoiler=no}}
produces1M1HS1NG2R
{{#invoke:Vrix|link_decode|message=1M1HSW3LL|spoiler=no}}
producesAMAHSWILL
Raw Encode/Decode
{{#invoke:Vrix|raw_encode|message=Scan for the Vishao Codex... negative.}}
producesSC1NF4RTH2V3SH14C4D2XN2G1T3V2
{{#invoke:Vrix|raw_decode|message=SC1NF4RTH2V3SH14C4D2XN2G1T3V2}}
producesSCANFORTHEVISHAOCODEXNEGATIVE
Error
{{#invoke:Vrix|error|message=invalid sector name}}
produces3NV1L3DS2CT4RN1M2
The above doc is transcluded from Module:Vrix/doc. (edit | history)
Add categories to the /doc subpage, not here. Subpages of this template.
local getArgs
local yesno = require('Module:Yesno')
require('strict')
--------------------------------------------------------------------------------
-- Helper functions
--------------------------------------------------------------------------------
local function _args(frame)
if not getArgs then
getArgs = require('Module:Arguments').getArgs
end
local args = getArgs(frame, {
trim = true,
removeBlanks = true,
wrappers = {
'Template:Vencode',
'Template:Vdecode',
'Template:Vlencode',
'Template:Vldecode',
'Template:Vrencode',
'Template:Vrdecode',
'Template:Verror',
},
parentOnly = true
})
-- default spoiler to true
if args.spoiler == nil then
args.spoiler = true
end
return args
end
local function _codec(args, src, dst)
return (tostring(args.message or args[1] or error('no message specified', 2))
:upper()
:gsub("[^%u%d]", "")
:gsub(src, function(x) return dst:sub(src:find(x)) end))
end
local function _tooltip(title, category, wikitext, link, isError)
local span_html = mw.html.create('span')
:addClass('rt-commentedText')
:addClass('tooltip')
:addClass('tooltip-dotted')
:css('font-weight', 'bold')
:attr('title', title)
:wikitext(wikitext)
if isError then
span_html:addClass('error')
end
local span = tostring(span_html)
local link_wikitext = "[[" .. link .. "|" .. span .. "]][[" .. category .. "]]"
return tostring(mw.html.create()
:wikitext(link_wikitext)
)
end
--------------------------------------------------------------------------------
-- Vrix class definition
--------------------------------------------------------------------------------
local Vrix = {}
Vrix.__index = Vrix
Vrix.VRIX="([123456])"
Vrix.ENGLISH="([AEIOUY])"
function Vrix.encode(args)
local emessage = tostring(args.message or args[1] or error('no message specified', 2))
local category = "Category:V'rix"
local vmessage = _codec(args, Vrix.ENGLISH, Vrix.VRIX)
local link = ":" .. category
if yesno(args.spoiler) then
return _tooltip(vmessage, category, emessage, link, nil)
else
return _tooltip(emessage, category, vmessage, link, nil)
end
end
function Vrix.decode(args)
local vmessage = tostring(args.message or args[1] or error('no message specified', 2))
local category = "Category:V'rix"
local emessage = _codec(args, Vrix.VRIX, Vrix.ENGLISH)
local link = ":" .. category
if yesno(args.spoiler) then
return _tooltip(emessage, category, vmessage, link, nil)
else
return _tooltip(vmessage, category, emessage, link, nil)
end
end
function Vrix.link_encode(args)
local emessage = tostring(args.message or args[1] or error('no message specified', 2))
local category = "Category:V'rix"
local vmessage = _codec(args, Vrix.ENGLISH, Vrix.VRIX)
if yesno(args.spoiler) then
return _tooltip(vmessage, category, emessage, vmessage, nil)
else
return _tooltip(emessage, category, vmessage, vmessage, nil)
end
end
function Vrix.link_decode(args)
local vmessage = tostring(args.message or args[1] or error('no message specified', 2))
local category = "Category:V'rix"
local emessage = _codec(args, Vrix.VRIX, Vrix.ENGLISH)
if yesno(args.spoiler) then
return _tooltip(emessage, category, vmessage, vmessage, nil)
else
return _tooltip(vmessage, category, emessage, vmessage, nil)
end
end
function Vrix.raw_encode(args)
return _codec(args, Vrix.ENGLISH, Vrix.VRIX)
end
function Vrix.raw_decode(args)
return _codec(args, Vrix.VRIX, Vrix.ENGLISH)
end
function Vrix.error(args)
local emessage = tostring(args.message or args[1] or error('no message specified', 2))
local category = "Category:Meta/Page with " .. emessage
local vmessage = _codec(args, Vrix.ENGLISH, Vrix.VRIX)
local link = ":" .. category
return _tooltip(emessage, category, vmessage, link, true)
end
--------------------------------------------------------------------------------
-- Exports
--------------------------------------------------------------------------------
local p, mt = {}, {}
function p._exportClasses()
-- For testing.
return {
Vrix = Vrix
}
end
function p.main(k, args)
if k:find("link_encode") then
return Vrix.link_encode(args)
end
if k:find("link_decode") then
return Vrix.link_decode(args)
end
if k:find("raw_encode") then
return Vrix.raw_encode(args)
end
if k:find("raw_decode") then
return Vrix.raw_decode(args)
end
if k:find("encode") then
return Vrix.encode(args)
end
if k:find("decode") then
return Vrix.decode(args)
end
if k:find("error") then
return Vrix.error(args)
end
return error("unknown function: "..k, 2)
end
function mt.__index(t, k)
return function (frame)
return t.main(k, _args(frame))
end
end
return setmetatable(p, mt)