A method to detect changes in player language in Singleplayer.

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

A method to detect changes in player language in Singleplayer.

Post by eradicator »

The Problem

When a player loads a savegame in English, then saves, changes to German and reloads the savegame the only event raised is on_load. In multiplayer this is not a problem because of on_player_left_game and on_player_joined_game.

A Solution

Just to be clear: I do NOT want information about what locale a player has. I just want to know IF it changed or not.

I do not care how exactly this is implemented. During observations I noticed that sometimes on_configuration_changed is raised with ConfigurationChangedData that is just a bunch of empty tables. That would be sufficent. Raising on_player_left/joined in Singleplayer would also be sufficent (let them both happen right after on_load or something). A seperate event for this would work too but that seems like a sledgehammer method?

Why?

Because I'm dealing with LuaPlayer.request_translation so I need to know when the locale changed.

[Edit 2021-08-02: To clarify, with "locale" I mean the name of the selected language, i.e. "en", "de", not the actual *content* of the locale, as that already raises on_configuration_changed due to hash mismatch.]
Last edited by eradicator on Mon Aug 02, 2021 4:28 pm, edited 3 times in total.
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
raiguard
Factorio Staff
Factorio Staff
Posts: 451
Joined: Wed Dec 13, 2017 8:29 pm
Contact:

Re: A method to detect changes in player language in Singleplayer.

Post by raiguard »

I dealt with this simply by not dealing with it. People will hardly ever change their locale mid-game unless they're a translator or a mod developer. I'd just provide a command to retranslate and call it a day.
Don't forget, you're here forever.

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

Re: A method to detect changes in player language in Singleplayer.

Post by eradicator »

Raiguard wrote:
Sun Aug 01, 2021 10:54 pm
I dealt with this simply by not dealing with it. People will hardly ever change their locale mid-game unless they're a translator or a mod developer. I'd just provide a command to retranslate and call it a day.
I do provide a command already. But I'm not calling it a day. I want Babelfish to deliver a native search experience without having to make unfounded assumptions about peoples habits. And the command solution requires people to be familiar with engine internals to even understand when to use it.
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.

curiosity
Filter Inserter
Filter Inserter
Posts: 324
Joined: Wed Sep 11, 2019 4:13 pm
Contact:

Re: A method to detect changes in player language in Singleplayer.

Post by curiosity »

eradicator wrote:
Mon Aug 02, 2021 11:01 am
I do provide a command already. But I'm not calling it a day. I want Babelfish to deliver a native search experience without having to make unfounded assumptions about peoples habits. And many people are not comfortable with using commands (if they can even be bothered to research them).
For a native search experience you should be asking for locale to become part of the game state, so it can be read directly.

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

Re: A method to detect changes in player language in Singleplayer.

Post by eradicator »

curiosity wrote:
Mon Aug 02, 2021 11:07 am
For a native search experience you should be asking for locale to become part of the game state, so it can be read directly.
Based on the way that request_translation() was implemented using network packages instead of direct disk reading I'm assuming that anything locale related is a huge mess and such requests would be labeled "never gonna happen". Apparently Raiguard had a different experience?

I already have a request_translation based solution to read the locale. But merely reading it does not help detecting changes unless I use on_tick to poll it from every player every tick.
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
raiguard
Factorio Staff
Factorio Staff
Posts: 451
Joined: Wed Dec 13, 2017 8:29 pm
Contact:

Re: A method to detect changes in player language in Singleplayer.

Post by raiguard »

eradicator wrote:
Mon Aug 02, 2021 11:01 am
Raiguard wrote:
Sun Aug 01, 2021 10:54 pm
I dealt with this simply by not dealing with it. People will hardly ever change their locale mid-game unless they're a translator or a mod developer. I'd just provide a command to retranslate and call it a day.
I do provide a command already. But I'm not calling it a day. I want Babelfish to deliver a native search experience without having to make unfounded assumptions about peoples habits. And the command solution requires people to be familiar with engine internals to even understand when to use it.
Our goals are slightly different - you want Babelfish to be a fully packaged solution for localised search, whereas flib is just providing a utility to handle most of the boilerplate for doing translations (even more so in the rewrite that I'm working on). It probably makes sense for you to automatically react to changes in locale, whereas flib doesn't handle that at all.

It's worth noting, however, that I have not had a single person ask how to retranslate dictionaries in the year and a half that I've been doing translations this way, which is what leads me to believe that changing locale halfway through a game is pretty rare.
Don't forget, you're here forever.

User avatar
raiguard
Factorio Staff
Factorio Staff
Posts: 451
Joined: Wed Dec 13, 2017 8:29 pm
Contact:

Re: A method to detect changes in player language in Singleplayer.

Post by raiguard »

eradicator wrote:
Mon Aug 02, 2021 11:14 am
curiosity wrote:
Mon Aug 02, 2021 11:07 am
For a native search experience you should be asking for locale to become part of the game state, so it can be read directly.
Based on the way that request_translation() was implemented using network packages instead of direct disk reading I'm assuming that anything locale related is a huge mess and such requests would be labeled "never gonna happen". Apparently Raiguard had a different experience?

I already have a request_translation based solution to read the locale. But merely reading it does not help detecting changes unless I use on_tick to poll it from every player every tick.
My LuaPlayer::active_locale request was not directly reading all locale - I'm sorry that I didn't word it clearly. The request is reading which locale the player has selected - English, Japanese, German, etc. It just means we won't have to request a translation to figure out which language they're using anymore.

Even if locale was redesigned to be a part of gamestate, it would undoubtedly still be a function - it might even still be called `request_translation()`. The only difference would be that instead of waiting for an event, it would come back immediately. If that happened in the future, then I could get away without storing translations in `global` at all!
Don't forget, you're here forever.

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

Re: A method to detect changes in player language in Singleplayer.

Post by eradicator »

@Raiguard Imho this is getting off topic.

TL;DR: I'd very much like to fix the edge case properly so I made a request hoping that it's an easy enhancement. If devs decide it's too edgy/not simple enough then I'll have to start on-tick-polling. I've added a comment to the opening post.

FullAnswer
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 “Modding interface requests”