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

Add localization override support using custom params #4038

Conversation

S3KCentrifugal
Copy link
Contributor

Adding support to override localization strings via TweakUnits/TweakDefs.

This is what custom units look like when missing from translations...
SampleWithoutCodeChange

This is what custom units look like when using custom param localization...
SampleWithCodeChange

The use case for this is overriding translated human names and tooltips names via TweakUnits or TweakDefs. In my case I am working on an Evolution mod where eco is removed from the game and many different types of units can evolve(Instead of just commander) and they end up with really ugly names that include the unit namespace.

This proposed change may make the scavenger language code redundant since all the translations can be set via TweakDefs. The same thing may be true for including Evolving commander translations the I8N translations folder. Although there may still be a use case to package translations with the game for mods. I will defer to the mod authors on that.

Here is a sample Tweak Units to test the change...
{ armllt = { customparams = { i18n_en_humanname = "Test Name LLT", i18n_en_tooltip = "Test Tooltip LLT", }, }, }

I've also attached a sample TweakDefs you can use for testing evolving units with custom names.
EvolvesTweakDef2.txt

@WatchTheFort WatchTheFort marked this pull request as draft December 19, 2024 00:39
@WatchTheFort
Copy link
Member

Using custom params should not be necessary, tweakdefs should be able to override these by setting translatedHumanName and translatedTooltip directly. Currently that doesn't happen because tweakdefs are loaded before this widget runs, so the values end up getting overwritten.

A widget will need to load the tweakdef values into these two properties, then calling the language API to reload the names. Currently the language widget will reload these when changing languages, it may need to be changed to be able to reload these on demand.

For proper modding support, mods can supply their own translation files, and load them by calling Spring.I18N.loadFile. Entries in them will overwrite base game entries.

@sprunk
Copy link
Collaborator

sprunk commented Dec 19, 2024

Using custom params should not be necessary, tweakdefs should be able to override these by setting translatedHumanName and translatedTooltip directly. Currently that doesn't happen because tweakdefs are loaded before this widget runs, so the values end up getting overwritten.

I think has to be customparams, tweakdefs run in a different lua environment and on a different UnitDefs table (they are just named the same, see beyond-all-reason/spring#1039). The first UnitDefs table is passed through engine and the only non-engine-native thing that survives intact is customparams.

@S3KCentrifugal
Copy link
Contributor Author

S3KCentrifugal commented Dec 19, 2024

Using custom params should not be necessary, tweakdefs should be able to override these by setting translatedHumanName and translatedTooltip directly. Currently that doesn't happen because tweakdefs are loaded before this widget runs, so the values end up getting overwritten.

A widget will need to load the tweakdef values into these two properties, then calling the language API to reload the names. Currently the language widget will reload these when changing languages, it may need to be changed to be able to reload these on demand.

For proper modding support, mods can supply their own translation files, and load them by calling Spring.I18N.loadFile. Entries in them will overwrite base game entries.

Hey, thanks for the quick reply.

I did notice overriding does not work using translatedHumanName. I was discussing the load order in the modding discussion channel. That inspired me to make this change.

By loading translations via "Spring.I18N" it required the translations to be distributed to the other players. I found this to be a bit of a nuisance when you can customize nearly everything except unit name in a multiplayer lobby.

image

@WatchTheFort
Copy link
Member

WatchTheFort commented Jan 11, 2025

Changed to use a dedicated widget, originally written by @S3KCentrifugal, to support tweakdefs being able to set unit names with custom params. This currently doesn't support changing language, as it only runs once on initialize for whatever the current language happens to be.

@WatchTheFort
Copy link
Member

WatchTheFort commented Jan 11, 2025

Added support for changing language, but for reasons I have yet to discover, it works for the description but not the name.

When I add the following tweakders:

VW5pdERlZnNbJ2FybWNvbSddLmN1c3RvbXBhcmFtcy5pMThuX2VuX2h1bWFubmFtZSA9ICJUZXN0IE5hbWUiDQpVbml0RGVmc1snYXJtY29tJ10uY3VzdG9tcGFyYW1zLmkxOG5fZW5fdG9vbHRpcCA9ICJUZXN0IERlc2NyaXB0aW9uIg0KVW5pdERlZnNbJ2FybWNvbSddLmN1c3RvbXBhcmFtcy5pMThuX2ZyX2h1bWFubmFtZSA9ICJMZSBUZXN0IE5vbSINClVuaXREZWZzWydhcm1jb20nXS5jdXN0b21wYXJhbXMuaTE4bl9mcl90b29sdGlwID0gIkxlIFRlc3QgRGVzY3JpcHRpb24i

Which is:

UnitDefs['armcom'].customparams.i18n_en_humanname = "Test Name"
UnitDefs['armcom'].customparams.i18n_en_tooltip = "Test Description"
UnitDefs['armcom'].customparams.i18n_fr_humanname = "Le Test Nom"
UnitDefs['armcom'].customparams.i18n_fr_tooltip = "Le Test Description"

In English it works for both, but when I change to French it works for description but not name.

@S3KCentrifugal
Copy link
Contributor Author

Added support for changing language, but for reasons I have yet to discover, it works for the description but not the name.

When I add the following tweakders:

VW5pdERlZnNbJ2FybWNvbSddLmN1c3RvbXBhcmFtcy5pMThuX2VuX2h1bWFubmFtZSA9ICJUZXN0IE5hbWUiDQpVbml0RGVmc1snYXJtY29tJ10uY3VzdG9tcGFyYW1zLmkxOG5fZW5fdG9vbHRpcCA9ICJUZXN0IERlc2NyaXB0aW9uIg0KVW5pdERlZnNbJ2FybWNvbSddLmN1c3RvbXBhcmFtcy5pMThuX2ZyX2h1bWFubmFtZSA9ICJMZSBUZXN0IE5vbSINClVuaXREZWZzWydhcm1jb20nXS5jdXN0b21wYXJhbXMuaTE4bl9mcl90b29sdGlwID0gIkxlIFRlc3QgRGVzY3JpcHRpb24i

Which is:

UnitDefs['armcom'].customparams.i18n_en_humanname = "Test Name"
UnitDefs['armcom'].customparams.i18n_en_tooltip = "Test Description"
UnitDefs['armcom'].customparams.i18n_fr_humanname = "Le Test Nom"
UnitDefs['armcom'].customparams.i18n_fr_tooltip = "Le Test Description"

In English it works for both, but when I change to French it works for description but not name.

Does this affect all GUIs that present names or just some? Could it be a bug in individual widgets not refreshing the UI properly?

@WatchTheFort
Copy link
Member

Figured it out, it has to do with the language_english_unit_names config setting. I will change it to default false in another PR.

@sprunk
Copy link
Collaborator

sprunk commented Jan 11, 2025

Perhaps anything that uses customparam-supplied name should default to english anyway? Nobody writing tweakdefs is going to provide chinese names

@WatchTheFort WatchTheFort marked this pull request as ready for review January 18, 2025 16:27
@WatchTheFort WatchTheFort merged commit 3394daf into beyond-all-reason:master Jan 18, 2025
WatchTheFort added a commit that referenced this pull request Jan 18, 2025
#4038 moved I18N initialization from setupdefs.lua into purely widget space. This broke grid menu, as it was caching its I18N entries outside of callins, so was running before the gui_language widget, even though it is on a higher layer.
WatchTheFort added a commit that referenced this pull request Jan 18, 2025
#4038 moved running the I18N initialization code for defs from setupdefs.lua into purely widget space. This broke any widgets trying to look up these I18N entries outside of callins, as the code would run before gui_language had a chance to run, despite it being on a lower layer.
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