AceLocale-2.1

From WowAce Wiki
Jump to: navigation, search
Ability FiegnDead.png

This addon has been abandoned by it's author.
Recommended alternatives: AceLocale-2.2

AceLocale-2.1 is a localization library for addons to use to handle proper localization and internationalization. It was intended to be more streamlined than its predecessor, taking advantage of techniques that make it faster and cheaper (memory wise) to use.

See also: AceLocale-2.1_API_Documentation

Overview

AceLocale-2.1 has been divided up into two basic sections. You have the AceLocale object and then translation objects (instances). They have separate methods and perform different tasks. Below is an example of how to use the new architecture that will print either "Good morning" or "Guten Morgen" depending on locale.

3 Steps to Using AceLocale 2.1

After following these following three steps you'll be able to get a properly translated values from your translation objects.

Step 1

Register all your desired locales via AceLocale:RegisterTranslation()

Step 2

Get a translation object via AceLocale:GetInstance()

Step 3

Set the locale either through AceLocale:GetInstance() or L:SetLocale()

Example

MyAddon-enUS.lua

local AceLocale = AceLibrary("AceLocale-2.1")

AceLocale:RegisterTranslation("MyAddon", "enUS", function()
    return {
        ["Good morning"] = "Good morning",
        ["Good evening"] = "Good evening",
        ["Monkey"] = "Monkey",
    }
end)

MyAddon-deDE.lua

local AceLocale = AceLibrary("AceLocale-2.1")

AceLocale:RegisterTranslation("MyAddon", "deDE", function()
    return {
        ["Good morning"] = "Guten Morgen",
        ["Good evening"] = "Guten Abend",
        ["Monkey"] = "Affe",
    }
end)

MyAddon.lua

local L = AceLibrary("AceLocale-2.1"):GetInstance("MyAddon", true)

MyAddon = AceLibrary("AceAddon-2.0"):new()

function MyAddon:OnEnable()
    print(L["Good morning"])
    
end