Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR provides a general i18n API to
IModInfo
that could be used in Neoforged to implement neoforged/NeoForge#639.I've added a unit test to cover the new behavior, however (as a new contributor) I'm unclear on the best way to test the functionality in game.
That said, if these assumptions are correct, then everything should work as intended:
I18NParser
implementation that usesI18NExtension
will return the i18n key when a translation is not present.I18NParser
'si18n
map contains (at least) the same entries as Minecraft'sLanguage
instance.I18NParser
'si18n
map is updated byLanguageManager
when the language is changed or resource pakcs are reloaded.Using the API
Translations from mod display name and description can be provided by adding the following keys to lang files:
"fml.menu.mods.info.name.[modid]"
"fml.menu.mods.info.description.[modid]"
Where
[modid]
should be replaced with the actual mod ID.These can then be accessed using new methods added to
IModInfo
(names subject to change):IModInfo.getDisplayNameTranslated()
IModInfo.getDescriptionTranslated()
Which return the translated string (if one exists), or the string defined in
mods.toml
otherwise.This could instead return an
Optional
or nullable value if preferred? That way you could easily check if a translated name/description exists and explicitly fallback usingOptional::orElseGet
.Tests
I've added a unit test for the new behavior. In order to do so, I had to make some preparatory changes elsewhere, which I've kept to their own commits for clarity.
As unit tests, they cannot check the assumptions I outlined above.