SMAPI - Stardew Modding API

SMAPI - Stardew Modding API

971k Downloads

SMAPI ignores the existence of en.json and en-EN.json in i18n folders

Spiderbuttons opened this issue ยท 0 comments

commented

SMAPI will not correctly use an en.json or en-EN.json file as it should for i18n. It should prioritize the latter, then the former, and then finally default.json, but specifically for English, it will only utilize default.json and ignore the other two. The issue happens in Translator:GetRelevantLocales and more upstream in one of BaseContentManager's two GetLocale functions. The overloaded GetLocale function grabs the language string from Stardew Valley itself, which returns an empty string specifically for the English language instead of a locale code like en-EN. This empty string makes its way back to GetRelevantLocales where the while loop sees an empty string and so skips to just adding default as the only relevant locale, which then means the eventual code that loads the actual .json files only knows to load default.json.

In my testing, making BaseContentManager.GetLocale(LanguageCode language) return en-EN if it receives an empty string from the game was enough to make SMAPI correctly load my en.json i18n file, though I can't say I'm fully aware of any consequences of doing so elsewhere in SMAPI (i.e. I don't know if anywhere else strictly relies on an empty string for the English locale, such as maybe locale-specific asset loading). Adjusting GetRelevantLocales is probably better.

To Reproduce:

  1. Create an i18n folder in your mod and populate a default.json
  2. Create an en.json with values that differ from default.json
  3. Use the i18n system for some text in-game
  4. Launch the game and see that the game uses your default.json values instead of your en.json values, even when your game is set to the English locale.