LibRockLocale-1.0
From WowAce Wiki
| Summary | |
|---|---|
| Lib: RockLocale-1.0 | |
| Localization library | |
| TOC | 2.4 (20400) |
| Category | Libraries |
| Author | ckknight |
| Details | |
| Links | |
| Website | http://www.wowace.com |
| Betas | Ace SVN Zip |
| Changelog | FishEye |
Contents |
[edit]
API Documentation
Note: This documentation is auto-generated. Please note that direct modifications may be overwritten on next autogenerate.
[edit]
:AddTranslations("locale" , func)
[edit]
Arguments
- "locale"
- string - the locale to specify, e.g. "enUS", "deDE", "frFR", "esES", "zhCN", "zhTW", or "koKR".
- func
- function - a function that will return a table. This will be called if the locale you specify is the proper one.
[edit]
Notes
- This is to be called on a LibRockLocale-1.0 namespace.
- For the first (base) locale set you specify, the values can be true, which means "same as the key".
[edit]
Example
local L = Rock("LibRockLocale-1.0"):GetTranslationNamespace("MyAddon")
L:AddTranslations("enUS", function() return {
["Monkey"] = true, -- same as ["Monkey"] = "Monkey"
["House"] = true, -- same as ["House"] = "House"
} end)
L:AddTranslations("deDE", function() return {
["Monkey"] = "Affe",
-- not specifying House
} end)
-- assume we're deDE
assert(L["Monkey"] == "Affe") -- as we specified
assert(L["House"] == "House") -- fallback to the base locale (enUS)
table
[edit]
:GetTranslationNamespace("name" [, tab])
[edit]
Arguments
- "name"
- string - the namespace to request
- tab
- table - the table to populate. This is only if you're declaring a library.
[edit]
Notes
- This is to be called on the LibRockLocale-1.0 library.
- This will create it if not existing already, or it will return what previously existed.
[edit]
Returns
table - The translation namespace.
[edit]
Example
local L = Rock("LibRockLocale-1.0"):GetTranslationNamespace("MyAddon")
[edit]
:HasBaseTranslation(key)
[edit]
Arguments
- key
- boolean - whether the translation exists on the base locale.
[edit]
Notes
- This is to be called on a LibRockLocale-1.0 namespace.
- This is to be called after adding translations.
[edit]
Example
local L = Rock("LibRockLocale-1.0"):GetTranslationNamespace("MyAddon")
L:AddTranslations("enUS", function() return {
["Monkey"] = true, -- same as ["Monkey"] = "Monkey"
["House"] = true, -- same as ["House"] = "House"
} end)
L:AddTranslations("deDE", function() return {
["Monkey"] = "Affe",
-- not specifying House
} end)
-- assume we're deDE
assert(L:HasBaseTranslation("Monkey")) -- as we specified
assert(L["House"] == "House")
assert(L:HasBaseTranslation("House")) -- because it does exist, just not on the current locale.
[edit]
:HasTranslation(key)
[edit]
Arguments
- key
- boolean or string - false if the translation doesn't exist, otherwise it returns the translation.
[edit]
Notes
- This is to be called on a LibRockLocale-1.0 namespace.
- This is to be called after adding translations.
[edit]
Example
local L = Rock("LibRockLocale-1.0"):GetTranslationNamespace("MyAddon")
L:AddTranslations("enUS", function() return {
["Monkey"] = true, -- same as ["Monkey"] = "Monkey"
["House"] = true, -- same as ["House"] = "House"
} end)
L:AddTranslations("deDE", function() return {
["Monkey"] = "Affe",
-- not specifying House
} end)
-- assume we're deDE
assert(L:HasTranslation("Monkey") == "Affe") -- as we specified
assert(L["House"] == "House")
assert(not L:HasTranslation("House")) -- because not specified by the specific locale.
[edit]
:HasTranslationNamespace("name")
[edit]
Arguments
- "name"
- string - the namespace to check
[edit]
Notes
- This is to be called on the LibRockLocale-1.0 library.
[edit]
Returns
boolean - whether the namespace has been created or not
[edit]
Example
local has = Rock("LibRockLocale-1.0"):HasTranslationNamespace("MyAddon")
[edit]
:SetStrictness(strict)
[edit]
Arguments
- strict
- boolean - whether to be strict or not. false by default.
[edit]
Notes
- This is to be called on a LibRockLocale-1.0 namespace.
- This is to be called after adding translations.
[edit]
Example
local L = Rock("LibRockLocale-1.0"):GetTranslationNamespace("MyAddon")
L:AddTranslations("enUS", function() return {
["Monkey"] = true, -- same as ["Monkey"] = "Monkey"
["House"] = true, -- same as ["House"] = "House"
} end)
L:AddTranslations("deDE", function() return {
["Monkey"] = "Affe",
-- not specifying House
} end)
L:SetStrictness(true)
-- assume we're deDE
assert(L["Monkey"] == "Affe") -- as we specified
local house = L["House"] -- pops an error, since we don't have the translation
[edit]
:__index("key")
[edit]
Arguments
- "key"
- string - the translation key
[edit]
Notes
- This is to be accessed on a LibRockLocale-1.0 namespace.
- This is to be accessed after adding translations.
- This will error if the translation doesn't exist
[edit]
Returns
string - the translated value
[edit]
Example
local L = Rock("LibRockLocale-1.0"):GetTranslationNamespace("MyAddon")
L:AddTranslations("enUS", function() return {
["Monkey"] = true, -- same as ["Monkey"] = "Monkey"
["House"] = true, -- same as ["House"] = "House"
} end)
L:AddTranslations("deDE", function() return {
["Monkey"] = "Affe",
-- not specifying House
} end)
-- assume we're deDE
assert(L["Monkey"] == "Affe") -- calling :__index("Monkey")
assert(L["House"] == "House") -- calling :__index("House")
[edit]
:reverse()
[edit]
Notes
- This is to be accessed on a LibRockLocale-1.0 namespace.
- This is to be accessed after adding translations.
- Unlike normal indexing, this will not error if a translation does not exist.
- This does follow the rules specified by :SetStrictness
[edit]
Example
local L = Rock("LibRockLocale-1.0"):GetTranslationNamespace("MyAddon")
L:AddTranslations("enUS", function() return {
["Monkey"] = true, -- same as ["Monkey"] = "Monkey"
["House"] = true, -- same as ["House"] = "House"
} end)
L:AddTranslations("deDE", function() return {
["Monkey"] = "Affe",
-- not specifying House
} end)
-- assume we're deDE
assert(L.reverse["Affe"] == "Monkey") -- because L["Monkey"] == "Affe"
assert(L.reverse["House"] == "House") -- because non-strict, L["House"] == "House", so the inverse is true
-- more generally:
assert(L.reverse[L[anything] ] == anything)
assert(L[L.reverse[anything] ] == anything)

