From 6a75564abce79cfe7e347839972d4c8672161e05 Mon Sep 17 00:00:00 2001 From: Anonomit Date: Tue, 2 Jul 2024 19:28:57 -0400 Subject: [PATCH] Fix localization #5 --- Config/OptionsTables.lua | 4 +-- Init/Init.lua | 35 +++++++++++------------- Locale/LocaleAutomatic.lua | 45 ++++++++++++++++++++++--------- Operations/RecognizeLineTypes.lua | 17 ++++++------ Operations/RewordWeaponStats.lua | 27 ++++++++++--------- Stats/Stats.lua | 25 +---------------- 6 files changed, 75 insertions(+), 78 deletions(-) diff --git a/Config/OptionsTables.lua b/Config/OptionsTables.lua index 19cbbe8..87b2ef2 100644 --- a/Config/OptionsTables.lua +++ b/Config/OptionsTables.lua @@ -1253,7 +1253,7 @@ local function MakeExtraOptions(opts, categoryName) end end - local speedString = strGsub(format("%.2f", sampleSpeed), "%.", DECIMAL_SEPERATOR) + local speedString = strGsub(format("%.2f", sampleSpeed), "%.", DECIMAL_SEPERATOR) -- always use default DECIMAL_SEPERATOR local speedStringFull = self.L["Speed"] .. " " .. speedString -- Weapon Speed do @@ -1297,7 +1297,7 @@ local function MakeExtraOptions(opts, categoryName) GUI:CreateGroup(opts, GUI:Order(), " ", nil, nil, true) -- Weapon DPS - local sampleDPS = strGsub(format("%.1f", sampleDamage / sampleSpeed), "%.", DECIMAL_SEPERATOR) + local sampleDPS = format("%.1f", sampleDamage / sampleSpeed) -- always uses period as decimal do local stat = "DamagePerSecond" diff --git a/Init/Init.lua b/Init/Init.lua index 894be74..3f09e06 100644 --- a/Init/Init.lua +++ b/Init/Init.lua @@ -73,8 +73,6 @@ do -- GAME_LOCALE = "enUS" -- AceLocale override -- TOOLTIP_UPDATE_TIME = 10000 - - -- DECIMAL_SEPERATOR = "," end --@end-debug@ @@ -1310,32 +1308,29 @@ do text = strGsub(text, "%%*$", "") -- strip comma separators, convert decimal separator into period - if DECIMAL_SEPERATOR == "." then - text = strGsub(text, "(%d),(%d)", "%1%2") + if self.L["."] == "." then + text = strGsub(text, "(%d)" .. self.L["."] .. "(%d%d%d)", "%1%2") else - text = self:ChainGsub(text, {"(%d)%.(%d)", "%1%2"}, {"%"..DECIMAL_SEPERATOR, "."}) + text = self:ChainGsub(text, {"(%d)%" .. self.L[","] .. "(%d%d%d)", "%1%2"}, {"%" .. self.L["."], "."}) end return tonumber(text) end - function Addon:ToFormattedNumber(text, noThousandsSeparator) + function Addon:ToFormattedNumber(text, noThousandsSeparator, numDecimalPlaces) + text = self:ToNumber(text) + if numDecimalPlaces then + text = format("%." .. numDecimalPlaces .. "f", text) + end text = tostring(self:ToNumber(text)) - if DECIMAL_SEPERATOR == "." then - if not noThousandsSeparator then - local count = 1 - while count > 0 do - text, count = strGsub(text, "^(-?%d+)(%d%d%d)", "%1,%2") - end - end - else - text = strGsub(text, "(%d)%.(%d)", "%1,%2") - if not noThousandsSeparator then - local count = 1 - while count > 0 do - text, count = strGsub(text, "^(-?%d+)(%d%d%d)", "%1.%2") - end + if self.L["."] ~= "." then + text = strGsub(text, "(%d)%.(%d)", "%1" .. self.L["."] .. "%2") + end + if not noThousandsSeparator then + local count = 1 + while count > 0 do + text, count = strGsub(text, "^(-?%d+)(%d%d%d)", "%1" .. self.L[","] .. "%2") end end diff --git a/Locale/LocaleAutomatic.lua b/Locale/LocaleAutomatic.lua index 83c1487..bd28c5a 100644 --- a/Locale/LocaleAutomatic.lua +++ b/Locale/LocaleAutomatic.lua @@ -7,6 +7,7 @@ local Addon = LibStub("AceAddon-3.0"):GetAddon(ADDON_NAME) local strLower = string.lower +local strFind = string.find local strMatch = string.match local strGsub = string.gsub @@ -21,18 +22,18 @@ local locale = GetLocale() local actual = {} local L = setmetatable({}, { __index = function(self, key) - if not rawget(actual, key) then - rawset(self, key, key) + if not actual[key] then + actual[key] = key Addon:Throwf("%s: Missing automatic translation for '%s'", ADDON_NAME, tostring(key)) end - return key + return actual[key] end, __newindex = function(self, key, val) - if rawget(actual, key) then + if actual[key] then Addon:Warnf(ADDON_NAME..": Automatic translation for '%s' has been overwritten", tostring(key)) end if type(val) == "table" then - -- get the largest index in table + -- get the largest key in table local max = 1 for i in pairs(val) do if i > max then @@ -42,8 +43,8 @@ local L = setmetatable({}, { -- try adding values from the table in order for i = 1, max do if val[i] then - actual[key] = val[i] - if rawget(actual, key) then + self[key] = val[i] + if actual[key] then return else Addon:Warnf(ADDON_NAME..": Automatic translation #%d failed for '%s'", i, tostring(key)) @@ -54,14 +55,14 @@ local L = setmetatable({}, { end elseif type(val) == "function" then -- use the function return value unless it errors - local success, val = Addon:xpcall(val) + local success, result = Addon:xpcall(val) if not success then Addon:Throwf("%s: Automatic translation error for '%s'", ADDON_NAME, tostring(key)) return end - rawset(actual, key, val) + actual[key] = result else - rawset(actual, key, val) + actual[key] = val end end, }) @@ -69,6 +70,16 @@ Addon.L = L +if locale == "esES" then + L["."] = "." + L[","] = "," +else + L["."] = DECIMAL_SEPERATOR + L[","] = LARGE_NUMBER_SEPERATOR +end + +L["[%d,%.]+"] = function() return "[%d%" .. L[","] .. "%" .. L["."] .. "]+" end + L["Options"] = OPTIONS @@ -324,7 +335,7 @@ L["Written by %s"] = ITEM_WRITTEN_BY L["%c%d %s Resistance"] = ITEM_RESIST_SINGLE if locale == "zhTW" and not Addon.isEra then - Addon.L["%c%d to All Resistances"] = strGsub(Addon.L["%c%d to All Resistances"], "(%%d)", "%1 ") + Addon.L["%c%d to All Resistances"] = strGsub(ITEM_RESIST_ALL, "%%d", "%1 ") else L["%c%d to All Resistances"] = ITEM_RESIST_ALL end @@ -402,6 +413,8 @@ end + + L["Defense Rating"] = ITEM_MOD_DEFENSE_SKILL_RATING_SHORT L["Increases defense rating by %s."] = ITEM_MOD_DEFENSE_SKILL_RATING @@ -463,7 +476,15 @@ L["Haste Rating (Spell)"] = {ITEM_MOD_HASTE_SPELL_RATING_SHORT, function() retur L["Improves spell haste rating by %s."] = {ITEM_MOD_HASTE_SPELL_RATING, function() return strGsub(ITEM_MOD_CRIT_SPELL_RATING, Addon:CoverSpecialCharacters(ITEM_MOD_CRIT_RATING), Addon:CoverSpecialCharacters(ITEM_MOD_HASTE_RATING)) end} L["Mastery"] = ITEM_MOD_MASTERY_RATING_SHORT -L["%c%d Mastery"] = {function() return "%c%d " .. L["Mastery"] end} +if strFind(L["%c%d Stamina"], "^%%") then + if strFind(L["%c%d Stamina"], " ") then + L["%c%d Mastery"] = "%c%d " .. L["Mastery"] + else + L["%c%d Mastery"] = "%c%d" .. L["Mastery"] + end +else + L["%c%d Mastery"] = L["Mastery"] .. " %c%d" +end L["Health Regeneration"] = ITEM_MOD_HEALTH_REGENERATION_SHORT L["Restores %s health per 5 sec."] = ITEM_MOD_HEALTH_REGEN diff --git a/Operations/RecognizeLineTypes.lua b/Operations/RecognizeLineTypes.lua index 11e7e24..6b522d4 100644 --- a/Operations/RecognizeLineTypes.lua +++ b/Operations/RecognizeLineTypes.lua @@ -20,7 +20,7 @@ local L_ITEM_MOD_INTELLECT = Addon.L["%c%d Intellect"] local L_ITEM_MOD_SPIRIT = Addon.L["%c%d Spirit"] local L_ITEM_RESIST_SINGLE = Addon.L["%c%d %s Resistance"] -local L_ITEM_MOD_MASTERY_RATING = Addon.L["%c%d Mastery"] +local L_ITEM_MOD_MASTERY_RATING_SHORT = Addon.L["%c%d Mastery"] local L_CURRENTLY_EQUIPPED = Addon.L["Currently Equipped"] local L_DESTROY_GEM = Addon.L["Gem to be destroyed"] @@ -140,7 +140,7 @@ local bindTypes = { } -local numberPattern = "[%d%"..DECIMAL_SEPERATOR.."]+" +local numberPattern = Addon.L["[%d,%.]+"] local lockedPattern = "%s" .. Addon.L["Locked"] @@ -441,6 +441,7 @@ contextActions = Addon:Map({ if not speed then return end -- SINGLE_DAMAGE_TEMPLATE can match unrelated lines, like in Chaotic gems tooltipData.speedStringFull = line.textRightText tooltipData.speedString = speed + -- actual DECIMAL_SEPERATOR is used to write speed if DECIMAL_SEPERATOR ~= "." then speed = strGsub(speed, "%"..DECIMAL_SEPERATOR, ".") end @@ -459,11 +460,11 @@ contextActions = Addon:Map({ end end -- didn't match any other possible line - local min, max = strMatch(line.textLeftTextStripped, "%+ ?(%d+) ?%- ?(%d+)") + local min, max = strMatch(line.textLeftTextStripped, "(" .. numberPattern .. ") ?%- ?(" .. numberPattern .. ")") if min then - tooltipData.damageBonus = {tonumber(min), tonumber(max)} + tooltipData.damageBonus = {Addon:ToNumber(min), Addon:ToNumber(max)} else - local n = tonumber(strMatch(line.textLeftTextStripped, "%+ ?(%d+)")) + local n = Addon:ToNumber(strMatch(line.textLeftTextStripped, numberPattern)) tooltipData.damageBonus = {n, n} end return SetContext(i, tooltipData, line) @@ -473,7 +474,7 @@ contextActions = Addon:Map({ if tooltipData.speed then local _, dps = MatchesAny(line.textLeftTextStripped, L_DPS_TEMPLATE) if dps then - tooltipData.dps = tonumber(dps) + tooltipData.dps = tonumber(dps) -- always uses period as decimal return SetContext(i, tooltipData, line) end end @@ -515,9 +516,9 @@ contextActions = Addon:Map({ end end end - elseif line.colorLeft == Addon.colors.GREEN and MatchesAny(line.textLeftTextStripped, L_ITEM_MOD_MASTERY_RATING) then + elseif line.colorLeft == Addon.colors.GREEN and MatchesAny(line.textLeftTextStripped, L_ITEM_MOD_MASTERY_RATING_SHORT) then line.stat = "Mastery Rating" - line.normalForm = line.textLeftText + line.normalForm = Addon.statsInfo["Mastery Rating"]:ConvertToNormalForm(line.textLeftTextStripped) return SetContext(i-1, tooltipData, line) end end diff --git a/Operations/RewordWeaponStats.lua b/Operations/RewordWeaponStats.lua index 27821f4..adfcfd3 100644 --- a/Operations/RewordWeaponStats.lua +++ b/Operations/RewordWeaponStats.lua @@ -24,7 +24,7 @@ function Addon:ModifyWeaponDamage(text, dps, speed, damageBonus) local noThousandsSeparator = self:GetOption("allow", "reword") and not self:GetOption("separateThousands", stat) local precision = self:GetOption("allow", "reword") and (1 / 10^self:GetOption("precision", stat)) or 1 - local minMax, min, gap, max = strMatch(text, "(([%d,]+)( ?%- ?)([%d,]+))") + local minMax, min, gap, max = strMatch(text, "((" .. self.L["[%d,%.]+"] .. ")( ?%- ?)(" .. self.L["[%d,%.]+"] .. "))") if min then min, max = self:ToNumber(min), self:ToNumber(max) local mid = dps * speed @@ -64,7 +64,7 @@ function Addon:ModifyWeaponDamage(text, dps, speed, damageBonus) end end - return strGsub(text, "[%d,]+ ?%- ?[%d,]+", pattern) + return strGsub(text, self.L["[%d,%.]+"] .. " ?%- ?" .. self.L["[%d,%.]+"], pattern) end return text end @@ -82,7 +82,7 @@ function Addon:ModifyWeaponDamageBonus(text, damageBonus) local noThousandsSeparator = self:GetOption("allow", "reword") and not self:GetOption("separateThousands", stat) local precision = self:GetOption("allow", "reword") and (1 / 10^self:GetOption("precision", stat)) or 1 - local minMax, min, gap, max = strMatch(text, "(([%d,]+)( ?%- ?)([%d,]+))") + local minMax, min, gap, max = strMatch(text, "((" .. self.L["[%d,%.]+"] .. ")( ?%- ?)(" .. self.L["[%d,%.]+"] .. "))") if min then min, max = self:ToNumber(min), self:ToNumber(max) local mid = (damageBonus[1] + damageBonus[2]) / 2 @@ -116,12 +116,13 @@ function Addon:ModifyWeaponDamageBonus(text, damageBonus) end end - return strGsub(text, "[%d,]+ ?%- ?[%d,]+", pattern) + return strGsub(text, self.L["[%d,%.]+"] .. " ?%- ?" .. self.L["[%d,%.]+"], pattern) end return text end + local stat = "Speed" local coveredSpeed = Addon:CoverSpecialCharacters(SPEED) function Addon:ModifyWeaponSpeed(text, speed, speedString) @@ -137,14 +138,16 @@ function Addon:ModifyWeaponSpeed(text, speed, speedString) end if self:GetOption("allow", "reword") then - local precision = self:GetOption("precision", stat) - if precision ~= 2 then - local newSpeed = format("%." .. precision .. "f", speed) - if DECIMAL_SEPERATOR ~= "." then - newSpeed = strGsub(newSpeed, "%.", DECIMAL_SEPERATOR) - end - text = strGsub(text, speedString, newSpeed) - end + local newSpeed = self:ToFormattedNumber(speed, nil, self:GetOption("precision", stat)) + text = strGsub(text, self:CoverSpecialCharacters(speedString), newSpeed) + -- local precision = self:GetOption("precision", stat) + -- if precision ~= 2 then + -- local newSpeed = format("%." .. precision .. "f", speed) + -- if self.L["."] ~= "." then + -- newSpeed = strGsub(newSpeed, "%.", self.L["."]) + -- end + -- text = strGsub(text, self:CoverSpecialCharacters(speedString), newSpeed) + -- end end return text end diff --git a/Stats/Stats.lua b/Stats/Stats.lua index aff60e8..4eada84 100644 --- a/Stats/Stats.lua +++ b/Stats/Stats.lua @@ -275,27 +275,12 @@ do local function ApplyMod(text, normalForm) local match1, match2 = strMatch(normalForm, normalFormCapture) local origStrNumber = match1 .. (match2 or "") - local strNumber, percent = strMatch(origStrNumber, "(%-?[%d,]+)(%%?)") - -- if DECIMAL_SEPERATOR ~= "." then - -- strNumber = strGsub(strNumber, "%"..DECIMAL_SEPERATOR, ".") - -- end - -- strNumber, commas = strGsub(strNumber, "(%d),(%d)", "%1%2") - -- local number = self:Round(tonumber(strNumber) * self:GetOption("mod", stat), 1 / 10^self:GetOption("precision", stat)) + local strNumber, percent = strMatch(origStrNumber, "(%-?" .. self.L["[%d,%.]+"] .. ")(%%?)") local number = self:Round(self:ToNumber(strNumber) * self:GetOption("mod", stat), 1 / 10^self:GetOption("precision", stat)) - -- strNumber = tostring(number) - -- if DECIMAL_SEPERATOR ~= "." then - -- strNumber = strGsub(strNumber, "%.", DECIMAL_SEPERATOR) - -- end strNumber = self:ToFormattedNumber(number, not self:GetOption("separateThousands", stat)) if isBaseStat and number > 0 then strNumber = "+" .. strNumber end - -- if commas > -1 then - -- local count = 1 - -- while count > 0 do - -- strNumber, count = strGsub(strNumber, "^(-?%d+)(%d%d%d)", "%1,%2") - -- end - -- end return strGsub(text, self:CoverSpecialCharacters(origStrNumber), self:CoverSpecialCharacters(strNumber .. percent)) end @@ -320,7 +305,6 @@ do strNumber = match2 end return self:ToNumber(strGsub(strNumber, "%%", "")) - -- return tonumber((self:ChainGsub(strNumber, {"%%", ""}, {"(%d),(%d)", "%1%2"}))) end function StatInfo:ConvertToNormalForm(text) @@ -347,13 +331,6 @@ do end function StatInfo:GetDefaultForm(number) - -- local strNumber = tostring(number) - -- if type(number) == "string" then - -- number = tonumber(strMatch(number, "%d+")) - -- end - -- if DECIMAL_SEPERATOR ~= "." then - -- strNumber = strGsub(strNumber, "%.", DECIMAL_SEPERATOR) - -- end local percent = strFind(number, "%%$") number = Addon:ToNumber(number) local strNumber