changeset 57:0d2967941745

localization internals message prefix is forced to string before used on table lookups
author Nenue
date Fri, 08 Jan 2016 10:15:09 -0500
parents 4b1b301cf8d4
children 0a9a6740ea5d
files Devian.lua Devian.toc Locale.lua
diffstat 3 files changed, 42 insertions(+), 67 deletions(-) [+]
line wrap: on
line diff
--- a/Devian.lua	Wed Jan 06 11:46:24 2016 -0500
+++ b/Devian.lua	Fri Jan 08 10:15:09 2016 -0500
@@ -5,18 +5,19 @@
 if not LibStub then
   print('Something has happened...')
 end
+local MAJOR, MINOR = 'Devian-2.0', 'r@project-revision@'
 Devian = LibStub("AceAddon-3.0"):NewAddon("Devian", "AceConsole-3.0", "AceEvent-3.0")
 local D = _G.Devian
 D:SetDefaultModuleState(false)
-
+D.L = {}
+setmetatable(D.L, {__index= function(t,k) return k end, __call = function(t,k,...) return string.format((t[k] or k) , ...) end})
+local L = D.L
 local pairs, tostring, tonumber, ipairs, type = pairs, tostring, tonumber, ipairs, type
 local max, rand, format = math.max, math.random, string.format
 local insert, wipe, concat = table.insert, table.wipe, table.concat
 local select, unpack = select, unpack
 local GetNumAddOns, GetAddOnInfo, GetAddOnEnableState, EnableAddOn = GetNumAddOns, GetAddOnInfo, GetAddOnEnableState, EnableAddOn
 local UnitName, DisableAddOn = UnitName, DisableAddOn
-local MAJOR, MINOR = 'Devian-2.0', 'r@project-revision@'
-local MSG_NEED_DEV_MODE = 'Must be in development mode to use this function.'
 local WORKSPACE_ON, WORKSPACE_OFF = 1, 2
 local PLAYER_REALM = UnitName("player") .. '-' .. GetRealmName()
 local print = _G.print
@@ -99,63 +100,19 @@
 
 
   -- no args, toggle ui
-  if mode == 'dock' then
+  if  mode == 'stack' then
     if db.workspace == 1 then
-      D:Print('Must be in dev mode to use this.')
-      return
-    end
-    if #args <= 2 then
-      D:Print("Not enough arguments for dock command.")
-      return
-    end
-
-    local target
-    local worklist = {}
-    for i = 2, #args do
-      local ch
-      local k = tostring(args[i])
-      local j = tonumber(args[i])
-      if db.channels[j] then
-        ch = db.channels[j]
-      elseif D.sig[k] then
-        ch = D.sig[k]
-      elseif D.sigID[k] then
-        ch = db.channels[D.sigID[k]]
-      elseif db.tags[k] and db.tags[k][1] then
-        ch = db.channels[db.tags[j][1]]
-        -- last resort
-      else
-        D:Print('No entry for argument #'..i..': '..tostring(args[i]))
-        return
-      end
-      --@debug@
-      --print(i, '->', ch.index, '-', ch.signature)--@end-debug@
-      if i > 2 then
-        insert(worklist, ch.index)
-      else
-        target = ch
-
-        --@debug@
-        --print('arg1', args[2], target)--@end-debug@
-      end
-    end
-    D:Print("Docking |cFF88FFFF"..concat(worklist, "|r, |cFF88FFFF").."|r with |cFFFFFF00"..target.index..', '..target.signature.."|r.")
-    return D:DockFrame(target.index, unpack(worklist))
-
-
-  elseif mode == 'stack' then
-    if db.workspace == 1 then
-      return D:Print(MSG_NEED_DEV_MODE)
+      return D:Print(L['Need devmode'])
     end
     return D:StackFrames()
   elseif mode == 'grid' then
     if db.workspace == 1 then
-      return D:Print(MSG_NEED_DEV_MODE)
+      return D:Print(L['Need devmode'])
     end
     return D:DistributeFrames()
   elseif mode == 'tag' then -- tagging
     if db.workspace == 1 then
-      return D:Print(MSG_NEED_DEV_MODE)
+      return D:Print(L['Need devmode'])
     end
 
     local sig
@@ -181,7 +138,7 @@
       local channel
       if not D.db.channels[dest] then
         dest = D.max_channel + 1
-        D:Print('Created channel |cFF88FFFF'.. (sig and (dest..':'..sig) or dest ) .. '|r')
+        D:Print(L('New channel created', sig and (dest..':'..sig) or dest ))
         channel = D:SetChannel(sig or tag,dest)
       else
 
@@ -196,21 +153,21 @@
 
       if db.tags[tag][dest] then -- is tag set?
         db.tags[tag][dest] = nil
-        D:Print('Hiding |cFF88FFFF'..tag..'|r messages in |cFFFFFF00'..db.channels[dest].index ..':'.. db.channels[dest].signature)
+        D:Print(L('Tag removed from channel', tag, db.channels[dest].index, db.channels[dest].signature))
       else
         db.tags[tag][dest] = dest
