LibRockLocale-1.0

From WowAce Wiki
Jump to: navigation, search

API Documentation

Note: This documentation is auto-generated. Please note that direct modifications may be overwritten on next autogenerate.

:AddTranslations("locale" , func)

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.

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".

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

:GetTranslationNamespace("name" [, tab])

Arguments

"name"
string - the namespace to request
tab
table - the table to populate. This is only if you're declaring a library.

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.

Returns

table - The translation namespace.

Example

local L = Rock("LibRockLocale-1.0"):GetTranslationNamespace("MyAddon")

:HasBaseTranslation(key)

Arguments

key
boolean - whether the translation exists on the base locale.

Notes

  • This is to be called on a LibRockLocale-1.0 namespace.
  • This is to be called after adding translations.

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.

:HasTranslation(key)

Arguments

key
boolean or string - false if the translation doesn't exist, otherwise it returns the translation.

Notes

  • This is to be called on a LibRockLocale-1.0 namespace.
  • This is to be called after adding translations.

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.

:HasTranslationNamespace("name")

Arguments

"name"
string - the namespace to check

Notes

  • This is to be called on the LibRockLocale-1.0 library.

Returns

boolean - whether the namespace has been created or not

Example

local has = Rock("LibRockLocale-1.0"):HasTranslationNamespace("MyAddon")

:SetStrictness(strict)

Arguments

strict
boolean - whether to be strict or not. false by default.

Notes

  • This is to be called on a LibRockLocale-1.0 namespace.
  • This is to be called after adding translations.

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

:__index("key")

Arguments

"key"
string - the translation key

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

Returns

string - the translated value

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")

:reverse()

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

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)