source: trunk/Modules/Export/files/3.3.5a/CzWoW/CzWoW.lua

Last change on this file was 794, checked in by maron, 11 years ago
  • Fixed: set user tag in user Profile.php
  • Added: translate game object with 2 lines (herbals)
  • Property svn:executable set to *
File size: 14.1 KB
Line 
1Enable_Interface=True;
2local MyPanel;
3local Load_text= "CzWoW načteno. Díky addonu by měl fungovat překlad výprav, NPC textů, textů knížek, rozhraní klienta, tutoriál, chybové hlášení uprostřed obrazovky. Pomoci překladu můžete na stránkách http://wowpreklad.zdechov.net/ Pro popis příkazů napiš příkaz /czwow help";
4 --DEFAULT_CHAT_FRAME:AddMessage("NPC");
5
6Debug = false; --turn this when you want to compare trim english text with text database
7
8-------------------
9--global function--
10-------------------
11
12local trim=function(text)
13 if not text then
14 return nil;
15 end
16 text = string.lower(text);
17 text = gsub(text, "%s+", " ");
18 text = gsub(text, "^%s+", "");
19 text = gsub(text, "%s+$", "");
20 text = gsub(text, " ", "");
21 return text;
22end
23
24local DoTranslate=function(text)
25 local en = text;
26 text = trim(text);
27 for i=1, CZWOW_QuestTitle_count, 1 do
28 if getglobal("CZWOW_QuestTitle_"..i)[text] then
29 return getglobal("CZWOW_QuestTitle_"..i)[text];
30 end
31 end
32 for i=1, CZWOW_QuestObjective_count, 1 do
33 if getglobal("CZWOW_QuestObjective_"..i)[text] then
34 return getglobal("CZWOW_QuestObjective_"..i)[text];
35 end
36 end
37 for i=1, CZWOW_QuestDescription_count, 1 do
38 if getglobal("CZWOW_QuestDescription_"..i)[text] then
39 return getglobal("CZWOW_QuestDescription_"..i)[text];
40 end
41 end
42 for i=1, CZWOW_QuestProgress_count, 1 do
43 if getglobal("CZWOW_QuestProgress_"..i)[text] then
44 return getglobal("CZWOW_QuestProgress_"..i)[text];
45 end
46 end
47 for i=1, CZWOW_QuestReward_count, 1 do
48 if getglobal("CZWOW_QuestReward_"..i)[text] then
49 return getglobal("CZWOW_QuestReward_"..i)[text];
50 end
51 end
52 for i=1, CZWOW_NPCAction_count, 1 do
53 if getglobal("CZWOW_NPCAction_"..i)[text] then
54 return getglobal("CZWOW_NPCAction_"..i)[text];
55 end
56 end
57 for i=1, CZWOW_BookPage_count, 1 do
58 if getglobal("CZWOW_BookPage_"..i)[text] then
59 return getglobal("CZWOW_BookPage_"..i)[text];
60 end
61 end
62 for i=1, CZWOW_NPCText_count, 1 do
63 if getglobal("CZWOW_NPCText_"..i)[text] then
64 return getglobal("CZWOW_NPCText_"..i)[text];
65 end
66 end
67 for i=1, CZWOW_ItemName_count, 1 do
68 if getglobal("CZWOW_ItemName_"..i)[text] then
69 return getglobal("CZWOW_ItemName_"..i)[text];
70 end
71 end
72 for i=1, CZWOW_ItemDescription_count, 1 do
73 if getglobal("CZWOW_ItemDescription_"..i)[text] then
74 return getglobal("CZWOW_ItemDescription_"..i)[text];
75 end
76 end
77 for i=1, CZWOW_ObjectName_count, 1 do
78 if getglobal("CZWOW_ObjectName_"..i)[text] then
79 return getglobal("CZWOW_ObjectName_"..i)[text];
80 end
81 end
82
83 return en;
84
85end
86
87
88
89local Translate=function(text)
90 if Debug then
91 if (text == nil) then else
92 print("Or: "..text);
93 print("En: "..trim(text));
94 text = DoTranslate(text);
95 print("Cz: "..text);
96 return text;
97 end
98 else
99 return DoTranslate(text);
100 end
101end
102
103------------------
104--addon function--
105------------------
106
107CzWoW_OnEvent=function(self, event, ...)
108 if (event == "VARIABLES_LOADED") then
109 CzWoW_OnLoadVar();
110 end
111 if Debug then print (event); end
112
113end
114
115CzWoW_OnLoad=function(self)
116
117 self:RegisterEvent("VARIABLES_LOADED");
118-- self:RegisterEvent("PLAYER_ENTERING_WORLD");
119-- self:RegisterEvent("COMBAT_LOG_EVENT");
120 self:RegisterEvent("ITEM_TEXT_TRANSLATION");
121-- self:RegisterEvent("ITEM_TEXT_BEGIN");
122 -- self:RegisterEvent("ITEM_TEXT_CLOSED");
123-- self:RegisterEvent("ITEM_PUSH");
124-- self:RegisterEvent("SHOW_COMPARE_TOOLTIP");
125 self:RegisterEvent("OnTooltipSetItem");
126 self:RegisterEvent("QUEST_LOG_UPDATE");
127
128
129 GameTooltip:HookScript("OnUpdate",GameObjectChange);
130 if(GameTooltip:GetScript("OnTooltipSetItem")) then
131 GameTooltip:HookScript("OnTooltipSetItem",ItemChangeName);
132 else
133 GameTooltip:SetScript("OnTooltipSetItem",ItemChangeName);
134 end
135 for nn, tooltip in ipairs(TooltipList) do
136 if tooltip then
137 for _, methodName in ipairs(MethodList) do
138 hooksecurefunc(tooltip, methodName, ItemChangeName);
139 end
140 end
141 end
142
143end
144
145--------Translate item------------------
146TooltipList = {
147 ItemRefTooltip,
148 GameTooltip,
149 ShoppingTooltip1,
150 ShoppingTooltip2,
151 ComparisonTooltip1,
152 ComparisonTooltip2,
153}
154
155MethodList = {
156 "SetLootItem",
157 "SetHyperlink",
158 "SetBagItem",
159 "SetInventoryItem",
160 "SetAuctionItem",
161 "SetAuctionSellItem",
162 "SetLootRollItem",
163 "SetTradeSkillItem",
164 "SetTrainerService",
165 "SetInboxItem",
166 "SetSendMailItem",
167 "SetQuestItem",
168 "SetQuestLogItem",
169 "SetTradePlayerItem",
170 "SetTradeTargetItem",
171 "SetMerchantItem",
172 "SetHyperlinkCompareItem",
173 "SetBuybackItem",
174}
175
176function TranslateTooltip(this)
177 if this then
178 local text = this:GetText();
179 for i=1, CZWOW_ItemName_count, 1 do
180 if getglobal("CZWOW_ItemName_"..i)[trim(text)] then
181 text = getglobal("CZWOW_ItemName_"..i)[trim(text)];
182 end
183 end
184 -- text = "bleble";
185-- DEFAULT_CHAT_FRAME:AddMessage(text);
186 this:SetText(text);
187 end
188end
189
190function ItemChangeName(this)
191 local name = "test ěščřžýáíéůú fsd fa";
192 if CZWOW_ItemName_count > 0 then
193 TranslateTooltip(GameTooltipTextLeft1);
194 TranslateTooltip(ItemRefTooltipTextLeft1);
195 TranslateTooltip(ShoppingTooltip1TextLeft2);
196 TranslateTooltip(ShoppingTooltip2TextLeft2);
197 TranslateTooltip(ComparisonTooltip1TextLeft4);
198 TranslateTooltip(ComparisonTooltip2TextLeft6);
199 --/run
200 end
201 if CZWOW_ItemDescription_count > 0 then
202 for i=1,GameTooltip:NumLines()do
203 local mytext=_G["GameTooltipTextLeft"..i];
204 if "\"" == strsub(mytext:GetText(), 0,1) then
205 local text = strsub(mytext:GetText(), 2,strlen(mytext:GetText())-2);
206 text = text..".";
207 for i=1, CZWOW_ItemDescription_count, 1 do
208 if getglobal("CZWOW_ItemDescription_"..i)[trim(text)] then
209 text = getglobal("CZWOW_ItemDescription_"..i)[trim(text)];
210 end
211 end
212 mytext:SetText("\""..text.."\"");
213 end
214 end
215 end
216
217 this:Show();
218end
219---------item at vendor------
220local old_MerchantFrame_UpdateMerchantInfo = MerchantFrame_UpdateMerchantInfo;
221function MerchantFrame_UpdateMerchantInfo()
222 old_MerchantFrame_UpdateMerchantInfo();
223 local numMerchantItems = GetMerchantNumItems();
224 for i=1, MERCHANT_ITEMS_PER_PAGE, 1 do
225 local index = (((MerchantFrame.page - 1) * MERCHANT_ITEMS_PER_PAGE) + i);
226 if ( index <= numMerchantItems ) then
227 name, texture, price, quantity, numAvailable, isUsable, extendedCost = GetMerchantItemInfo(index);
228 local text = name;
229 for i=1, CZWOW_ItemName_count, 1 do
230 if getglobal("CZWOW_ItemName_"..i)[trim(text)] then
231 text = getglobal("CZWOW_ItemName_"..i)[trim(text)];
232 end
233 end
234 getglobal("MerchantItem"..i.."Name"):SetText(text);
235 end
236 end
237end
238
239-------item at loot--------------------
240local old_LootFrame_Update = LootFrame_Update;
241function LootFrame_Update()
242 old_LootFrame_Update();
243 local numLootItems = LootFrame.numLootItems;
244 --Logic to determine how many items to show per page
245 local numLootToShow = LOOTFRAME_NUMBUTTONS;
246 if ( numLootItems > LOOTFRAME_NUMBUTTONS ) then
247 numLootToShow = numLootToShow - 1;
248 end
249 local texture, item, quantity, quality;
250 local button, countString, color;
251 for index = 1, LOOTFRAME_NUMBUTTONS do
252 local slot = (numLootToShow * (LootFrame.page - 1)) + index;
253 texture, item, quantity, quality = GetLootSlotInfo(slot);
254
255 local text = item;
256 for i=1, CZWOW_ItemName_count, 1 do
257 if getglobal("CZWOW_ItemName_"..i)[trim(text)] then
258 text = getglobal("CZWOW_ItemName_"..i)[trim(text)];
259 end
260 end
261
262 getglobal("LootButton"..index.."Text"):SetText(text);
263 end
264end
265
266---------translate gameobject----------
267function GameObjectChange(this)
268 if 1 == GameTooltip:NumLines() or 2 == GameTooltip:NumLines() then
269 if CZWOW_ObjectName_count > 0 then
270 if GameTooltipTextLeft1 then
271 for i=1, CZWOW_ObjectName_count, 1 do
272 local text = GameTooltipTextLeft1:GetText();
273 if getglobal("CZWOW_ObjectName_"..i)[trim(text)] then
274 GameTooltipTextLeft1:SetText(getglobal("CZWOW_ObjectName_"..i)[trim(text)]);
275 end
276 end
277 GameTooltip:Show();
278 end;
279 end
280 end
281end
282
283
284CzWoW_OnLoadVar=function()
285 SLASH_CZWOW1 = "/czwow";
286 SlashCmdList["CZWOW"]=CzWoW_CMD;
287
288
289 DEFAULT_CHAT_FRAME:AddMessage(Load_text);
290
291 if Enable_Interface then
292 --načtení UI
293 TranslateInterface();
294 end
295
296end
297
298
299CzWoW_CMD=function(msg)
300 DEFAULT_CHAT_FRAME:AddMessage(Load_text);
301 if msg == "help" then
302 print("Nápověda pro nastavení překladového addonu")
303 print("/czwow interface - pro povolení/zakázání překládání uživatelského rozhraní")
304 end
305
306 if msg == "config" then
307 InterfaceOptionsFrame_OpenToCategory(MyPanel);
308 end
309
310 if msg == "debug" then
311 Debug = not Debug;
312 end
313
314 if msg == "interface" then
315 Enable_Interface = not Enable_Interface;
316 if Enable_Interface then
317 print("Nyní bylo povoleno překládání rozhraní clienta, může se projevit nestabilita wow. Pokud k tomu bude docházet doporučuji zakázat.")
318 TranslateInterface();
319 else
320 print("Nyní bylo zakázáno překládání rozhraní clienta. Aby se změny projevily je zapotřebí restart wow, nebo znovunačtení uživatelského rozhraní, které se prování příkazem: /run ReloadUI()")
321 end
322 end
323end
324
325function SC_ChaChingPanel_OnLoad(panel)
326 panel.name = "CzWoW";
327 panel.okay = function (self) SC_ChaChingPanel_Close(); end;
328 panel.cancel = function (self) SC_ChaChingPanel_CancelOrLoad(); end;
329 InterfaceOptions_AddCategory(panel);
330 MyPanel = panel;
331end
332
333----------------------
334--translate function--
335----------------------
336
337CZWOW_OnUpdate=function()
338 if GossipFrame:IsShown() then GossipFrameUpdate() end
339 if QuestFrameProgressPanel:IsVisible() then QuestFrameProgressPanel_OnShow(); end
340 if QuestFrameRewardPanel:IsVisible() then QuestFrameRewardPanel_OnShow(); end
341 if ItemTextFrame:IsVisible() then ItemTextFrame_OnEvent(); end
342 if ( QuestInfoFrame.questLog ) then QuestLog_Update(); end
343end
344
345--formuláře výprav u NPC
346QuestFrameProgressPanel_OnShow=function()
347 if getglobal("CZWOW_QuestTitle_1")[trim(GetTitleText())] then
348 QuestProgressTitleText:SetText(Translate(GetTitleText()));
349 QuestProgressText:SetText(Translate(GetProgressText()));
350 end
351end
352
353QuestFrameRewardPanel_OnShow=function()
354-- if getglobal("CZWOW_QuestTitle_1")[trim(GetTitleText())] then
355-- QuestRewardTitleText:SetText(Translate(GetTitleText()));
356-- QuestRewardText:SetText(Translate(GetRewardText()));
357-- end;
358end
359--konec formuláře výprav
360
361
362-- překládání textů questů u zadávání a v quest logu
363local old_QuestInfo_Display=QuestInfo_Display;
364QuestInfo_Display=function(...)
365 old_QuestInfo_Display(...);
366
367
368 if ( QuestInfoFrame.questLog ) then
369 questTitle = GetQuestLogTitle(GetQuestLogSelection());
370 questDescription, questObjectives=GetQuestLogQuestText();
371 else
372 questTitle = GetTitleText();
373 questDescription = GetQuestText();
374 questObjectives = GetObjectiveText();
375 end
376
377 if getglobal("CZWOW_QuestTitle_1")[trim(questTitle)] then
378 QuestInfoTitleHeader:SetText(Translate(questTitle));
379 QuestInfoRewardText:SetText(Translate(questLogTitleText));
380 QuestInfoDescriptionText:SetText(Translate(questDescription));
381 QuestInfoObjectivesText:SetText(Translate(questObjectives));
382 QuestInfoRewardText:SetText(Translate(GetRewardText()));
383 end
384end
385
386--překládání titulů questů v seznamu questů
387local old_QuestLog_Update=QuestLog_Update;
388QuestLog_Update=function()
389old_QuestLog_Update();
390 local buttons = QuestLogScrollFrame.buttons;
391 local numButtons = #buttons;
392 local scrollOffset = HybridScrollFrame_GetOffset(QuestLogScrollFrame);
393
394 local questIndex, questTitleTag, questNumGroupMates, questNormalText, questCheck;
395 local title, level, questTag, suggestedGroup, isHeader, isCollapsed, isComplete, isDaily;
396 local partyMembersOnQuest, tempWidth, textWidth;
397 for i=1, numButtons do
398 local questLogTitle = buttons[i];
399 questIndex = i + scrollOffset;
400 questLogTitle:SetID(questIndex);
401 title, _, _, _, _, _, _, _ = GetQuestLogTitle(questIndex);
402 if questLogTitle then questLogTitle:SetText(Translate(title)); end
403 end
404end
405--konec questlog
406
407--Formuláře NPC postav
408local old_GossipFrameOptionsUpdate=GossipFrameOptionsUpdate;
409GossipFrameOptionsUpdate=function(...)
410 if select("#", ...)>0 then
411 old_GossipFrameOptionsUpdate(...);
412 for i=1, NUMGOSSIPBUTTONS, 1 do
413 titleButton=getglobal("GossipTitleButton" .. i);
414 local en=titleButton:GetText();
415 titleButton:SetText(Translate(en));
416 GossipResize(titleButton);
417-- TODO: kontrolovat také s bez "The"
418 end
419 end
420end
421
422local old_GossipFrameUpdate=GossipFrameUpdate;
423GossipFrameUpdate=function()
424 old_GossipFrameUpdate();
425 local en=GossipGreetingText:GetText();
426 GossipGreetingText:SetText(Translate(en));
427end;
428
429local old_GossipFrameActiveQuestsUpdate=GossipFrameActiveQuestsUpdate;
430GossipFrameActiveQuestsUpdate=function(...)
431 local titleButton;
432 local titleIndex = 1;
433 old_GossipFrameActiveQuestsUpdate(...);
434 for i=1, select("#", ...), 3 do
435 titleButton = _G["GossipTitleButton" .. titleIndex];
436 if getglobal("CZWOW_QuestTitle_1")[trim(select(i, ...))] then
437 titleButton:SetText(Translate(select(i, ...)));
438 end
439 titleIndex = titleIndex + 1;
440 end
441end
442
443local old_GossipFrameAvailableQuestsUpdate=GossipFrameAvailableQuestsUpdate;
444GossipFrameAvailableQuestsUpdate=function(...)
445 local titleButton;
446 local titleIndex = 1;
447 old_GossipFrameAvailableQuestsUpdate(...);
448 for i=1, select("#", ...), 3 do
449 titleButton = _G["GossipTitleButton" .. titleIndex];
450 titleButton:SetText(Translate(select(i, ...)));
451 titleIndex = titleIndex + 1;
452 end
453end
454--konec formuláře NPC postav
455
456--page texty
457ItemTextFrame_OnEvent=function(self, event, ...)
458 local en=ItemTextGetText();
459 ItemTextPageText:SetText(Translate(en));
460end;
461--konec page texty
462
463
464
465
Note: See TracBrowser for help on using the repository browser.