summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-03-05 15:30:51 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-03-05 15:30:51 -0500
commite82406a8458b6b7d1a032f5b2120f8d84a2abf66 (patch)
treea7cc93b9e9b9060f61766c008c2734d21068a131 /src/SMAPI/Framework
parent2f279708b3529020ac0630fe96b8dd456e9cb509 (diff)
downloadSMAPI-e82406a8458b6b7d1a032f5b2120f8d84a2abf66.tar.gz
SMAPI-e82406a8458b6b7d1a032f5b2120f8d84a2abf66.tar.bz2
SMAPI-e82406a8458b6b7d1a032f5b2120f8d84a2abf66.zip
fix error loading locale code cache when a mod adds custom languages (#766)
Diffstat (limited to 'src/SMAPI/Framework')
-rw-r--r--src/SMAPI/Framework/ContentCoordinator.cs20
1 files changed, 9 insertions, 11 deletions
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<Dictionary<string, LocalizedContentManager.LanguageCode>>(() => this.GetLocaleCodes(includeCustomLanguages: false));
+ this.LocaleCodes = new Lazy<Dictionary<string, LocalizedContentManager.LanguageCode>>(() => this.GetLocaleCodes(customLanguages: Enumerable.Empty<ModLanguage>()));
}
/// <summary>Get a new content manager which handles reading files from the game content folder with support for interception.</summary>
@@ -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<Dictionary<string, LocalizedContentManager.LanguageCode>>(() => this.GetLocaleCodes(includeCustomLanguages: true));
+ var customLanguages = this.MainContentManager.Load<List<ModLanguage>>("Data/AdditionalLanguages");
+ this.LocaleCodes = new Lazy<Dictionary<string, LocalizedContentManager.LanguageCode>>(() => 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);
}
/// <summary>Dispose held resources.</summary>
@@ -495,19 +496,16 @@ namespace StardewModdingAPI.Framework
}
/// <summary>Get the language enums (like <see cref="LocalizedContentManager.LanguageCode.ja"/>) indexed by locale code (like <c>ja-JP</c>).</summary>
- /// <param name="includeCustomLanguages">Whether to read custom languages from <c>Data/AdditionalLanguages</c>.</param>
- private Dictionary<string, LocalizedContentManager.LanguageCode> GetLocaleCodes(bool includeCustomLanguages)
+ /// <param name="customLanguages">The custom languages to add to the lookup.</param>
+ private Dictionary<string, LocalizedContentManager.LanguageCode> GetLocaleCodes(IEnumerable<ModLanguage> customLanguages)
{
var map = new Dictionary<string, LocalizedContentManager.LanguageCode>(StringComparer.OrdinalIgnoreCase);
// custom languages
- if (includeCustomLanguages)
+ foreach (ModLanguage language in customLanguages)
{
- foreach (ModLanguage language in Game1.content.Load<List<ModLanguage>>("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)