Jump to content

Module:TNTFallback

From Wikimedia Commons, the free media repository
Lua

CodeDiscussionEditHistoryLinksLink countSubpages:DocumentationTestsResultsSandboxLive codeAll modules


Usage

{{#invoke:TNTFallback|function_name}}

Code

---------------------------------------------------------------------------------- This module implements a wrapper for [[Module:TNT]] that allows returning-- a fallback message; used by {{Documentation}}.---- @module TNTFallback-- @alias p-- @author [[User:ExE Boss]]-- @require [[Module:TNT]]--------------------------------------------------------------------------------require("strict");localTNT=require("Module:TNT");localp={};---------------------------------------------------------------------------------- Based on [[Module:TNT]]'s `msg` function,-- but takes an optional `fallback` parameter.--------------------------------------------------------------------------------functionp.msg(frame)localdataset,key;localparams={n=0};locallang=nil;localfallback=nil;fork,vinpairs(frame.args)doif(k==1)thendataset=v;elseif(k==2)thenkey=v;elseif(type(k)=="number"andk>2)thenlocali=k-2;params[i]=v;params.n=math.max(params.n,i);elseif((k=="lang")and(v~="_"))thenlang=v;elseif((k=="fallback")and(v~=""))thenfallback=v;endendlocalresult;if(lang)thenresult=TNT.formatInLanguage(lang,dataset,key,unpack(params,1,params.n));elseresult=TNT.format(dataset,key,unpack(params,1,params.n));endif(fallbackand(-- not translated(resultandresult==TNT.formatInLanguage("en",dataset,key,unpack(params,1,params.n)))-- no messageor(notresult)))thenif(notlang)thenif(frame:callParserFunction("int:lang")~="en")thenreturnmw.message.newRawMessage(fallback,unpack(params,1,params.n)):plain();endelseif(lang~="en")thenreturnmw.message.newRawMessage(fallback,unpack(params,1,params.n)):plain();endendreturnresult;endreturnp;
close