Move all strings to separate file for localization

Sasky [03-18-15 - 16:31]
Move all strings to separate file for localization
Filename
AutoInvite.lua
lang/en.lua
lua/cli.lua
lua/guild.lua
lua/kick.lua
ui/ai_enabled_fragment.lua
ui/ai_options_fragment.lua
diff --git a/AutoInvite.lua b/AutoInvite.lua
index 5ec2bf8..8d88991 100644
--- a/AutoInvite.lua
+++ b/AutoInvite.lua
@@ -1,6 +1,6 @@
 -- This file is part of AutoInvite
 --
--- (C) 2014 Scott Yeskie (Sasky)
+-- (C) 2015 Scott Yeskie (Sasky)
 --
 -- This program is free software; you can redistribute it and/or modify
 -- it under the terms of the GNU General Public License as published by
@@ -44,7 +44,7 @@ AutoInvite.callback = function(_, messageType, from, message)

     --TODO: Move this to the actual invite send so not per-message
 	if GetGroupSize() >= AutoInvite.cfg.maxSize then
-        echo("Group full. Disabling AutoInvite")
+        echo(GetString(SI_AUTO_INVITE_GROUP_FULL_STOP))
         AutoInvite.stopListening()
 	end

@@ -53,9 +53,8 @@ AutoInvite.callback = function(_, messageType, from, message)
             from = AutoInvite.accountNameLookup(messageType, from)
 			if from == "" or from == nil then return end
         end
-
-		from = from:gsub("%^.+", "")
-        echo("Sending invite to " .. from)
+
+        echo(zo_strformat(GetString(SI_AUTO_INVITE_SEND_TO_USER),from))
         AutoInvite:invitePlayer(from)
 	end

@@ -66,7 +65,7 @@ end
 AutoInvite.playerLeave = function(_, unitTag, connectStatus, isSelf)
     if AutoInvite.enabled and AutoInvite.cfg.restart then
         if not AutoInvite.listening then
-            echo("Now space in group. Restarted listening.")
+            echo(zo_strformat(GetString(SI_AUTO_INVITE_GROUP_OPEN_RESTART), AutoInvite.cfg.watchStr))
         end
         AutoInvite.startListening()
     end
@@ -136,9 +135,9 @@ AutoInvite.startListening = function(restart)
 		EVENT_MANAGER:RegisterForEvent(AutoInvite.AddonId, EVENT_CHAT_MESSAGE_CHANNEL, AutoInvite.callback)
 		AutoInvite.listening = true
         if restart ~= nil then
-            echo("Now space in group. AutoInvite restarted listening on '" ..  AutoInvite.cfg.watchStr .. "'")
+            echo(zo_strformat(GetString(SI_AUTO_INVITE_GROUP_OPEN_RESTART), AutoInvite.cfg.watchStr))
         else
-            echo("AutoInvite listening on string '" .. AutoInvite.cfg.watchStr .. "'")
+            echo(zo_strformat(GetString(SI_AUTO_INVITE_START_ON), AutoInvite.cfg.watchStr))
         end
     end
 end
diff --git a/lang/en.lua b/lang/en.lua
index 9bdcb2f..25f12b4 100644
--- a/lang/en.lua
+++ b/lang/en.lua
@@ -1,6 +1,6 @@
 -- This file is part of AutoInvite
 --
--- (C) 2014 Scott Yeskie (Sasky)
+-- (C) 2015 Scott Yeskie (Sasky)
 --
 -- This program is free software; you can redistribute it and/or modify
 -- it under the terms of the GNU General Public License as published by
@@ -15,7 +15,53 @@
 -- You should have received a copy of the GNU General Public License
 -- along with this program.  If not, see <http://www.gnu.org/licenses/>.

-ZO_CreateStringId("SI_AUTO_INVITE", "Auto Invite")
-ZO_CreateStringId("SI_AUTO_INVITE_STOP", "Stop AutoInvite")
+--Main Title (not translated)
+ZO_CreateStringId("SI_AUTO_INVITE", "AutoInvite")
+
+--Status messages
 ZO_CreateStringId("SI_AUTO_INVITE_NO_GROUP_MESSAGE", "Group is empty")
