Editing
Module:TNTFallback
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
-------------------------------------------------------------------------------- -- 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"); local TNT = require("Module:TNT"); local p = {}; -------------------------------------------------------------------------------- -- Based on [[Module:TNT]]'s `msg` function, -- but takes an optional `fallback` parameter. -------------------------------------------------------------------------------- function p.msg(frame) local dataset, key; local params = { n = 0 }; local lang = nil; local fallback = nil; for k, v in pairs(frame.args) do if (k == 1) then dataset = v; elseif (k == 2) then key = v; elseif (type(k) == "number" and k > 2) then local i = k - 2; params[i] = v; params.n = math.max(params.n, i); elseif ((k == "lang") and (v ~= "_")) then lang = v; elseif ((k == "fallback") and (v ~= "")) then fallback = v; end end local result; if (lang) then result = TNT.formatInLanguage(lang, dataset, key, unpack(params, 1, params.n)); else result = TNT.format(dataset, key, unpack(params, 1, params.n)); end if (fallback and ( -- not translated (result and result == TNT.formatInLanguage("en", dataset, key, unpack(params, 1, params.n))) -- no message or (not result) )) then if (not lang) then if (frame:callParserFunction("int:lang") ~= "en") then return mw.message.newRawMessage(fallback, unpack(params, 1, params.n)):plain(); end elseif (lang ~= "en") then return mw.message.newRawMessage(fallback, unpack(params, 1, params.n)):plain(); end end return result; end return p;
Summary:
Please note that all contributions to Islcamical Commons may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
commons:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:TNTFallback/doc
(
edit
)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Module
Discussion
English
Views
Read
Edit source
View history
More
Search
Navigation
Main page
welcome
Community portal
village pump
participate
Upload file
Recent changes
latestfiles
Random File
contact
Special pages
Tools
What links here
Related changes
Upload file
Page information