Babylonian

From Norganna's AddOns

Jump to: navigation, search

What is Babylonian

Babylonian is an embedded addon, which is used by Auctioneer, BeanCounter, Enchantrix, Gatherer, Informant and Itemizer1. It is used to localize these addons.

Note: all addons that currently use Babylonian, use the same version.

As an embedded addon Babylonian does not have a *.toc or *.xml file. The reason being: It's functions are called directly from another addon.Having said this: The Gatherer version of the addon does have a xml file in it's folder (load.xml)

Open Point: Why does the implementation for Gatherer have this xml file, where there is none for the other addons?

How to use Babylonian

If you have made an addon and you want to use Babylonian as your localization addon the following are usefull to know:

Babylonian's functions

  • SetOrder(order): Orders the localization db for the order(= locale) localization (+ the enUS order). And returns this locale to the game.
  • GetOrder(): Gets the localization that is currently used (mainly used to register the localization in Khaos atm)
  • FetchString(stringTable, locale, stringKey): Returns the string found in the stringTable that belongs to the stringKey for the asked locale.
  • GetString(stringTable, stringKey, default): Returns the string stringkey in stringTable and returns default if not found. (Basically it is the same as fetchString, which is used by this function).

What to implement in the files for <your addon>

XML

Since Babylonian is an embedded addon, no GUI changes are needed.

TOC

In your addon's toc file the following line should be incorporated (assuming that your addon, like all current addon's that use Babylonian, have a local copy of it in its folder structure):
Babylonian\Babylonian.lua

LUA

Your lua needs a bit more preparation, since you have to add things to / creat multiple lua-files (Explanation order follows the function explanation order).
Translation Table
First of all you need some translation tables taking the following form: <your addon>Strings.lua:
<your addon>Localizations = {
    enUS = {
        ["SomeStringName"] = "Some String Name";
    }
    deDE = {
        ["SomeStringName"] = "Name einige Zeigenfolger";
    }
    nlNL = {
        ["SomeStringName"] = "Naam van een String";
    }
}
SetOrder
SetOrder is only implemented in the following lua-snippet (note: Pseudo-code is used for all non-essential code, for real implementation examples take a look in the lua code of any of the listed addons):
function setLocale(param, <some other parameter>)
    param = <Get the locale setting for GetOrder>
    if (param == 'default') or (param == 'off') then
        Babylonian.SetOrder()
    else 
        Babylonian.SetOrder(param)
    end
    <some code for e.g. setting things in the chat or in Khaos, often uses the _<SHORT> function>
end
GetOrder
Since the only example where GetOrder is used is linked to Khaos (for Auctioneer) it is skipped for now.
FetchString / GetString
This function is implemented in 2 ways. 1 very short way used only by Gatherer and 1 longer used by the rest. I will show both:

Gatherer Implementation
This is the only implementation that also does not implement GetString in the same function. (GetLocale is a function that determines which locale to use).
function Gatherer.Locale.TrClient(key)
    --Returns the translated string
    return Babylonian.FetchString(GathererLocalizations, GetLocale(), key)
end


Gatherer implements GetString in the 2 following functions: 1) Gatherer.Locale.Tr
function Gatherer.Locale.Tr(key, ...)
    --This function tries to translate the key (localization == false or nill if it could not be
    --translated.
    --After that Gatherer's Translate function does some things with it
    local localization = Babylonian.GetString(GathererLocalizations, key, key)
    return Gatherer.Locale.Translate(localization, ...)
end


2) Gatherer.Locale.TrLocale
function Gatherer.Locale.TrLocale(key)
    -- Return the translation found by GetString 
    return Babylonian.GetString(GathererLocalizations, key, key)
end


Other implementation
This function _<SHORT> (e.g. _AUCT) is called by (among others) SetLocale function (shown above).
function _<SHORT>(stringKey, locale)
    if (locale) then
        if (type(locale) == "string") then
            --Return the searched for string in the language determined by locale.
            return Babylonian.FetchString(<your Addon>Localizations, locale, stringKey);
        else
            --Return the searched for string in the language that has been set
            return Babylonian.FetchString(<your Addon>Localizations, GetLocale(), stringKey);
        end
    elseif (<your Addon>_CustomLocalizations[stringKey]) then
        --If it is some custom localization return that
        return Babylonian.FetchString(<your Addon>Localizations, <your Addon>_CustomLocalizations[stringKey], stringKey)
    else
        --Return the translation found by GetString (or if nothing found return the key to signal an error.
        return Babylonian.GetString(<your Addon>Localizations, stringKey) or stringKey
    end


end

1 The link to Itemizer is striked through since it is currently on ice.
Personal tools
World of Warcraft™ and Blizzard Entertainment™ are trademarks or registered trademarks of Blizzard Entertainment, Inc. in the U.S. and/or other countries.