---ZO_CreateStringId("", "")
\ No newline at end of file
+ZO_CreateStringId("SI_AUTO_INVITE_SEND_TO_USER", "Sending invite to <<1>>")
+ZO_CreateStringId("SI_AUTO_INVITE_KICK", "Kicking <<1>> (offline for <<2>>)")
+ZO_CreateStringId("SI_AUTO_INVITE_GROUP_OPEN_RESTART", "Now space in group. Restarted listening on '<<1>>'")
+ZO_CreateStringId("SI_AUTO_INVITE_START_ON", "AutoInvite listening on string '<<1>>'")
+ZO_CreateStringId("SI_AUTO_INVITE_STOP", "Stop AutoInvite")
+ZO_CreateStringId("SI_AUTO_INVITE_GROUP_FULL_STOP", "Group full. Disabling AutoInvite")
+ZO_CreateStringId("SI_AUTO_INVITE_OFF", "Disabling AutoInvite")
+
+--Error messages
+ZO_CreateStringId("SI_AUTO_INVITE_ERROR_ACCOUNT", "Could not find player name for <<1>>. Please manually invite.")
+ZO_CreateStringId("SI_AUTO_INVITE_ERROR_ZONE", "Player <<1>> is not in Cyrodiil but in <<2>>")
+ZO_CreateStringId("SI_AUTO_INVITE_INV_BLOCK", "Blocking invite to prevent crashes.")
+ZO_CreateStringId("SI_AUTO_INVITE_ERROR_INVITE", "Error - couldn't invite on channel:")
+ZO_CreateStringId("SI_AUTO_INVITE_ERROR_KICK_TABLE", "No one named <<1>> found in group scan. Please manually kick.")
+
+--Menu
+ZO_CreateStringId("SI_AUTO_INVITE_OPT_ENABLED", "Enabled")
+ZO_CreateStringId("SI_AUTO_INVITE_TT_ENABLED", "Whether to enable AutoInvite")
+ZO_CreateStringId("SI_AUTO_INVITE_OPT_STRING", "Invite String")
+ZO_CreateStringId("SI_AUTO_INVITE_TT_STRING", "Text to check messages to auto-invite for")
+ZO_CreateStringId("SI_AUTO_INVITE_OPT_MAX_SIZE", "Max group size")
+ZO_CreateStringId("SI_AUTO_INVITE_TT_MAX_SIZE", "Maximum number of players to invite to group")
+ZO_CreateStringId("SI_AUTO_INVITE_OPT_RESTART", "Restart")
+ZO_CreateStringId("SI_AUTO_INVITE_TT_RESTART", "Restart AutoInvite if drop below max")
+ZO_CreateStringId("SI_AUTO_INVITE_OPT_CYRCHECK", "Cyrodiil Check")
+ZO_CreateStringId("SI_AUTO_INVITE_TT_CYRCHECK", "Only invite players that are in Cyrodiil.\n(This only runs if you are in Cyrodiil yourself.)")
+ZO_CreateStringId("SI_AUTO_INVITE_OPT_KICK", "Auto kick")
+ZO_CreateStringId("SI_AUTO_INVITE_TT_KICK", "Kick players that go offline")
+ZO_CreateStringId("SI_AUTO_INVITE_OPT_KICK_TIME", "Time before kick")
+ZO_CreateStringId("SI_AUTO_INVITE_TT_KICK_TIME", "Number of seconds to wait before kicking an offline player")
+ZO_CreateStringId("SI_AUTO_INVITE_OPT_SLASHCMD", "Slash Commands")
+ZO_CreateStringId("SI_AUTO_INVITE_BTN_REFRESH", "Refresh List")
+ZO_CreateStringId("SI_AUTO_INVITE_BTN_REFORM", "Re-form Group")
+
+--Slash commands
+--Note: Don't translate between the color codes  |C ... |r
+ZO_CreateStringId("SI_AUTO_INVITE_SLASHCMD_INFO", "AutoInvite - command |CFFFF00/ai <str>|r. Usage:")
+ZO_CreateStringId("SI_AUTO_INVITE_SLASHCMD_START", "|CFFFF00/ai foo|r - start listening on 'foo'")
+ZO_CreateStringId("SI_AUTO_INVITE_SLASHCMD_STOP", "|CFFFF00/ai|r - turn off AutoInvite")
+ZO_CreateStringId("SI_AUTO_INVITE_SLASHCMD_HELP", "|CFFFF00/ai help|r - show this help menu")
+
+--Templates for using in code (reference):
+--ZO_CreateStringId("SI_AUTO_INVITE_", )
+--GetString(SI_AUTO_INVITE...)
+--zo_strformat(GetString(SI_AUTO_INVITE_...), param1, param2))
\ No newline at end of file
diff --git a/lua/cli.lua b/lua/cli.lua
index 35bcdb5..60b0686 100644
--- a/lua/cli.lua
+++ b/lua/cli.lua
@@ -1,6 +1,6 @@
 -- This file is part of AutoInvite
 --
