[1.1.34] on_string_translated handles empty localised string incorrectly

Things that we don't consider worth fixing at this moment.
Post Reply
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

[1.1.34] on_string_translated handles empty localised string incorrectly

Post by eradicator »

Code:

Code: Select all

/c
script.on_event(defines.events.on_string_translated, function(e) game.print(serpent.line(e.localised_string)) end)
game.player.request_translation( {'',{''},{''},{''},{''}} )
Result:

Code: Select all

{"", "", "", "", ""}
As you can see the event data localised string is missing the subtables. This breaks association between the request and the result.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2250
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [1.1.34] on_string_translated handles empty localised string incorrectly

Post by boskid »

This LocalisedString has to go through the input actions so at some point it has to be converted from lua table to internally used LocalisedString. This issue you have is because internally there are 3 states for LocalisedString: Translation, Literal and Empty. In this case you have Literal with 4 parameters which are themselves Literals (they have no key) but they have no parameters so they are converted into Empty. That step drops the inner brackets. If you would have a translation (which means non empty key) or literal with parameters (which means at least one parameter) those inner tables would be preserved.

Fixing this issue could easily become a breaking change which will not happen in the middle of a stable and there is a relatively easy workaround for this (do not use literal with no parameters) so i am moving this to "wont fix"

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: [1.1.34] on_string_translated handles empty localised string incorrectly

Post by eradicator »

Thank you for the detailed answer.
boskid wrote:
Fri Jun 04, 2021 9:17 am
easy workaround for this (do not use literal with no parameters)
Regrettably this only works if I create the localised strings myself. If other people throw these at my remote interface and you won't fix it then I have to re-implement that behavior in lua.

So far I'm only dealing with runtime LuaSomethingPrototype.localised_name and description. Do you know if that "transformation" of {""} to "" also happens during prototype loading?
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

Post Reply

Return to “Won't fix.”