vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2  
3 Babylonian
4 A sub-addon that manages the locales for other addons.
5 3.4.1 (Platypus)
6 $Id: Babylonian.lua 716 2006-02-09 15:25:17Z mentalpower $
7  
8 License:
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13  
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18  
19 You should have received a copy of the GNU General Public License
20 along with this program(see GLP.txt); if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22  
23 ]]
24  
25 local self = {}
26 if (not self.update) then self.update = {}; end
27 --Local function prototypes
28 local split, setOrder, getOrder, fetchString, getString, registerAddOn, unRegisterAddOn, updateKhaos, isAddOnRegistered
29  
30 function split(str, at)
31 local splut = {}
32 if (type(str) ~= "string") then return nil end
33 if (not str) then str = "" end
34 if (not at) then table.insert(splut, str)
35 else for n, c in string.gfind(str, '([^%'..at..']*)(%'..at..'?)') do
36 table.insert(splut, n); if (c == '') then break end
37 end end
38 return splut
39 end
40  
41 function setOrder(order)
42 if (not order) then self.order = {}
43 else self.order = split(order, ",") end
44 table.insert(self.order, GetLocale())
45 table.insert(self.order, "enUS")
46 if not(self.order[1] == getOrder()) then
47 SetCVar("BabylonianOrder", order)
48 updateKhaos()
49 end
50 SetCVar("BabylonianOrder", order)
51 end
52  
53 function getOrder()
54 return GetCVar("BabylonianOrder")
55 end
56  
57 function fetchString(stringTable, locale, stringKey)
58 if (type(stringTable)=="table" and
59 type(stringTable[locale])=="table" and
60 stringTable[locale][stringKey]) then
61 return stringTable[locale][stringKey]
62 end
63 end
64  
65 function getString(stringTable, stringKey, default)
66 local val
67 for i=1, table.getn(self.order) do
68 val = fetchString(stringTable, self.order[i], stringKey)
69 if (val) then return val end
70 end
71 return default
72 end
73  
74 --The following three functions were added to work around some Khaos behaviours.
75 function registerAddOn(AddOn, updateFunction)
76  
77 --Make both arguments required and make sure that they're the right type
78 if ((not AddOn) or (not type(AddOn) == "string")) or ((not updateFunction) or (not type(updateFunction) == "function")) then
79 EnhTooltip.DebugPrint("Invalid arguments passed to Babylonian.RegisterAddOn() |"..AddOn.." | "..updateFunction);
80 return
81 end
82  
83 EnhTooltip.DebugPrint("Registering '"..AddOn.."' with Babylonian");
84 self.update[AddOn] = updateFunction;
85 end
86  
87 function unRegisterAddOn(AddOn)
88  
89 --Again make sure the argument exists and that its the right type
90 if ((not AddOn) or (not type(AddOn) == "string")) then
91 return
92 end
93  
94 EnhTooltip.DebugPrint("UnRegistering '"..AddOn.."' with Babylonian");
95 self.update[AddOn] = nil;
96 end
97  
98 function isAddOnRegistered(AddOn)
99  
100 --Again make sure the argument exists and that its the right type
101 if ((not AddOn) or (not type(AddOn) == "string")) then
102 return nil;
103 end
104  
105 return (self.update[AddOn] ~= nil);
106 end
107  
108 function updateKhaos()
109 local table = self.update
110  
111 for AddOn, updateFunction in table do
112 EnhTooltip.DebugPrint("Updating '"..AddOn.."'s Khaos Locale");
113 updateFunction(getOrder(), nil, true);
114 end
115 end
116  
117 if (not Babylonian) then
118 Babylonian = {
119 ['SetOrder'] = setOrder,
120 ['GetOrder'] = getOrder,
121 ['GetString'] = getString,
122 ['FetchString'] = fetchString,
123 ['RegisterAddOn'] = registerAddOn,
124 ['UnRegisterAddOn'] = unRegisterAddOn,
125 ['IsAddOnRegistered'] = isAddOnRegistered,
126 }
127 RegisterCVar("BabylonianOrder", "")
128 setOrder(getOrder())
129 end