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 <%version%> (<%codename%>)
6 $Id: Babylonian.lua 962 2006-08-18 03:03:29Z 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 GPL.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
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 end
49 SetCVar("BabylonianOrder", order)
50 end
51  
52 function getOrder()
53 return GetCVar("BabylonianOrder")
54 end
55  
56 function fetchString(stringTable, locale, stringKey)
57 if (type(stringTable)=="table" and type(stringTable[locale])=="table" and stringTable[locale][stringKey]) then
58 return stringTable[locale][stringKey]
59 end
60 end
61  
62 function getString(stringTable, stringKey, default)
63 local val
64 for i=1, table.getn(self.order) do
65 val = fetchString(stringTable, self.order[i], stringKey)
66 if (val) then return val end
67 end
68 return default
69 end
70  
71 if (not Babylonian) then
72 Babylonian = {
73 ['SetOrder'] = setOrder,
74 ['GetOrder'] = getOrder,
75 ['GetString'] = getString,
76 ['FetchString'] = fetchString,
77 }
78 RegisterCVar("BabylonianOrder", "")
79 setOrder(getOrder())
80 end