diff --git a/src/SMAPI/Framework/ContentCoordinator.cs b/src/SMAPI/Framework/ContentCoordinator.cs index 00f9439c..0cdc0736 100644 --- a/src/SMAPI/Framework/ContentCoordinator.cs +++ b/src/SMAPI/Framework/ContentCoordinator.cs @@ -137,7 +137,7 @@ namespace StardewModdingAPI.Framework this.ContentManagers.Add(contentManagerForAssetPropagation); this.VanillaContentManager = new LocalizedContentManager(serviceProvider, rootDirectory); this.CoreAssets = new CoreAssetPropagator(this.MainContentManager, contentManagerForAssetPropagation, this.Monitor, reflection, aggressiveMemoryOptimizations); - this.LocaleCodes = new Lazy>(() => this.GetLocaleCodes(includeCustomLanguages: false)); + this.LocaleCodes = new Lazy>(() => this.GetLocaleCodes(customLanguages: Enumerable.Empty())); } /// Get a new content manager which handles reading files from the game content folder with support for interception. @@ -201,7 +201,8 @@ namespace StardewModdingAPI.Framework public void OnAdditionalLanguagesInitialized() { // update locale cache for custom languages, and load it now (since languages added later won't work) - this.LocaleCodes = new Lazy>(() => this.GetLocaleCodes(includeCustomLanguages: true)); + var customLanguages = this.MainContentManager.Load>("Data/AdditionalLanguages"); + this.LocaleCodes = new Lazy>(() => this.GetLocaleCodes(customLanguages)); _ = this.LocaleCodes.Value; } @@ -441,7 +442,7 @@ namespace StardewModdingAPI.Framework if (language == LocalizedContentManager.LanguageCode.mod && LocalizedContentManager.CurrentModLanguage == null) return null; - return Game1.content.LanguageCodeString(language); + return this.MainContentManager.LanguageCodeString(language); } /// Dispose held resources. @@ -495,19 +496,16 @@ namespace StardewModdingAPI.Framework } /// Get the language enums (like ) indexed by locale code (like ja-JP). - /// Whether to read custom languages from Data/AdditionalLanguages. - private Dictionary GetLocaleCodes(bool includeCustomLanguages) + /// The custom languages to add to the lookup. + private Dictionary GetLocaleCodes(IEnumerable customLanguages) { var map = new Dictionary(StringComparer.OrdinalIgnoreCase); // custom languages - if (includeCustomLanguages) + foreach (ModLanguage language in customLanguages) { - foreach (ModLanguage language in Game1.content.Load>("Data/AdditionalLanguages")) - { - if (!string.IsNullOrWhiteSpace(language?.LanguageCode)) - map[language.LanguageCode] = LocalizedContentManager.LanguageCode.mod; - } + if (!string.IsNullOrWhiteSpace(language?.LanguageCode)) + map[language.LanguageCode] = LocalizedContentManager.LanguageCode.mod; } // vanilla languages (override custom language if they conflict)