Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a text supplier for TextWidget. #69

Merged
merged 3 commits into from
Mar 7, 2024

Conversation

AbdielKavash
Copy link
Member

@AbdielKavash AbdielKavash commented Mar 6, 2024

Simple change for a fairly complex reason. Let me explain:

This is a part of the localization effort for MUI. There are some text fields which use elements (strings, numbers) that need to be localized. Some of these elements can change their value dynamically, when the user is looking at the GUI. A simple example could be a readout: "EU stored: 1,500 / 20,000" (fictional, just for the sake of the example). This readout needs to be both translated (text "EU stored:") and localized (numbers with correct group separators).

Currently, readouts like this are handled by DynamicTextWidget. However this has a major flaw: the full string is first computed on the server, and then it is sent to the client. This will not work when the server and the client use a different locale, as the server's locale is used to build the string to display.

In reality, this does not need such a level of sophistication. We can simply build the string to display on the client, as long as the client has access to all the data it needs to do so (the current and maximum EU amounts in the example above). I have checked all the uses of DynamicTextWidget (there are only a couple of them in the whole pack), and this is never an issue.

I have added methods setTextSupplier and for convenience setStringSupplier to TextWidget, which will allow the displayed text to be changed from the client side, without the server being involved at all. This way, the client can also properly apply localization standards as needed. I propose also deprecating DynamicTextWidget and moving over all uses of it to the new methods (which I will do as a part of my ongoing localization effort).

 

For demonstration, this is a client with the French locale connecting to a server with the US locale. Top text is a static TextWidget, middle is DynamicTextWidget, bottom is TextWidget using the new supplier method. (The second and third number are supposed to update every tick, it is a timestamp, hard to show in a static picture.)

@AbdielKavash AbdielKavash requested review from miozune and a team March 6, 2024 12:04
@AbdielKavash AbdielKavash requested a review from Caedis March 7, 2024 01:35
@Caedis
Copy link
Member

Caedis commented Mar 7, 2024

Looks good, though I think MUI2 will have something similar.

@miozune miozune merged commit 417a5a7 into GTNewHorizons:master Mar 7, 2024
1 check passed
Dream-Master pushed a commit to GTNewHorizons/GigaGramFab that referenced this pull request Mar 9, 2024
* Replaces one instance where a dynamic text field is being communicated
between server and client with a purely client-side method. In some
cases this allows the client to do localization on these texts
correctly. (See GTNewHorizons/ModularUI#69.)

This is a part of the series of PRs implementing new ModularUI features,
however this mod does not use any numeric text fields or similar, and
thus no other changes are needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants