Mantas-2155X / MakerSearch

GNU General Public License v3.0
15 stars 4 forks source link

New releases don't use the auto translate #4

Open SpockBauru opened 3 years ago

SpockBauru commented 3 years ago

Newer versions of HS2_MakerSearch (after v1.2.1) don't auto translates texts that are not translated already. You need to hover the mouse over the item and wait for the translation.

Something in v1.3.0 created this behavior.

To replicate the issue:

Delete the Mods.txt file inside BepInEx\Translation\en\Text

Open the Character maker, and open the XUnity.AutoTranslator UI (Alt + 0)

Go to clothes> Tops and search for SENA mods. You will see that in v1.3.0 (and beyond) the translations are not added to the queue in XUA UI, and you need to hover the mouse on the clothes for 2 seconds to translate them. But in the old v1.2.1 all untranslated text are added to the XUA queue and are translated as expected.

GeBo1 commented 3 years ago

I took a look and I think it might be this:

foreach (var info in whatever) {
    TranslationHelper.Translate(info.name, s => Tools.searchNameStrings[info] = info.name + "/v" + s);
}

Since Translate is async info can be a different object when the callback fires. Try:

foreach (var info in whatever) {
    var currentInfo = info;
    TranslationHelper.Translate(info.name, s => Tools.searchNameStrings[currentInfo] = currentInfo.name + "/v" + s);
}
Mantas-2155X commented 3 years ago

Hello, thank you for the issue. I have spent a while investigating and trying to figure out what's wrong.

The reason why versions before v1.3.0 worked fine is because MakerSearch at that time did not have its own caching system and was force translating every clothing item every boot.

Versions v1.3.0 and after have a separate caching system which keeps the translated items for later use. Removing the Mods.txt file or the entire Translation folder did not cause it to re-translate all clothing items because of the saved cache in BepInEx/cache/HS2_MakerSearch.cache. If an item is in that cache, it will not ask XUA to translate it, that is why you need to hover over the name.

Please verify this on your end by:

I will implement GeBo1's suggestion for the next version.

SpockBauru commented 3 years ago

Cleaning the cache did the trick, thanks!

GeBo1 commented 3 years ago

There's still an issue where due to the in-plugin cache it won't update when translations are added/changed/corrected, will they? If possible the best option would probably be to use TryTranslate() first, and don't persist the translations returned from that between sessions, then fall back to TranslateAsync for entries where that fails, and persist those. In that case anything that comes from local translations will keep in sync with the translations and only auto-translated responses would be cached. Otherwise some sort of periodic trashing of the cache, I guess.