|
Developer_Changes_For_4_1_9_30100
Important changes concerning the revamped Ace3 localization system.
IntroductionAs part of the ongoing effort to improve efficiency in Titan Panel and reduce development time spend on trivial tasks, the localization system has been reworked, in version 4.1.9.30100 to utilize the AceLocale-3.0 library. What this means for usersA great deal of effort has been put into facilitating the chance, with the least impact on users. Still, since the change breaks compatibility with the old system (something that was regrettably unavoidable), there is a chance that several older (and mostly unmaintained) Titan native plugins, may cause errors or display empty menu items, when invoking their right-click dropdown menu. The changes required to make those plugins functional again are for the most part, trivial. Users are encouraged to contact the plugin authors for a solution, or seek alternatives. Data Broker plugins remain totally unaffected by the change, as they generally handle their own localization without referencing anything, in the display addon (in our case, Titan Panel). What this means for plugin authorsIn the old system, Titan Panel's localization strings were directly connected to global variables, declared inside the localization files (e.g ..\Interface\Addons\Titan\locale\Localization.lua - for enUS). This has now changed, as the aforementioned translation strings are registered with AceLocale-3.0, as fields to a table. In order to reference localization strings, belonging to the core display addon (Titan Panel), the author will be required to create a reference to the locale table like this : In your main plugin code file (TitanMyAddon.lua or whatever you've named it) and preferably before the OnLoad function handler, ask AceLocale to give you the proper translation object: local L = LibStub("AceLocale-3.0"):GetLocale("Titan", true) The line above fetches the localization table registered under the name of 'Titan' (pretty much the entire localization table of the core display addon), corresponding to the client's language and assigns it to the local variable L. The first argument in the GetLocale method, is the core addon name that we (the Titan Dev Team) specified in the locale file(s), when we registered the appropriate translations. The second is a boolean value specifying whether AceLocale should fail silently if locale information is found or not. true means no error message will be displayed if locale info cannot be loaded. After you've acquired the translation object/table, it's just a matter of substituting it in wherever you previously would have used the global variable. Let's look at a common example of this : Many plugins used to add a command for disabling/hiding the Titan object, in their right-click menu, like this : TitanPanelRightClickMenu_AddCommand(TITAN_PANEL_MENU_HIDE, TITAN_COORDS_ID, TITAN_PANEL_MENU_FUNC_HIDE); ...which should now be changed to... TitanPanelRightClickMenu_AddCommand(L["TITAN_PANEL_MENU_HIDE"], TITAN_COORDS_ID, TITAN_PANEL_MENU_FUNC_HIDE); Example 2 :Some plugins were using TITAN_MONEY_FORMAT in order to format strings, generally intended to hold money info. This should now be changed to L["TITAN_MONEY_FORMAT"], after specifying L in the main code, as previously demonstrated. Below, you may find a more tangible example, derived from the TitanGoldTracker code : currentMoneyRichText = currentMoneyRichText.."\n"..character.."\t"..TitanUtils_GetHighlightText(format(TITAN_MONEY_FORMAT, TitanPanelGoldTracker_BreakMoney(floor(GoldArray[GoldArraySorted[i]]/10)))); currentMoneyRichText = currentMoneyRichText.."\n"..character.."\t"..TitanUtils_GetHighlightText(format(L["TITAN_MONEY_FORMAT"], TitanPanelGoldTracker_BreakMoney(floor(GoldArray[GoldArraySorted[i]]/10)))); Example 3 :Old system: -- FPS tooltip
if ( showFPS ) then
local fpsText = format(TITAN_FPS_FORMAT, button.fps);
local avgFPSText = format(TITAN_FPS_FORMAT, button.avgFPS);
local minFPSText = format(TITAN_FPS_FORMAT, button.minFPS);
local maxFPSText = format(TITAN_FPS_FORMAT, button.maxFPS);
GameTooltip:AddLine("\n");
GameTooltip:AddLine(TitanUtils_GetHighlightText(TITAN_FPS_TOOLTIP));
GameTooltip:AddDoubleLine(TITAN_FPS_TOOLTIP_CURRENT_FPS, TitanUtils_GetHighlightText(fpsText));
GameTooltip:AddDoubleLine(TITAN_FPS_TOOLTIP_AVG_FPS, TitanUtils_GetHighlightText(avgFPSText));
GameTooltip:AddDoubleLine(TITAN_FPS_TOOLTIP_MIN_FPS, TitanUtils_GetHighlightText(minFPSText));
GameTooltip:AddDoubleLine(TITAN_FPS_TOOLTIP_MAX_FPS, TitanUtils_GetHighlightText(maxFPSText));
endNew system: local L = LibStub("AceLocale-3.0"):GetLocale("Titan", true)
...
-- do some stuff here, initialize variables, functions, etc.
...
-- we finally reach the relevant code where localization strings are needed...
-- FPS tooltip
if ( showFPS ) then
local fpsText = format(L["TITAN_FPS_FORMAT"], button.fps);
local avgFPSText = format(L["TITAN_FPS_FORMAT"], button.avgFPS);
local minFPSText = format(L["TITAN_FPS_FORMAT"], button.minFPS);
local maxFPSText = format(L["TITAN_FPS_FORMAT"], button.maxFPS);
GameTooltip:AddLine("\n");
GameTooltip:AddLine(TitanUtils_GetHighlightText(L["TITAN_FPS_TOOLTIP"]));
GameTooltip:AddDoubleLine(L["TITAN_FPS_TOOLTIP_CURRENT_FPS"], TitanUtils_GetHighlightText(fpsText));
GameTooltip:AddDoubleLine(L["TITAN_FPS_TOOLTIP_AVG_FPS"], TitanUtils_GetHighlightText(avgFPSText));
GameTooltip:AddDoubleLine(L["TITAN_FPS_TOOLTIP_MIN_FPS"], TitanUtils_GetHighlightText(minFPSText));
GameTooltip:AddDoubleLine(L["TITAN_FPS_TOOLTIP_MAX_FPS"], TitanUtils_GetHighlightText(maxFPSText));
endNotes to Authors:If your plugin is using its own localization system and was never referencing a locale string that existed in Titan Panel, then no action is required. You do not have to revamp your entire system, as long as nothing is broken. We do recommend however, that you consider using AceLocale-3.0 for your addon(s), in the future. Properly documenting the "upgrade" procedure is outside the scope of this wiki article, but for more information you may want to have a look at the Ace3 documentation over @ WoWAce.com. Basic introduction to usage (Ace3): http://www.wowace.com/projects/ace3/pages/getting-started/ API/AceLocale-3.0: http://www.wowace.com/projects/ace3/pages/api/ace-locale-3-0/ |
Sign in to add a comment