Resource Map Markers


Automatically mark resources on the map.

Utilities
4 years ago
0.18 - 1.1
15.2K

i [DONE] wishlist: localized names in map markers

4 years ago

G'day. Factorio now has an API for translating localized strings and getting the results in your lua code. It is asynchronous, so involves requesting the translation and then waiting for an event giving you the data, but you should be able to cache the results in global for resources. Optionally refresh them at start, I guess?

https://lua-api.factorio.com/latest/LuaPlayer.html#LuaPlayer.request_translation -- I think it is likely 0.18 only, but you should be able to test for it having a non-nil value and use it if so. Uh, clearly this is gonna be a challenge if one a multi-player game, since map markers can only have one label, but I'd personally just go with "game.players[1] is gonna be the closest to the 'standard' language for the game" myself.

There are also some helpers for doing this stuff. flib has some tooling which might help, depending on what you need: https://factoriolib.github.io/flib/modules/translation.html

Rusty Locale also provides an implementation of "get the right localized string for a prototype", which may also be useful:
https://github.com/theRustyKnife/rusty-locale

I'm asking, of course, that you translate strings from internal names to the localized versions in the markers, when possible. :)

I strongly suspect but have not confirmed that the request_translation API is 0.18 only, but you should be able to conditionally invoke it by checking for the field being present (or a function) in LuaPlayer.

Thank you so much!

4 years ago

Wow I had no idea this was possible at all. I remember seeing a dev say a while back that mods can't use localized strings because it causes desync in multiplayer, but I guess they've come up with a solution since then. I'll look into that, it's definitely something I want to fix in this mod. Thanks for the info!

4 years ago

No worries. FWIW, Raiguard (flib author) hangs out on the official discord #mod-making, and has done a whole lot of stuff with this for their "Quick Item Search" mod, so if you run into any problems that'd be where I'd go ask. I only know it exists. :)

4 years ago

Wasn't too hard after all! Added in v0.3.0

4 years ago

That is so awesome! Thank you!

4 years ago

Since yesterday the mod shows raw names again instead of localized names.
Could your mod depend on Flib, by chance? I did see some translation changes in its changelog.

4 years ago

No that's odd I don't use flib, can you share your save?

4 years ago
(updated 4 years ago)

Sure. Here's my save and modpack: https://mega.nz/file/3oFnzCgR#SOW22Piuh_zJKMsSYnEXwk2zm9HTpLOxVUZU1QD7f6k

I am using russian locale

4 years ago

I ran your save in both en and ru locales and the markers seemed to be fully translated. Where you running this in multiplayer?

4 years ago

This is weird. The game is generally hosted at another PC with RU locale. But it is the same, when I run this save offline.
Nevermind then. I'll think something out.

4 years ago

If there are any other players on the map the behavior might be a bit weird. Since map marker labels are shared between players on the same team, they have to have the same text, so if two players have different locale settings I'm not sure what would happen. You could end up with all the labels being from one player's locale or a mix.

New response