Module:TNTTools

local p = {}

local TNT = require('Module:TNT') local SA = require('Module:SimpleArgs')

function TNTTabFull (TNTTab) if (string.sub(TNTTab, 1, 5)) ~= 'I18n/' then TNTTab = 'I18n/'..TNTTab end if (string.sub(TNTTab, string.len(TNTTab)-3)) ~= '.tab' then TNTTab = TNTTab..'.tab' end return TNTTab end --TNTTabFull

function p.GetTabTrans (TNTTab, S, CaseSensitive) CaseSensitive = ((CaseSensitive ~= nil) and (CaseSensitive == true)) or true local Wds = TNT.format (TNTTabFull(TNTTab), S)	if not CaseSensitive then Wds = string.lower (Wds) end return mw.text.split (Wds, '|') end --GetTabTrans

function p.GetSTransWithParams (TNTTab, S, ...) return TNT.format (TNTTabFull(TNTTab), S, {...}) or '' end

function p.GetTabOr1Trans (TNTTab, S, MaxTrans) local Trans = p.GetTabTrans (TNTTab, S)	if WithTrans then tab = mw.text.split (Trans, '|') if #tab > MaxTrans then error (string.format('Found %s translations for "%s". Search in commons:data:%s.tab',#tab,S,TNTTab), 0) -- Translation not required end return tab else return Trans end end --GetTabOr1Trans

function p.SFoundInTNTArr (TNTTab, val, CaseSensitive, S)	if (S == nil) or (S == '') then error('Not arguments trying to find "'..val..'"') --It doesn't require translation, only for degug end local Arr = p.GetTabTrans (TNTTab, S, CaseSensitive) if not CaseSensitive then val = string.lower (val) end for I, W in ipairs(Arr) do		if W == val then return true end end return false end --SFoundInTNTArr

function p.IdxFromTabTrans (TNTTab, val, CaseSensitive, ...) local Arr = unpack(arg) if Arr == nil then error('Not arguments trying to find "'..val..'"') --It doesn't require translation, only for degug end local Idx = 0 for I, W in ipairs(Arr) do		if p.SFoundInTNTArr (TNTTab, val, CaseSensitive, W) then Idx = I			break end end return Idx end	--IdxFromTabTrans

function p.Str (frame) local args, NArgs = SA.GetArgs (frame) local tab = SA.GetStrArgsFromPos (args, NArgs, 3) return TNT.format (TNTTabFull(args[1]), args[2], unpack(tab)) end --Str

function p.FoundStrBool (frame) local args = SA.GetArgs (frame) return p.SFoundInTNTArr (args[1], args[2], SA.GetBoolFromArgs (args,3), args[4]) end function p.FoundStrNum (frame) local args = SA.GetArgs (frame) if p.SFoundInTNTArr (args[1], args[2], SA.GetBoolFromArgs (args,3), args[4]) then return 1 else return 0 end end --FoundStrNum function p.FoundIdx (frame) local args, NArgs = SA.GetArgs (frame) local tab = SA.GetStrArgsFromPos (args, NArgs, 4) return p.IdxFromTabTrans (args[1], args[2], SA.GetBoolFromArgs (args,3), tab) end --FoundIdx return p