Skip to content

Commit

Permalink
Fix localization
Browse files Browse the repository at this point in the history
  • Loading branch information
Anonomit committed Jul 3, 2024
1 parent cd7aa40 commit 6a75564
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 78 deletions.
4 changes: 2 additions & 2 deletions Config/OptionsTables.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"

Expand Down
35 changes: 15 additions & 20 deletions Init/Init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ do
-- GAME_LOCALE = "enUS" -- AceLocale override

-- TOOLTIP_UPDATE_TIME = 10000

-- DECIMAL_SEPERATOR = ","
end
--@end-debug@

Expand Down Expand Up @@ -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

Expand Down
45 changes: 33 additions & 12 deletions Locale/LocaleAutomatic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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))
Expand All @@ -54,21 +55,31 @@ 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,
})
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
17 changes: 9 additions & 8 deletions Operations/RecognizeLineTypes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -140,7 +140,7 @@ local bindTypes = {
}


local numberPattern = "[%d%"..DECIMAL_SEPERATOR.."]+"
local numberPattern = Addon.L["[%d,%.]+"]
local lockedPattern = "%s" .. Addon.L["Locked"]


Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
27 changes: 15 additions & 12 deletions Operations/RewordWeaponStats.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
25 changes: 1 addition & 24 deletions Stats/Stats.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 6a75564

Please sign in to comment.