portoform barrier and division by zero fix, framework update
This commit is contained in:
+305
-75
@@ -1,9 +1,7 @@
|
||||
|
||||
--todo: GetText(addonId, phraseId)
|
||||
--todo: SetText(addonId, phraseId, FontString, ...)
|
||||
--todo: need to send a callback when setting a new language, this will be used by the volatile menu to refresh the menu
|
||||
|
||||
--[=[
|
||||
DetailsFramework.Language.Register(addonId, languageId, gameLanguageOnly)
|
||||
DetailsFramework.Language.Register(addonId, languageId[, gameLanguageOnly])
|
||||
create a language table within an addon namespace
|
||||
@addonId: an identifier, can be any table or string, will be used when getting the table with phrase translations, example: "DetailsLocalization", "Details", "PlaterLoc", _G.Plater
|
||||
@languageId: game languages: "deDE", "enUS", "esES", "esMX", "frFR", "itIT", "koKR", "ptBR", "ruRU", "zhCN", "zhTW", or any other value if 'gameLanguageOnly' is false (default)
|
||||
@@ -19,7 +17,7 @@
|
||||
local newLanguageTable = DetailsFramework.Language.Register(_G.Details, "valyrianValyria", false)
|
||||
newLanguageTable["STRING_MY_PHRASE"] = "ñuha udrir"
|
||||
|
||||
DetailsFramework.Language.GetLanguageTable(addonId, languageId)
|
||||
DetailsFramework.Language.GetLanguageTable(addonId[, languageId])
|
||||
get the languageTable for the requested languageId within the addon namespace
|
||||
if languageId is not passed, uses the current language set for the addonId
|
||||
the default languageId for the addon is the first language registered with DetailsFramework.Language.Register()
|
||||
@@ -36,18 +34,24 @@
|
||||
local languageTable = DetailsFramework.Language.GetLanguageTable("Details", "valyrianValyria")
|
||||
fontString:SetText(languageTable["STRING_MY_PHRASE"])
|
||||
|
||||
DetailsFramework.Language.GetText(addonId, phraseId[, silent])
|
||||
get a text from a registered addonId and phraseId
|
||||
@addonId: an identifier, can be any table or string, will be used when getting the table with phrase translations, example: "DetailsLocalization", "Details", "PlaterLoc", _G.Plater
|
||||
@phraseId: any string to identify the a translated text, example: phraseId: "OPTIONS_FRAME_WIDTH" text: "Adjust the Width of the frame."
|
||||
@silent: if true won't error on invalid phrase text and instead use the phraseId as the text, it will still error on invalid addonId
|
||||
|
||||
DetailsFramework.Language.SetCurrentLanguage(addonId, languageId)
|
||||
set the language used by default when retriving a languageTable with DF.Language.GetLanguageTable() and not passing the second argument (languageId) within the call
|
||||
use this in combination with a savedVariable to use a language of the user choice
|
||||
@addonId: an identifier, can be any table or string, will be used when getting the table with phrase translations, example: "DetailsLocalization", "Details", "PlaterLoc", _G.Plater
|
||||
@languageId: game languages: "deDE", "enUS", "esES", "esMX", "frFR", "itIT", "koKR", "ptBR", "ruRU", "zhCN", "zhTW", or any other value if 'gameLanguageOnly' is false (default)
|
||||
|
||||
DetailsFramework.Language.RegisterFontString(addonId, fontString, phraseId, silent, ...)
|
||||
DetailsFramework.Language.RegisterFontString(addonId, fontString, phraseId[, silent[, ...]])
|
||||
when setting a languageId with DetailsFramework.Language.SetCurrentLanguage(), automatically change the text of all registered FontStrings
|
||||
@addonId: an identifier, can be any table or string, will be used when getting the table with phrase translations, example: "DetailsLocalization", "Details", "PlaterLoc", _G.Plater
|
||||
@fontString: a UIObject FontString
|
||||
@phraseId: any string to identify the a translated text, example: "My Phrase", "STRING_TEXT_LENGTH", text: "This is my phrase"
|
||||
@silent: if true won't error on invalid phrase text and instead use the phraseId as the text, it will still error on invalid addonId
|
||||
@silent: if true won't error on invalid phrase text and instead use the phraseId as the text, it will still error on invalid addonId and fontString
|
||||
@vararg: arguments to pass for format(text, ...)
|
||||
|
||||
DetailsFramework.Language.UpdateFontStringArguments(addonId, fontString, ...)
|
||||
@@ -57,6 +61,24 @@
|
||||
@addonId: an identifier, can be any table or string, will be used when getting the table with phrase translations, example: "DetailsLocalization", "Details", "PlaterLoc", _G.Plater
|
||||
@fontString: a UIObject FontString
|
||||
@vararg: arguments to pass for format(text, ...)
|
||||
|
||||
DetailsFramework.Language.RegisterTableKey(addonId, table, key, phraseId[, silent[, ...]])
|
||||
when setting a languageId with DetailsFramework.Language.SetCurrentLanguage(), automatically change the text of all registered tables, table[key] = 'new translated text'
|
||||
@addonId: an identifier, can be any table or string, will be used when getting the table with phrase translations, example: "DetailsLocalization", "Details", "PlaterLoc", _G.Plater
|
||||
@table: a lua table
|
||||
@key: any value except nil or boolean
|
||||
@phraseId: any string to identify the a translated text, example: token: "OPTIONS_FRAME_WIDTH" text: "Adjust the Width of the frame."
|
||||
@silent: if true won't error on invalid phrase text or table already registered, it will still error on invalid addonId, table, key and phraseId
|
||||
@vararg: arguments to pass for format(text, ...)
|
||||
|
||||
DetailsFramework.Language.UpdateTableKeyArguments(addonId, table, key, ...)
|
||||
--same as UpdateFontStringArguments() but for table keys
|
||||
@addonId: an identifier, can be any table or string, will be used when getting the table with phrase translations, example: "DetailsLocalization", "Details", "PlaterLoc", _G.Plater
|
||||
@table: a lua table
|
||||
@key: any value except nil or boolean
|
||||
@vararg: arguments to pass for format(text, ...)
|
||||
|
||||
|
||||
--]=]
|
||||
|
||||
local DF = _G["DetailsFramework"]
|
||||
@@ -81,12 +103,14 @@ local supportedGameLanguages = {
|
||||
}
|
||||
|
||||
local functionSignature = {
|
||||
["RegisterLanguage"] = "RegisterLanguage(addonID, languageID [, gameLanguageOnly])",
|
||||
["RegisterLanguage"] = "RegisterLanguage(addonID, languageID[, gameLanguageOnly])",
|
||||
["SetCurrentLanguage"] = "SetCurrentLanguage(addonID, languageID)",
|
||||
["GetLanguageTable"] = "GetLanguageTable(addonID [, languageID])",
|
||||
["RegisterFontString"] = "RegisterFontString(addonID, fontString, phraseID [, silent] [, ...]])",
|
||||
["GetLanguageTable"] = "GetLanguageTable(addonID[, languageID])",
|
||||
["RegisterFontString"] = "RegisterFontString(addonID, fontString, phraseID[, silent[, ...]])",
|
||||
["UpdateFontStringArguments"] = "UpdateFontStringArguments(addonID, fontString, ...)",
|
||||
["GetText"] = "GetText(addonID, phraseID [, silent])",
|
||||
["RegisterTableKey"] = "RegisterTableKey(addonId, table, key, phraseId[[, silent[, ...]])",
|
||||
["GetText"] = "GetText(addonID, phraseID[, silent])",
|
||||
["UpdateTableKeyArguments"] = "UpdateTableKeyArguments(addonId, table, key, ...)",
|
||||
}
|
||||
|
||||
local functionCallPath = {
|
||||
@@ -96,6 +120,8 @@ local functionCallPath = {
|
||||
["RegisterFontString"] = "DetailsFramework.Language.RegisterFontString",
|
||||
["UpdateFontStringArguments"] = "DetailsFramework.Language.UpdateFontStringArguments",
|
||||
["GetText"] = "DetailsFramework.Language.GetText",
|
||||
["RegisterTableKey"] = "DetailsFramework.Language.RegisterTableKey",
|
||||
["UpdateTableKeyArguments"] = "DetailsFramework.Language.UpdateTableKeyArguments",
|
||||
}
|
||||
|
||||
local errorText = {
|
||||
@@ -107,16 +133,20 @@ local errorText = {
|
||||
["PhraseIDNotRegistered"] = "phraseID not registered",
|
||||
["FontString"] = "require a FontString on #%d argument",
|
||||
["FontStringNotRegistered"] = "FontString not registered yet",
|
||||
["TableKeyNotRegistered"] = "table not registered yet",
|
||||
["KeyNotRegistered"] = "key not registered yet",
|
||||
["InvalidTable"] = "require a table on #%d argument",
|
||||
["InvalidTableKey"] = "require a table key on #%d argument",
|
||||
["TableKeyAlreadyRegistered"] = "table already registered", --not in use
|
||||
}
|
||||
|
||||
|
||||
--create languages namespace
|
||||
DF.Language = {
|
||||
RegisteredNamespaces = {},
|
||||
}
|
||||
--create language namespace
|
||||
DF.Language = DF.Language or {version = 1}
|
||||
DF.Language.RegisteredNamespaces = DF.Language.RegisteredNamespaces or {}
|
||||
|
||||
|
||||
--internal functions
|
||||
|
||||
local isValid_AddonID = function(addonId)
|
||||
if (type(addonId) ~= "string" and type(addonId) ~= "table") then
|
||||
return false
|
||||
@@ -146,10 +176,15 @@ local getOrCreateAddonNamespace = function(addonId, languageId)
|
||||
if (not addonNamespaceTable) then
|
||||
addonNamespaceTable = {
|
||||
addonId = addonId,
|
||||
|
||||
--by default, the current language is the first registered language
|
||||
currentLanguageId = languageId,
|
||||
languages = {},
|
||||
fontStrings = {},
|
||||
tableKeys = setmetatable({}, {__mode = "k"}),
|
||||
|
||||
--set when the first language table is registered
|
||||
defaultLanguageTable = nil,
|
||||
}
|
||||
DF.Language.RegisteredNamespaces[addonId] = addonNamespaceTable
|
||||
end
|
||||
@@ -181,6 +216,8 @@ local getCurrentLanguageId = function(addonNamespaceTable)
|
||||
return addonNamespaceTable.currentLanguageId
|
||||
end
|
||||
|
||||
--if invalid, the __index from the metatable get the value from the first registered table
|
||||
--will return nil if the languageTable is from the first registered language
|
||||
local getTextFromLangugeTable = function(languageTable, phraseId)
|
||||
return languageTable[phraseId]
|
||||
end
|
||||
@@ -190,8 +227,8 @@ local getRegisteredFontStrings = function(addonNamespaceTable)
|
||||
end
|
||||
|
||||
local getText = function(addonNamespaceTable, phraseId)
|
||||
local currentLanguageId = getCurrentLanguageId(addonNamespaceTable) --never nil
|
||||
local languageTable = getLanguageTable(addonNamespaceTable, currentLanguageId) --can be nil if the languageId isn't registered yet
|
||||
local currentLanguageId = getCurrentLanguageId(addonNamespaceTable)
|
||||
local languageTable = getLanguageTable(addonNamespaceTable, currentLanguageId)
|
||||
|
||||
--if the languageTable is invalid, let the function caller handle it
|
||||
--note: languageTable is always valid when the callstack started at from DF.Language.SetCurrentLanguage
|
||||
@@ -199,7 +236,9 @@ local getText = function(addonNamespaceTable, phraseId)
|
||||
return false
|
||||
end
|
||||
|
||||
local text = getTextFromLangugeTable(languageTable, phraseId)
|
||||
--by using getTextFromLangugeTable the metatable will get the default of the first registered language
|
||||
--local text = getTextFromLangugeTable(languageTable, phraseId)
|
||||
local text = rawget(languageTable, phraseId)
|
||||
if (isValid_Text(text)) then
|
||||
return text
|
||||
end
|
||||
@@ -208,18 +247,24 @@ local getText = function(addonNamespaceTable, phraseId)
|
||||
local clientLanguage = GetLocale()
|
||||
if (currentLanguageId ~= clientLanguage) then
|
||||
languageTable = getLanguageTable(addonNamespaceTable, clientLanguage)
|
||||
text = getTextFromLangugeTable(languageTable, phraseId)
|
||||
if (isValid_Text(text)) then
|
||||
return text
|
||||
if (languageTable) then
|
||||
--text = getTextFromLangugeTable(languageTable, phraseId)
|
||||
text = rawget(languageTable, phraseId)
|
||||
if (isValid_Text(text)) then
|
||||
return text
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--attempt to get from english
|
||||
if (currentLanguageId ~= CONST_LANGAGEID_ENUS and clientLanguage ~= CONST_LANGAGEID_ENUS) then
|
||||
languageTable = getLanguageTable(addonNamespaceTable, CONST_LANGAGEID_ENUS)
|
||||
text = getTextFromLangugeTable(languageTable, phraseId)
|
||||
if (isValid_Text(text)) then
|
||||
return text
|
||||
if (languageTable) then
|
||||
--text = getTextFromLangugeTable(languageTable, phraseId)
|
||||
text = rawget(languageTable, phraseId)
|
||||
if (isValid_Text(text)) then
|
||||
return text
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -227,6 +272,14 @@ local getText = function(addonNamespaceTable, phraseId)
|
||||
end
|
||||
|
||||
local setLanguageTable = function(addonNamespaceTable, languageId, languageTable)
|
||||
local isFirstLanguage = not next(addonNamespaceTable.languages)
|
||||
if (isFirstLanguage) then
|
||||
addonNamespaceTable.defaultLanguageTable = languageTable
|
||||
else
|
||||
local defaultLanguageMetatable = {__index = function(table, key) return addonNamespaceTable.defaultLanguageTable[key] or key end}
|
||||
setmetatable(languageTable, defaultLanguageMetatable)
|
||||
end
|
||||
|
||||
addonNamespaceTable.languages[languageId] = languageTable
|
||||
return languageTable
|
||||
end
|
||||
@@ -235,11 +288,7 @@ local setCurrentLanguageId = function(addonNamespaceTable, languageId)
|
||||
addonNamespaceTable.currentLanguageId = languageId
|
||||
end
|
||||
|
||||
local getFontStringTable = function(addonNamespaceTable, fontString)
|
||||
return addonNamespaceTable.fontStrings[fontString]
|
||||
end
|
||||
|
||||
local parseFontStringArguments = function(...)
|
||||
local parseArguments = function(...)
|
||||
local argumentAmount = select("#", ...)
|
||||
if (argumentAmount > 0) then
|
||||
return {...}
|
||||
@@ -248,12 +297,30 @@ local parseFontStringArguments = function(...)
|
||||
end
|
||||
end
|
||||
|
||||
local updateFontStringTable_Arguments = function(fontStringTable, ...)
|
||||
fontStringTable.arguments = parseFontStringArguments(...)
|
||||
--hold information about a localization, used by registered fontStrings and keyTables, has .phraesId, .arguments and .key (on keyTables)
|
||||
local createPhraseInfoTable = function(phraseId, key, ...)
|
||||
return {phraseId = phraseId, key = key, arguments = parseArguments(...)}
|
||||
end
|
||||
|
||||
local updateFontStringTable_PhraseId = function(fontStringTable, phraseId)
|
||||
fontStringTable.phraseId = phraseId
|
||||
local updatePhraseInfoArguments = function(phraseInfoTable, ...)
|
||||
phraseInfoTable.arguments = parseArguments(...)
|
||||
end
|
||||
|
||||
--get a phraseInfo and text returning a formatted text using arguments if they exists
|
||||
local getFormattedText = function(phraseInfoTable, text)
|
||||
if (phraseInfoTable.arguments) then
|
||||
return format(text, unpack(phraseInfoTable.arguments))
|
||||
else
|
||||
return text
|
||||
end
|
||||
end
|
||||
|
||||
local updateFontStringTable_PhraseId = function(phraseInfoTable, phraseId)
|
||||
phraseInfoTable.phraseId = phraseId
|
||||
end
|
||||
|
||||
local getFontStringPhraseInfoTable = function(addonNamespaceTable, fontString)
|
||||
return addonNamespaceTable.fontStrings[fontString]
|
||||
end
|
||||
|
||||
local setFontString_InternalMembers = function(fontString, addonId, phraseId, arguments)
|
||||
@@ -262,12 +329,9 @@ local setFontString_InternalMembers = function(fontString, addonId, phraseId, ar
|
||||
fontString.__languageArguments = arguments or fontString.__languageArguments
|
||||
end
|
||||
|
||||
local setFontString_Text = function(fontString, fontStringTable, text)
|
||||
if (fontStringTable.arguments) then
|
||||
fontString:SetText(format(text, unpack(fontStringTable.arguments)))
|
||||
else
|
||||
fontString:SetText(text)
|
||||
end
|
||||
local setFontString_Text = function(fontString, phraseInfoTable, text)
|
||||
local formattedText = getFormattedText(phraseInfoTable, text)
|
||||
fontString:SetText(formattedText)
|
||||
end
|
||||
|
||||
--this method only exists on registered FontStrings
|
||||
@@ -275,39 +339,109 @@ local fontStringMethod_SetTextByPhraseID = function(fontString, phraseId, ...)
|
||||
local addonId = fontString.__languageAddonId
|
||||
local addonNamespaceTable = getAddonNamespace(addonId)
|
||||
|
||||
local fontStringTable = getFontStringTable(addonNamespaceTable, fontString)
|
||||
updateFontStringTable_PhraseId(fontStringTable, phraseId)
|
||||
updateFontStringTable_Arguments(fontStringTable, ...)
|
||||
setFontString_InternalMembers(fontString, addonId, phraseId, fontStringTable.arguments)
|
||||
local phraseInfoTable = getFontStringPhraseInfoTable(addonNamespaceTable, fontString)
|
||||
updateFontStringTable_PhraseId(phraseInfoTable, phraseId)
|
||||
updatePhraseInfoArguments(phraseInfoTable, ...)
|
||||
setFontString_InternalMembers(fontString, addonId, phraseId, phraseInfoTable.arguments)
|
||||
|
||||
local text = getText(addonNamespaceTable, phraseId)
|
||||
setFontString_Text(fontString, fontStringTable, text)
|
||||
setFontString_Text(fontString, phraseInfoTable, text)
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
local registerFontString = function(addonNamespaceTable, fontString, phraseId, ...)
|
||||
local fontStringTable = {phraseId = phraseId}
|
||||
fontStringTable.arguments = parseFontStringArguments(...)
|
||||
|
||||
addonNamespaceTable.fontStrings[fontString] = fontStringTable
|
||||
local phraseInfoTable = createPhraseInfoTable(phraseId, nil, ...)
|
||||
addonNamespaceTable.fontStrings[fontString] = phraseInfoTable
|
||||
|
||||
--save internal information about the language directly in the FontString
|
||||
setFontString_InternalMembers(fontString, addonNamespaceTable.addonId, phraseId, fontStringTable.arguments)
|
||||
setFontString_InternalMembers(fontString, addonNamespaceTable.addonId, phraseId, phraseInfoTable.arguments)
|
||||
|
||||
fontString.SetTextByPhraseID = fontStringMethod_SetTextByPhraseID
|
||||
|
||||
return fontStringTable
|
||||
return phraseInfoTable
|
||||
end
|
||||
|
||||
--iterate among all registered fontStrings of an addon namespace and set the new text on them
|
||||
local updateAllRegisteredFontStringText = function(addonNamespaceTable, languageTable)
|
||||
local updateAllRegisteredFontStringText = function(addonNamespaceTable)
|
||||
local fontStrings = getRegisteredFontStrings(addonNamespaceTable)
|
||||
for fontString, fontStringTable in pairs(fontStrings) do
|
||||
local phraseId = fontStringTable.phraseId
|
||||
for fontString, phraseInfoTable in pairs(fontStrings) do
|
||||
local phraseId = phraseInfoTable.phraseId
|
||||
--note: text is always valid when the callstack started at from DF.Language.SetCurrentLanguage
|
||||
local text = getText(addonNamespaceTable, phraseId)
|
||||
setFontString_Text(fontString, fontStringTable, text)
|
||||
setFontString_Text(fontString, phraseInfoTable, text)
|
||||
end
|
||||
end
|
||||
|
||||
--internal tableKey looks like:
|
||||
--addonNamespaceTable.tableKeys = {} -> this table is a weaktable 'k'
|
||||
--addonNamespaceTable.tableKeys[table] = {} -> table is a table from code elsewhere, it is used as a key for the internal code here, table created is what stores the keys
|
||||
--addonNamespaceTable.tableKeys[table][key] -> key is the key from the table elsewhere which points to a string
|
||||
--addonNamespaceTable.tableKeys[table][key] = {phraseId = phraseId, arguments = {...}, key = key}
|
||||
|
||||
--when registring a tableKey in practice, look like:
|
||||
--Details.StoredStrings = {}; Details.StoredStrings["Height"] = "height": table is 'Details.StoredStrings' key is "Height"
|
||||
--registerTableKey(_, Details.StoredStrings, "Height", _, _)
|
||||
|
||||
local setTableKey_Text = function(table, key, phraseInfoTable, text)
|
||||
local formattedText = getFormattedText(phraseInfoTable, text)
|
||||
table[key] = formattedText
|
||||
end
|
||||
|
||||
local getTableKeyTable = function(addonNamespaceTable, table)
|
||||
return addonNamespaceTable.tableKeys[table]
|
||||
end
|
||||
|
||||
--get the phraseInfo from the addon namespace
|
||||
local getTableKeyPhraseInfoTable = function(addonNamespaceTable, table, key)
|
||||
return addonNamespaceTable.tableKeys[table][key]
|
||||
end
|
||||
|
||||
--get the phraseInfo from the tableKey
|
||||
local getPhraseInfoFromTableKey = function(tableKeyTable, key)
|
||||
return tableKeyTable[key]
|
||||
end
|
||||
|
||||
local isTableKeyRegistered = function(addonNamespaceTable, table)
|
||||
return getTableKeyTable(addonNamespaceTable, table) and true
|
||||
end
|
||||
|
||||
--return true if the phraseInfo is present in the tableKey
|
||||
local isKeyRegisteredInTableKey = function(tableKeyTable, key)
|
||||
return getPhraseInfoFromTableKey(tableKeyTable, key) and true
|
||||
end
|
||||
|
||||
local getRegisteredTableKeys = function(addonNamespaceTable)
|
||||
return addonNamespaceTable.tableKeys
|
||||
end
|
||||
|
||||
local registerTableKeyTable = function(addonNamespaceTable, table, tableKeyTable)
|
||||
addonNamespaceTable.tableKeys[table] = tableKeyTable
|
||||
end
|
||||
|
||||
local registerTableKey = function(addonNamespaceTable, table, key, phraseId, ...)
|
||||
local tableKeyTable = getTableKeyTable(addonNamespaceTable, table)
|
||||
if (not tableKeyTable) then
|
||||
tableKeyTable = {}
|
||||
registerTableKeyTable(addonNamespaceTable, table, tableKeyTable)
|
||||
end
|
||||
|
||||
--create a table for this table key as a table can hold several keys with localization strings
|
||||
local phraseInfoTable = createPhraseInfoTable(phraseId, key, ...)
|
||||
tableKeyTable[key] = phraseInfoTable
|
||||
return tableKeyTable
|
||||
end
|
||||
|
||||
--iterate among all registered tableKey of an addon namespace and set the new text on them
|
||||
local updateAllRegisteredTableKeyText = function(addonNamespaceTable)
|
||||
local tableKeys = getRegisteredTableKeys(addonNamespaceTable)
|
||||
for table, tableKeyTable in pairs(tableKeys) do
|
||||
for key, phraseInfoTable in pairs(tableKeyTable) do
|
||||
local phraseId = phraseInfoTable.phraseId
|
||||
--note: text is always valid when the callstack started at from DF.Language.SetCurrentLanguage
|
||||
local text = getText(addonNamespaceTable, phraseId)
|
||||
setTableKey_Text(table, key, phraseInfoTable, text)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -386,16 +520,46 @@ function DF.Language.SetCurrentLanguage(addonId, languageId)
|
||||
|
||||
setCurrentLanguageId(languageId)
|
||||
|
||||
--go into the registered FontStrings and change their text
|
||||
updateAllRegisteredFontStringText(addonNamespaceTable, languageTable)
|
||||
--go into the registered FontStrings and KeyTables and change their text
|
||||
updateAllRegisteredFontStringText(addonNamespaceTable)
|
||||
updateAllRegisteredTableKeyText(addonNamespaceTable)
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
--@addonId: an identifier, can be any table or string, will be used when getting the table with phrase translations, example: "DetailsLocalization", "Details", "PlaterLoc", _G.Plater
|
||||
--@phraseId: any string to identify the a translated text, example: phraseId: "OPTIONS_FRAME_WIDTH" text: "Adjust the Width of the frame."
|
||||
--@silent: if true won't error on invalid phrase text and instead use the phraseId as the text, it will still error on invalid addonId
|
||||
function DF.Language.GetText(addonId, phraseId, silent)
|
||||
if (not isValid_AddonID(addonId)) then
|
||||
error(functionCallPath["GetText"] .. ": " .. format(errorText["AddonID"], 1) .. ", use: " .. functionSignature["GetText"] .. ".")
|
||||
|
||||
elseif (not isValid_PhraseID(phraseId)) then
|
||||
error(functionCallPath["GetText"] .. ": " .. format(errorText["PhraseID"], 2) .. ", use: " .. functionSignature["GetText"] .. ".")
|
||||
end
|
||||
|
||||
local addonNamespaceTable = getAddonNamespace(addonId)
|
||||
if (not addonNamespaceTable) then
|
||||
error(functionCallPath["GetText"] .. ": " .. errorText["NoLanguages"] .. ", use: " .. functionSignature["RegisterLanguage"] .. ".")
|
||||
end
|
||||
|
||||
local text = getText(addonNamespaceTable, phraseId)
|
||||
if (isValid_Text(text)) then
|
||||
return text
|
||||
end
|
||||
|
||||
if (not silent) then
|
||||
error(functionCallPath["GetText"] .. ": " .. errorText["PhraseIDNotRegistered"] .. ", use: " .. functionSignature["GetLanguageTable"] .. "['PhraseID'] = 'translated text'.")
|
||||
end
|
||||
|
||||
return phraseId
|
||||
end
|
||||
|
||||
|
||||
--@addonId: an identifier, can be any table or string, will be used when getting the table with phrase translations, example: "DetailsLocalization", "Details", "PlaterLoc", _G.Plater
|
||||
--@fontString: a UIObject FontString
|
||||
--@phraseId: any string to identify the a translated text, example: token: "OPTIONS_FRAME_WIDTH" text: "Adjust the Width of the frame."
|
||||
--@silent: if true won't error on invalid phrase text and instead use the phraseId as the text, it will still error on invalid addonId
|
||||
--@silent: if true won't error on invalid phrase text and instead use the phraseId as the text, it will still error on invalid addonId and fontString
|
||||
--@vararg: arguments to pass for format(text, ...)
|
||||
function DF.Language.RegisterFontString(addonId, fontString, phraseId, silent, ...)
|
||||
if (not isValid_AddonID(addonId)) then
|
||||
@@ -448,42 +612,108 @@ function DF.Language.UpdateFontStringArguments(addonId, fontString, ...)
|
||||
error(functionCallPath["UpdateFontStringArguments"] .. ": " .. format(errorText["FontString"], 2) .. ", use: " .. functionSignature["UpdateFontStringArguments"] .. ".")
|
||||
end
|
||||
|
||||
local fontStringTable = getFontStringTable(addonNamespaceTable, fontString)
|
||||
if (not fontStringTable) then
|
||||
local phraseInfoTable = getFontStringPhraseInfoTable(addonNamespaceTable, fontString)
|
||||
if (not phraseInfoTable) then
|
||||
error(functionCallPath["UpdateFontStringArguments"] .. ": " .. errorText["FontStringNotRegistered"] .. ", use: " .. functionSignature["RegisterFontString"] .. ".")
|
||||
end
|
||||
updateFontStringTable_Arguments(fontStringTable, ...)
|
||||
updatePhraseInfoArguments(phraseInfoTable, ...)
|
||||
|
||||
local text = getText(addonNamespaceTable, fontStringTable.phraseId)
|
||||
setFontString_Text(fontString, fontStringTable, text)
|
||||
local text = getText(addonNamespaceTable, phraseInfoTable.phraseId)
|
||||
setFontString_Text(fontString, phraseInfoTable, text)
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
--@addonId: an identifier, can be any table or string, will be used when getting the table with phrase translations, example: "DetailsLocalization", "Details", "PlaterLoc", _G.Plater
|
||||
--@phraseId: any string to identify the a translated text, example: phraseId: "OPTIONS_FRAME_WIDTH" text: "Adjust the Width of the frame."
|
||||
--@silent: if true won't error on invalid phrase text and instead use the phraseId as the text, it will still error on invalid addonId
|
||||
function DF.Language.GetText(addonId, phraseId, silent)
|
||||
--@table: a lua table
|
||||
--@key: any value except nil or boolean
|
||||
--@phraseId: any string to identify the a translated text, example: token: "OPTIONS_FRAME_WIDTH" text: "Adjust the Width of the frame."
|
||||
--@silent: if true won't error on invalid phrase text or table already registered, it will still error on invalid addonId, table, key and phraseId
|
||||
--@vararg: arguments to pass for format(text, ...)
|
||||
function DF.Language.RegisterTableKey(addonId, table, key, phraseId, silent, ...)
|
||||
if (not isValid_AddonID(addonId)) then
|
||||
error(functionCallPath["GetText"] .. ": " .. format(errorText["AddonID"], 1) .. ", use: " .. functionSignature["GetText"] .. ".")
|
||||
error(functionCallPath["RegisterTableKey"] .. ": " .. format(errorText["AddonID"], 1) .. ", use: " .. functionSignature["RegisterTableKey"] .. ".")
|
||||
end
|
||||
|
||||
elseif (not isValid_PhraseID(phraseId)) then
|
||||
error(functionCallPath["GetText"] .. ": " .. format(errorText["PhraseID"], 2) .. ", use: " .. functionSignature["GetText"] .. ".")
|
||||
if (type(table) ~= "table") then
|
||||
error(functionCallPath["RegisterTableKey"] .. ": " .. format(errorText["InvalidTable"], 2) .. ", use: " .. functionSignature["RegisterTableKey"] .. ".")
|
||||
end
|
||||
|
||||
if (key == nil or type(key) == "boolean") then
|
||||
error(functionCallPath["RegisterTableKey"] .. ": " .. format(errorText["InvalidTableKey"], 3) .. ", use: " .. functionSignature["RegisterTableKey"] .. ".")
|
||||
end
|
||||
|
||||
if (not isValid_PhraseID(phraseId)) then
|
||||
error(functionCallPath["RegisterTableKey"] .. ": " .. format(errorText["PhraseID"], 4) .. ", use: " .. functionSignature["RegisterTableKey"] .. ".")
|
||||
end
|
||||
|
||||
local addonNamespaceTable = getAddonNamespace(addonId)
|
||||
if (not addonNamespaceTable) then
|
||||
error(functionCallPath["GetText"] .. ": " .. errorText["NoLanguages"] .. ", use: " .. functionSignature["RegisterLanguage"] .. ".")
|
||||
error(functionCallPath["RegisterTableKey"] .. ": " .. errorText["NoLanguages"] .. ", use: " .. functionSignature["RegisterLanguage"] .. ".")
|
||||
end
|
||||
|
||||
local tableKeyTable = registerTableKey(addonNamespaceTable, table, key, phraseId, ...)
|
||||
|
||||
local text = getText(addonNamespaceTable, phraseId)
|
||||
if (isValid_Text(text)) then
|
||||
return text
|
||||
if (not isValid_Text(text)) then
|
||||
if (not silent) then
|
||||
error(functionCallPath["RegisterTableKey"] .. ": " .. errorText["PhraseIDNotRegistered"] .. ", use: " .. functionSignature["GetLanguageTable"] .. "['PhraseID'] = 'translated text'.")
|
||||
else
|
||||
text = phraseId
|
||||
end
|
||||
end
|
||||
|
||||
if (not silent) then
|
||||
error(functionCallPath["GetText"] .. ": " .. errorText["PhraseIDNotRegistered"] .. ", use: " .. functionSignature["GetLanguageTable"] .. "['PhraseID'] = 'translated text'.")
|
||||
setTableKey_Text(table, key, tableKeyTable, text)
|
||||
return true
|
||||
end
|
||||
|
||||
--@addonId: an identifier, can be any table or string, will be used when getting the table with phrase translations, example: "DetailsLocalization", "Details", "PlaterLoc", _G.Plater
|
||||
--@table: a lua table
|
||||
--@key: any value except nil or boolean
|
||||
--@vararg: arguments to pass for format(text, ...)
|
||||
function DF.Language.UpdateTableKeyArguments(addonId, table, key, ...)
|
||||
if (not isValid_AddonID(addonId)) then
|
||||
error(functionCallPath["UpdateTableKeyArguments"] .. ": " .. format(errorText["AddonID"], 1) .. ", use: " .. functionSignature["UpdateTableKeyArguments"] .. ".")
|
||||
end
|
||||
|
||||
return phraseId
|
||||
local addonNamespaceTable = getAddonNamespace(addonId)
|
||||
if (not addonNamespaceTable) then
|
||||
error(functionCallPath["UpdateTableKeyArguments"] .. ": " .. errorText["NoLanguages"] .. ", use: " .. functionSignature["RegisterLanguage"] .. ".")
|
||||
end
|
||||
|
||||
if (type(table) ~= "table") then
|
||||
error(functionCallPath["UpdateTableKeyArguments"] .. ": " .. format(errorText["InvalidTable"], 2) .. ", use: " .. functionSignature["UpdateTableKeyArguments"] .. ".")
|
||||
end
|
||||
|
||||
if (key == nil or type(key) == "boolean") then
|
||||
error(functionCallPath["UpdateTableKeyArguments"] .. ": " .. format(errorText["InvalidTableKey"], 3) .. ", use: " .. functionSignature["UpdateTableKeyArguments"] .. ".")
|
||||
end
|
||||
|
||||
if (not isTableKeyRegistered(addonNamespaceTable, table)) then
|
||||
error(functionCallPath["UpdateTableKeyArguments"] .. ": " .. errorText["TableKeyNotRegistered"] .. ", use: " .. functionSignature["RegisterTableKey"] .. ".")
|
||||
end
|
||||
|
||||
local tableKeyTable = getTableKeyTable(addonNamespaceTable, table) --can't nil as the line above checked if it exists
|
||||
|
||||
if (not isKeyRegisteredInTableKey(tableKeyTable, key)) then
|
||||
error(functionCallPath["UpdateTableKeyArguments"] .. ": " .. errorText["KeyNotRegistered"] .. ", use: " .. functionSignature["RegisterTableKey"] .. ".")
|
||||
end
|
||||
|
||||
local phraseInfo = getPhraseInfoFromTableKey(tableKeyTable, key) --can't nil as the line above checked if it exists
|
||||
updatePhraseInfoArguments(phraseInfo, key, ...)
|
||||
|
||||
local text = getText(addonNamespaceTable, phraseInfo.phraseId)
|
||||
setTableKey_Text(table, key, tableKeyTable, text)
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
function DF.Language.RegisterTableKeyWithDefaultt(addonId, table, key, phraseId, defaultText)
|
||||
if (addonId and phraseId) then
|
||||
print("registered...")
|
||||
DetailsFramework.Language.RegisterTableKey(addonId, table, key, phraseId)
|
||||
else
|
||||
print("used default")
|
||||
table[key] = defaultText
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user