-        D:Print('Showing |cFF88FFFF'..tag..'|r messages in |cFFFFFF00'..db.channels[dest].index ..':'.. db.channels[dest].signature)
+        D:Print(L('Tag added to channel', tag, db.channels[dest].index, db.channels[dest].signature))
       end
       D:UpdateDock()
     else
-      D:Print('Usage: /dvn tag <prefix> <console name or number>')
+      D:Print(L['Command tag help'])
     end
     return
   elseif tonumber(mode) ~= nil or mode == 'save' then
     -- iterating for something
     if mode == 'save' then
       if tonumber(tag) == nil then
-        T:Print('Save ID is invalid:', tag)
+        T:Print(L('Invalid ID from arg', tag))
       end
       list_state = tonumber(tag)
     else
@@ -224,7 +181,6 @@
   elseif mode == nil then
     list_state = (db.workspace == 1) and db.last_workspace or 1
     db.workspace = list_state
-    db.load_message = "quick swapped workspace #"..list_state
   else
     return D:PrintHelp()
   end
@@ -277,15 +233,15 @@
   end
 
   if mode ~= 'save' then
-    --db.load_message = "AddOn profile ".. list_state .." was loaded."
+    db.load_message = (mode == nil) and L("Toggled to profile", list_state) or L('Switched to profile number', list_state)
     ReloadUI()
   else
-      D:Print('Profile #'.. (list_state)..' saved.')
+
     if list_state == 1 then
-      D:Print('This will be your main AddOn list.')
-    elseif list_state == db.default_list then
+      D:Print(L['Profile main saved'])
+    else
       db.last_workspace = list_state
-      D:Print('This will be your default workspace')
+      D:Print(L('Profile number saved', list_state, list_state))
     end
   end
 end
@@ -301,8 +257,8 @@
   if db.workspace == 1 then
     return D.oldprint(prefix, ...)
   end
-
-  if tostring(prefix) == nil then
+  prefix =  tostring(prefix)
+  if prefix == nil then
     prefix = 'nil*'
   end
 
@@ -388,7 +344,6 @@
 
 
 function D:OnEnable()
-  print(MAJOR, MINOR)
 
   if db.unlisted and #db.unlisted > 0 then
     D:Print('New AddOns have been found since the last profile update: '.. concat(db.unlisted, ', '))
@@ -396,9 +351,9 @@
   end
 
   if db.workspace == 1 then
-    D:Print('Gameplay mode active (list #'..db.workspace..'). Print handling turned |cFFFFFF00OFF|r.')
+    D:Print(L('Devian loaded on standby',MAJOR, MINOR))
   else
-    D:Print('Development mode active (list #'..db.workspace..'). Print handling |cFF00FF00ON|r.')
+    D:Print(L('Devian loaded in workspace', MAJOR, MINOR, db.workspace))
     -- movement fading
     if db.movement_fade then
       self:RegisterEvent('PLAYER_STARTED_MOVING', function()
--- a/Devian.toc	Wed Jan 06 11:46:24 2016 -0500
+++ b/Devian.toc	Fri Jan 08 10:15:09 2016 -0500
@@ -7,6 +7,7 @@
 ## OptionalDeps: Ace3
 Devian.xml
 Devian.lua
+Locale.lua
 UI.lua
 Config.lua
 Dock.lua
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Locale.lua	Fri Jan 08 10:15:09 2016 -0500
@@ -0,0 +1,19 @@
+
+local L = Devian.L
+L['Devian loaded on standby'] = "%s%s. Work mode |cFFFFFF00off|r. /dvn help for info."
+L['Devian loaded in workspace'] = "%s%s. Work mode |cFF00FF00on|r. Profile #%d loaded."
+
+L['Profile number saved'] = "Workspace profile #%d saved. Use |cFFFFFF00/dvn %s|r to activate it."
+L['Profile main saved'] = "Non-work profile saved."
+L['Switch to profile number'] = "Switch to profile #%d"
+L["Toggled to profile"] = "Quick-swapped to profile #%d"
+
+L['Need devmode'] = "Workspace needs to be enabled to use this command."
+L['Not enough args'] = "Not enough arguments for command |cFFFFFF00%s|r"
+L['Invalid ID from arg'] = "|cFFFFFF00%d|r is not a valid channel."
+L['Invalid IDsig from arg'] = "|cFFFFFF00%d|r|cFF00FFFF/%s|r is not a valid channel."
+L['New channel created'] = 'Created channel |cFF88FFFF%s|r'
+
+L['Command tag help'] = "Usage /dvn <prefix> <channel>"
+L['Tag removed from channel'] = 'Stopping |cFF88FFFF%s|r output to |cFFFFFF00%s:%s|r'
+L['Tag added to channel'] = 'Adding |cFF88FFFF%s|r output to |cFFFFFF00%s:%s|r'
\ No newline at end of file