Battle Pet Completionist

Battle Pet Completionist

115k Downloads

Map Pin Not Working in zhCN & zhTW

LiangYuxuan opened this issue · 9 comments

commented

AddOn is calling C_PetJournal.GetPetInfoBySpeciesID for tooltipSource and parsing it for pet source, in the following function.

function DataModule:GetPetSource(speciesId)
local _, _, _, _, tooltipSource = C_PetJournal.GetPetInfoBySpeciesID(speciesId)
local index = string.find(tooltipSource, ":")
local source = ""
if index then
source = string.sub(tooltipSource, 1, index - 1)
end
if string.find(source, BATTLE_PET_SOURCE_1) ~= nil then return BATTLE_PET_SOURCE_1
elseif string.find(source, BATTLE_PET_SOURCE_2) ~= nil then return BATTLE_PET_SOURCE_2
elseif string.find(source, BATTLE_PET_SOURCE_3) ~= nil then return BATTLE_PET_SOURCE_3
elseif string.find(source, BATTLE_PET_SOURCE_4) ~= nil then return BATTLE_PET_SOURCE_4
elseif string.find(source, BATTLE_PET_SOURCE_5) ~= nil then return BATTLE_PET_SOURCE_5
elseif string.find(source, BATTLE_PET_SOURCE_6) ~= nil then return BATTLE_PET_SOURCE_6
elseif string.find(source, BATTLE_PET_SOURCE_7) ~= nil then return BATTLE_PET_SOURCE_7
elseif string.find(source, BATTLE_PET_SOURCE_8) ~= nil then return BATTLE_PET_SOURCE_8
elseif string.find(source, BATTLE_PET_SOURCE_9) ~= nil then return BATTLE_PET_SOURCE_9
elseif string.find(source, BATTLE_PET_SOURCE_10) ~= nil then return BATTLE_PET_SOURCE_10
elseif string.find(source, BATTLE_PET_SOURCE_11) ~= nil then return BATTLE_PET_SOURCE_11
else return nil end
end

The line 197 is finding colon in English character (:), which works fine in most of locales. However, in zhCN & zhTW, Chinese character is used in localized tooltipSource, and the index will be nil, resulting the function returns nil, disabling the pin.

I'm replacing line 197 to the following line and make it work again.

local index = string.find(tooltipSource, "[::]", 1, false)

Dumping some related data

Dump: value=C_PetJournal.GetPetInfoBySpeciesID(515) 
[1]="初生孢芽", 
[2]=134532, 
[3]=1, 
[4]=62564, 
[5]="|cFFFFD200宠物对战:|r赞加沼泽", 
[6]="这些矮墩墩的小家伙经常会在寻找它们最爱的食物荧光菌帽时陷入麻烦。", 
[7]=true, 
[8]=true, 
[9]=false, 
[10]=false, 
[11]=true, 
[12]=42554, 
[13]=0.40000000596046
Dump: BATTLE_PET_SOURCE_5 
BATTLE_PET_SOURCE_5="宠物对战"

Might be related to #21 .

commented

I can confirm issue resolved after update. Thank you!

commented

@davidmc24 can you take a look at #41 ?

commented

@LiangYuxuan I have just pushed release 11.0.0-20240801-1 - can you please test if that solves the issue, and reopen the ticket if it is still an issue?

commented

Thank you, I'll test it tomorrow, and release it if nothing breaks 😃

commented

@davidmc24 do you know if there is an easy way to get the separator for the current language?
Since it also seems to be a problem with other language 🙂

commented

No, I don't think there's a way to get that. I think we could avoid the issue by instead iterating through each of the possible source labels (G["BATTLE_PET_SOURCE_" .. i]) and checking if it's included in the string. That way, no dependency on the particular text/format of the string, and at worst would result in no match, which we could default to an "other" category or something.

commented

If you'd like, I can try that approach out in the next day or two.

commented

@davidmc24 that would be nice, thank you 🙂

commented

Perfect 😊