How can I get a localized string in a Factorio mod Lua script?
item.localised_name contains only the key. I can use print({"",item.localised_name}) to print the localized name to the UI. but I want it in a variable to write it into a file.
There's a couple different ways you could go about this. I'd recommend just passing the localised string to write_file as it accepts localised strings and will translate it according to each player's locale when writing to the file.
Note that write_data also accepts the append parameter, so you can write your file in pieces for each bit you want to translate.
Alternatively, you can call request_translation if you want to have the translated value of a specific player's locale and you need it in your lua.
Note though that this is asynchronous so you get the result back in an event.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With