summaryrefslogtreecommitdiff
path: root/src/SMAPI
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-05-16 19:16:08 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-09-14 17:58:33 -0400
commit5cd5e2416dfe6eab1a36be1646890d57f3f4a191 (patch)
tree96b6da3fa805a4caff1fe5c5587f8001e3025257 /src/SMAPI
parentf2dd11fe3fbe8b31665ad25e6e58b0026c00098e (diff)
downloadSMAPI-5cd5e2416dfe6eab1a36be1646890d57f3f4a191.tar.gz
SMAPI-5cd5e2416dfe6eab1a36be1646890d57f3f4a191.tar.bz2
SMAPI-5cd5e2416dfe6eab1a36be1646890d57f3f4a191.zip
fix cache misses for non-English players
Diffstat (limited to 'src/SMAPI')
-rw-r--r--src/SMAPI/Framework/ContentManagers/GameContentManager.cs32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/SMAPI/Framework/ContentManagers/GameContentManager.cs b/src/SMAPI/Framework/ContentManagers/GameContentManager.cs
index 6ce50f00..085982b6 100644
--- a/src/SMAPI/Framework/ContentManagers/GameContentManager.cs
+++ b/src/SMAPI/Framework/ContentManagers/GameContentManager.cs
@@ -119,15 +119,28 @@ namespace StardewModdingAPI.Framework.ContentManagers
/// <param name="language">The language code for which to inject the asset.</param>
public override void Inject<T>(string assetName, T value, LanguageCode language)
{
+ // handle explicit language in asset name
+ {
+ if (this.TryParseExplicitLanguageAssetKey(assetName, out string newAssetName, out LanguageCode newLanguage))
+ {
+ this.Inject(newAssetName, value, newLanguage);
+ return;
+ }
+ }
base.Inject(assetName, value, language);
// track whether the injected asset is translatable for is-loaded lookups
- bool isTranslated = this.TryParseExplicitLanguageAssetKey(assetName, out _, out _);
- string localisedKey = isTranslated ? assetName : $"{assetName}.{language}";
- if (this.Cache.ContainsKey(localisedKey))
- this.IsLocalisableLookup[localisedKey] = true;
- else if (!isTranslated && this.Cache.ContainsKey(assetName))
- this.IsLocalisableLookup[localisedKey] = false;
+ string keyWithLocale = $"{assetName}.{this.GetLocale(language)}";
+ if (this.Cache.ContainsKey(keyWithLocale))
+ {
+ this.IsLocalisableLookup[assetName] = true;
+ this.IsLocalisableLookup[keyWithLocale] = true;
+ }
+ else if (this.Cache.ContainsKey(assetName))
+ {
+ this.IsLocalisableLookup[assetName] = false;
+ this.IsLocalisableLookup[keyWithLocale] = false;
+ }
else
this.Monitor.Log($"Asset '{assetName}' could not be found in the cache immediately after injection.", LogLevel.Error);
}
@@ -174,11 +187,11 @@ namespace StardewModdingAPI.Framework.ContentManagers
return this.Cache.ContainsKey(normalisedAssetName);
// translated
- string localisedKey = $"{normalisedAssetName}.{this.GetLocale(this.GetCurrentLanguage())}";
- if (this.IsLocalisableLookup.TryGetValue(localisedKey, out bool localisable))
+ string keyWithLocale = $"{normalisedAssetName}.{this.GetLocale(this.GetCurrentLanguage())}";
+ if (this.IsLocalisableLookup.TryGetValue(keyWithLocale, out bool localisable))
{
return localisable
- ? this.Cache.ContainsKey(localisedKey)
+ ? this.Cache.ContainsKey(keyWithLocale)
: this.Cache.ContainsKey(normalisedAssetName);
}
@@ -190,6 +203,7 @@ namespace StardewModdingAPI.Framework.ContentManagers
/// <param name="rawAsset">The asset key to parse.</param>
/// <param name="assetName">The asset name without the language code.</param>
/// <param name="language">The language code removed from the asset name.</param>
+ /// <returns>Returns whether the asset key contains an explicit language and was successfully parsed.</returns>
private bool TryParseExplicitLanguageAssetKey(string rawAsset, out string assetName, out LanguageCode language)
{
if (string.IsNullOrWhiteSpace(rawAsset))