vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 Enchantrix Addon for World of Warcraft(tm).
3 Version: 3.6.1 (Platypus)
4 Revision: $Id: EnxLocale.lua 944 2006-07-11 03:31:50Z mentalpower $
5  
6 Localization routines
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 -- Global functions
25 local addonLoaded -- Enchantrix.Locale.AddonLoaded()
26 local delocalizeFilterVal -- Enchantrix.Locale.DelocalizeFilterVal()
27 local localizeFilterVal -- Enchantrix.Locale.LocalizeFilterVal()
28 local getLocalizedFilterVal -- Enchantrix.Locale.GetLocalizedFilterVal()
29 local delocalizeCommand -- Enchantrix.Locale.DelocalizeCommand()
30 local localizeCommand -- Enchantrix.Locale.LocalizeCommand()
31  
32 -- Local functions
33 local buildCommandMap
34 local getLocalizedCmdString
35  
36 local customLocalizations = {
37 ['TextGeneral'] = GetLocale(),
38 ['TextCombat'] = GetLocale(),
39 ['ArgSpellname'] = GetLocale(),
40 ['PatReagents'] = GetLocale(),
41 }
42  
43 Enchantrix.State.Locale_Changed = true --This needs to be initialy set to true so that the following tables get built at startup.
44 local commandMap, commandMapRev;
45  
46 function addonLoaded()
47 buildCommandMap()
48 end
49  
50 function _ENCH(stringKey, locale)
51 if locale then
52 if type(locale) == "string" then
53 return Babylonian.FetchString(EnchantrixLocalizations, locale, stringKey)
54 else
55 return Babylonian.FetchString(EnchantrixLocalizations, GetLocale(), stringKey)
56 end
57 elseif (customLocalizations[stringKey]) then
58 return Babylonian.FetchString(EnchantrixLocalizations, customLocalizations[stringKey], stringKey)
59 else
60 return Babylonian.GetString(EnchantrixLocalizations, stringKey)
61 end
62 end
63  
64 function buildCommandMap()
65 commandMap = {}
66 commandMapRev = {}
67  
68 commandMap = {
69 [_ENCH('CmdOn')] = 'on',
70 [_ENCH('CmdOff')] = 'off',
71 [_ENCH('CmdBarker')] = 'barker',
72 [_ENCH('CmdHelp')] = 'help',
73 [_ENCH('CmdToggle')] = 'toggle',
74 [_ENCH('CmdDisable')] = 'disable',
75 [_ENCH('CmdClear')] = 'clear',
76 [_ENCH('CmdLocale')] = 'locale',
77 [_ENCH('CmdDefault')] = 'default',
78 [_ENCH('CmdPrintin')] = 'print-in',
79 [_ENCH('CmdFindBidauct')] = 'bidbroker',
80 [_ENCH('CmdFindBidauctShort')] = 'bidbroker',
81 [_ENCH('CmdFindBuyauct')] = 'percentless',
82 [_ENCH('CmdFindBuyauctShort')] = 'percentless',
83 [_ENCH('ShowEmbed')] = 'embed',
84 [_ENCH('ShowCount')] = 'counts',
85 [_ENCH('ShowTerse')] = 'terse',
86 [_ENCH('ShowValue')] = 'valuate',
87 [_ENCH('ShowGuessAuctioneerHsp')] = 'valuate-hsp',
88 [_ENCH('ShowGuessAuctioneerMed')] = 'valuate-median',
89 [_ENCH('ShowGuessBaseline')] = 'valuate-baseline',
90 }
91  
92 for k, v in pairs(commandMap) do
93 commandMapRev[v] = k
94 end
95 end
96  
97 function getLocalizedCmdString(value)
98 return _ENCH('Cmd'..string.upper(string.sub(value,1,1))..string.sub(value,2))
99 end
100  
101 function delocalizeFilterVal(value)
102 if value == _ENCH('CmdOn') then
103 return 'on'
104 elseif value == _ENCH('CmdOff') then
105 return 'off'
106 elseif value == _ENCH('CmdDefault') then
107 return 'default'
108 elseif value == _ENCH('CmdToggle') then
109 return 'toggle'
110 else
111 return value
112 end
113 end
114  
115 function localizeFilterVal(value)
116 if (value == 'on') or (value == true) then
117 return _ENCH("CmdOn")
118 elseif (value == 'off') or (value == false) then
119 return _ENCH("CmdOff")
120 elseif (value == 'default') or (value == nil) then
121 return _ENCH("CmdDefault")
122 else
123 return value
124 end
125 end
126  
127 function getLocalizedFilterVal(key)
128 return localizeFilterVal(Enchantrix.Config.GetFilter(key))
129 end
130  
131 -- Turns a localized slash command into the generic English version of the command
132 function delocalizeCommand(cmd)
133 if Enchantrix.State.Locale_Changed then
134 buildCommandMap()
135 Enchantrix.State.Locale_Changed = nil
136 end
137 return commandMap[cmd] or cmd
138 end
139  
140 -- Translate a generic English slash command to the localized version, if available
141 function localizeCommand(cmd)
142 if Enchantrix.State.Locale_Changed then
143 buildCommandMap()
144 Enchantrix.State.Locale_Changed = nil
145 end
146 return commandMapRev[cmd] or cmd
147 end
148  
149 Enchantrix.Locale = {
150 Revision = "$Revision: 944 $",
151  
152 AddonLoaded = addonLoaded,
153  
154 DelocalizeFilterVal = delocalizeFilterVal,
155 LocalizeFilterVal = localizeFilterVal,
156 GetLocalizedFilterVal = getLocalizedFilterVal,
157 DelocalizeCommand = delocalizeCommand,
158 LocalizeCommand = localizeCommand,
159 }