--- (C) 2014 Scott Yeskie (Sasky)
+-- (C) 2015 Scott Yeskie (Sasky)
 --
 -- This program is free software; you can redistribute it and/or modify
 -- it under the terms of the GNU General Public License as published by
@@ -26,10 +26,10 @@ local function echo(msg) CHAT_SYSTEM.primaryContainer.currentBuffer:AddMessage("

 -- print command usage
 AutoInvite.help = function()
-    echo("AutoInvite - command '/ai <str>'. Usage")
-    echo("  '/ai foo' - autoInvite on 'foo' command'")
-    echo("  '/ai help' - show this menu")
-    echo("  '/ai' - turn off autoInvite (auto on group full)")
+    echo(GetString(SI_AUTO_INVITE_SLASHCMD_INFO))
+    echo("  " .. GetString(SI_AUTO_INVITE_SLASHCMD_START))
+    echo("  " .. GetString(SI_AUTO_INVITE_SLASHCMD_HELP))
+    echo("  " .. GetString(SI_AUTO_INVITE_SLASHCMD_STOP))
     return
 end

@@ -40,7 +40,7 @@ SLASH_COMMANDS["/ai"] = function(str)
             AutoInvite.help()
             return
         end
-        echo("Disabling AutoInvite")
+        echo(GetString(SI_AUTO_INVITE_OFF))
         AutoInvite.disable()
         return
     end
diff --git a/lua/guild.lua b/lua/guild.lua
index 9ea4898..be696fe 100644
--- a/lua/guild.lua
+++ b/lua/guild.lua
@@ -1,6 +1,6 @@
 -- This file is part of AutoInvite
 --
--- (C) 2014 Scott Yeskie (Sasky)
+-- (C) 2015 Scott Yeskie (Sasky)
 --
 -- This program is free software; you can redistribute it and/or modify
 -- it under the terms of the GNU General Public License as published by
@@ -24,7 +24,7 @@ AutoInvite = AutoInvite or {}

 function AutoInvite.executeNameLookup(hasChar, charName, zone)
     if not hasChar then
-        echo("Could not find player name for " .. acctName .. ". Please manually invite.")
+        echo(zo_strformat(GetString(SI_AUTO_INVITE_ERROR_ACCOUNT), charName))
         return ""
     end

@@ -33,8 +33,8 @@ function AutoInvite.executeNameLookup(hasChar, charName, zone)
         dbg("In Cyrodiil? " .. b(AutoInvite.isCyrodiil()) .. " / Zone: " .. zone)

         if AutoInvite.isCyrodiil() and zone ~= "Cyrodiil" then
-            echo("Player " .. charName .. " is not in Cyrodiil but in " .. zone)
-            echo("Blocking invite to prevent crashes.")
+            echo(zo_strformat(GetString(SI_AUTO_INVITE_ERROR_ZONE), charName, zone))
+            echo(GetString(SI_AUTO_INVITE_INV_BLOCK))
             return ""
         end
     end
@@ -83,6 +83,6 @@ function AutoInvite.accountNameLookup(channel, acctName)
             if charName then return charName end
         end

-        echo("Error - couldn't invite on channel: " .. channel)
+        echo(GetString(SI_AUTO_INVITE_ERROR_INVITE) .. channel)
     end
 end
\ No newline at end of file
diff --git a/lua/kick.lua b/lua/kick.lua
index 77d6562..fd883db 100644
--- a/lua/kick.lua
+++ b/lua/kick.lua
@@ -1,6 +1,6 @@
 -- This file is part of AutoInvite
 --
--- (C) 2014 Scott Yeskie (Sasky)
+-- (C) 2015 Scott Yeskie (Sasky)
 --
 -- This program is free software; you can redistribute it and/or modify
 -- it under the terms of the GNU General Public License as published by
@@ -42,7 +42,7 @@ function AutoInvite.kickByName(name)
             return
         end
     end
-    echo("No one named " .. name .. " found in group scan. Please manually kick.")
+    echo(zo_strformat(GetString(SI_AUTO_INVITE_ERROR_KICK), name))
 end

 function AutoInvite.kickCheck()
@@ -52,7 +52,7 @@ function AutoInvite.kickCheck()
     for p,t in pairs(AutoInvite.kickTable) do
         local offTime = GetDiffBetweenTimeStamps(now, t)
         if offTime > AutoInvite.cfg.kickDelay then
-            echo("  KICK: " .. p .. " offline for " .. offTime)
+            echo(zo_strformat(GetString(SI_AUTO_INVITE_KICK), p, offTime))
             AutoInvite.kickByName(p)
         else
             dbg(p .. " offline for " .. offTime .. " / " .. AutoInvite.cfg.kickDelay)
diff --git a/ui/ai_enabled_fragment.lua b/ui/ai_enabled_fragment.lua
index 96afbc8..11f9b49 100644
--- a/ui/ai_enabled_fragment.lua
+++ b/ui/ai_enabled_fragment.lua
@@ -27,8 +27,8 @@ function AutoInviteUI:CreateEnabledFragment()

     ui.enabled = LAMCreateControl.checkbox(ui, {
         type = "checkbox",
-        name = "Enabled",
-        tooltip = "Whether to enable AutoInvite",
+        name = GetString(SI_AUTO_INVITE_OPT_ENABLED),
+        tooltip = GetString(SI_AUTO_INVITE_TT_ENABLED),
         getFunc = function() return AutoInvite.listening end,
         setFunc = function(val)
             if val then AutoInvite.startListening() else AutoInvite.disable() end
@@ -41,8 +41,8 @@ function AutoInviteUI:CreateEnabledFragment()
     --TODO: Sanity check between enable and blank string
     ui.text = LAMCreateControl.editbox(ui, {
         type = "editbox",
-        name = "Invite String",
-        tooltip = "Text to check messages to auto-invite for",
+        name = GetString(SI_AUTO_INVITE_OPT_STRING),
+        tooltip = GetString(SI_AUTO_INVITE_TT_STRING),
         getFunc = function() return AutoInvite.cfg.watchStr end,
         setFunc = function(val) AutoInvite.cfg.watchStr = val end,
         --width = "half"
diff --git a/ui/ai_options_fragment.lua b/ui/ai_options_fragment.lua
index a1bcb83..28f0645 100644
--- a/ui/ai_options_fragment.lua
+++ b/ui/ai_options_fragment.lua
@@ -29,15 +29,13 @@ function AutoInviteUI:CreateOptionFragment()
     ui.refreshList = wm:CreateControlFromVirtual(nil, ui.main, "ZO_DefaultButton")
     ui.refreshList:SetAnchor(TOPRIGHT, ui.main, TOPRIGHT, -365, 5)
     ui.refreshList:SetWidth(160)
-    ui.refreshList:SetText("Refresh List")
---    ui.refreshList:SetHandler("OnMouseEnter", ZO_Options_OnMouseEnter)
---    ui.refreshList:SetHandler("OnMouseExit", ZO_Options_OnMouseExit)
+    ui.refreshList:SetText(GetString(SI_AUTO_INVITE_BTN_REFRESH))
     ui.refreshList:SetHandler("OnClicked", function() MINI_GROUP_LIST:RefreshData() end)

     ui.max = LAMCreateControl.slider(ui, {
         type = "slider",
-        name = "Max group size",
-        tooltip = "Maximum number of players to invite to group",
+        name = GetString(SI_AUTO_INVITE_OPT_MAX_SIZE),
+        tooltip = GetString(SI_AUTO_INVITE_TT_MAX_SIZE),
         min = 4,
         max = 24,
         getFunc = function() return AutoInvite.cfg.maxSize end,
@@ -49,8 +47,8 @@ function AutoInviteUI:CreateOptionFragment()

     ui.restart = LAMCreateControl.checkbox(ui, {
         type = "checkbox",
-        name = "Restart",
-        tooltip = "Restart AutoInvite if drop below max",
+        name = GetString(SI_AUTO_INVITE_OPT_RESTART),
+        tooltip = GetString(SI_AUTO_INVITE_TT_RESTART),
         getFunc = function() return AutoInvite.cfg.restart end,
         setFunc = function(val) AutoInvite.cfg.restart = val  end,
         --width = "half"
@@ -59,8 +57,8 @@ function AutoInviteUI:CreateOptionFragment()

     ui.cyr = LAMCreateControl.checkbox(ui, {
         type = "checkbox",
-        name = "Cyrodiil Check",
-        tooltip = "Only invite players that are in Cyrodiil.\n(This only runs if you are in Cyrodiil yourself.)",
+        name = GetString(SI_AUTO_INVITE_OPT_CYRCHECK),
+        tooltip = GetString(SI_AUTO_INVITE_TT_CYRCHECK),
         getFunc = function() return AutoInvite.cfg.cyrCheck end,
         setFunc = function(val) AutoInvite.cfg.cyrCheck = val end,
         --width = "half"
@@ -69,8 +67,8 @@ function AutoInviteUI:CreateOptionFragment()

     ui.kick = LAMCreateControl.checkbox(ui, {
         type = "checkbox",
-        name = "Auto kick",
-        tooltip = "Kick players that go offline",
+        name = GetString(SI_AUTO_INVITE_OPT_KICK),
+        tooltip = GetString(SI_AUTO_INVITE_TT_KICK),
         getFunc = function() return AutoInvite.cfg.autoKick end,
         setFunc = function(val) AutoInvite.cfg.autoKick = val  end,
         --width = "half"
@@ -79,8 +77,8 @@ function AutoInviteUI:CreateOptionFragment()

     ui.kickTime = LAMCreateControl.slider(ui, {
         type = "slider",
-        name = "Time before kick",
-        tooltip = "Number of seconds to wait before kicking an offline player",
+        name = GetString(SI_AUTO_INVITE_OPT_KICK_TIME),
+        tooltip = GetString(SI_AUTO_INVITE_TT_KICK_TIME),
         min = 5,
         max = 600,
         getFunc = function() return AutoInvite.cfg.kickDelay end,
@@ -93,24 +91,16 @@ function AutoInviteUI:CreateOptionFragment()
     ui.regroup = wm:CreateControlFromVirtual(nil, ui.main, "ZO_DefaultButton")
     ui.regroup:SetAnchor(TOPLEFT, ui.kickTime, BOTTOMLEFT, 70, 70)
     ui.regroup:SetWidth(160)
-    ui.regroup:SetText("Re-form Group")
---    ui.regroup:SetHandler("OnMouseEnter", ZO_Options_OnMouseEnter)
---    ui.regroup:SetHandler("OnMouseExit", ZO_Options_OnMouseExit)
+    ui.regroup:SetText(GetString(SI_AUTO_INVITE_BTN_REFORM))
     ui.regroup:SetHandler("OnClicked", function() AutoInvite:resetGroup() end)

---    ui.queueTrigger = wm:CreateControlFromVirtual(nil, ui.main, "ZO_DefaultButton")
---    ui.queueTrigger:SetAnchor(TOPLEFT, ui.regroup, TOPRIGHT, 20, 0)
---    ui.queueTrigger:SetWidth(160)
---    ui.queueTrigger:SetText("Trigger Queue")
---    ui.queueTrigger:SetHandler("OnMouseEnter", ZO_Options_OnMouseEnter)
---    ui.queueTrigger:SetHandler("OnMouseExit", ZO_Options_OnMouseExit)
---    ui.queueTrigger:SetHandler("OnClicked", function() AutoInvite:processQueue() end)
-
+    local slashcmds = GetString(SI_AUTO_INVITE_SLASHCMD_START) ..
+            "\n" .. GetString(SI_AUTO_INVITE_SLASHCMD_HELP) ..
+            "\n" .. GetString(SI_AUTO_INVITE_SLASHCMD_STOP)
     ui.note = LAMCreateControl.description(ui, {
         type = "description",
-        title = "Slash Commands",
-        text = "/ai foo - start listening on 'foo'\n/ai - stop listening",
-        --width = "half"
+        title = GetString(SI_AUTO_INVITE_OPT_SLASHCMD),
+        text = slashcmds,
     })
     ui.note:SetAnchor(BOTTOMRIGHT, ZO_GroupList, BOTTOMRIGHT, -40, -40)
     ui.note.desc:SetColor(.7,.7,.7,1)