summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/ContentManagers
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-04-15 00:40:45 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-09-14 17:13:53 -0400
commit6c220453e16c6cb5ad150b61cf02685a97557b3c (patch)
tree8122aaa95a9135a1d3d418fb9a932c909d261ec5 /src/SMAPI/Framework/ContentManagers
parent09d1c5a601e77c051dfde8a31f422b2c898086c3 (diff)
downloadSMAPI-6c220453e16c6cb5ad150b61cf02685a97557b3c.tar.gz
SMAPI-6c220453e16c6cb5ad150b61cf02685a97557b3c.tar.bz2
SMAPI-6c220453e16c6cb5ad150b61cf02685a97557b3c.zip
fix translatable assets not updated when switching language (#586)
Diffstat (limited to 'src/SMAPI/Framework/ContentManagers')
-rw-r--r--src/SMAPI/Framework/ContentManagers/BaseContentManager.cs3
-rw-r--r--src/SMAPI/Framework/ContentManagers/GameContentManager.cs23
-rw-r--r--src/SMAPI/Framework/ContentManagers/IContentManager.cs3
3 files changed, 29 insertions, 0 deletions
diff --git a/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs b/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs
index 7821e454..b2b3769b 100644
--- a/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs
+++ b/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs
@@ -138,6 +138,9 @@ namespace StardewModdingAPI.Framework.ContentManagers
}
}
+ /// <summary>Perform any cleanup needed when the locale changes.</summary>
+ public virtual void OnLocaleChanged() { }
+
/// <summary>Normalise path separators in a file path. For asset keys, see <see cref="AssertAndNormaliseAssetName"/> instead.</summary>
/// <param name="path">The file path to normalise.</param>
[Pure]
diff --git a/src/SMAPI/Framework/ContentManagers/GameContentManager.cs b/src/SMAPI/Framework/ContentManagers/GameContentManager.cs
index f159f035..55cf15ec 100644
--- a/src/SMAPI/Framework/ContentManagers/GameContentManager.cs
+++ b/src/SMAPI/Framework/ContentManagers/GameContentManager.cs
@@ -112,6 +112,29 @@ namespace StardewModdingAPI.Framework.ContentManagers
return data;
}
+ /// <summary>Perform any cleanup needed when the locale changes.</summary>
+ public override void OnLocaleChanged()
+ {
+ base.OnLocaleChanged();
+
+ // find assets for which a translatable version was loaded
+ HashSet<string> removeAssetNames = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
+ foreach (string key in this.IsLocalisableLookup.Where(p => p.Value).Select(p => p.Key))
+ removeAssetNames.Add(this.TryParseExplicitLanguageAssetKey(key, out string assetName, out _) ? assetName : key);
+
+ // invalidate translatable assets
+ string[] invalidated = this
+ .InvalidateCache((key, type) =>
+ removeAssetNames.Contains(key)
+ || (this.TryParseExplicitLanguageAssetKey(key, out string assetName, out _) && removeAssetNames.Contains(assetName))
+ )
+ .Select(p => p.Item1)
+ .OrderBy(p => p, StringComparer.InvariantCultureIgnoreCase)
+ .ToArray();
+ if (invalidated.Any())
+ this.Monitor.Log($"Invalidated {invalidated.Length} asset names: {string.Join(", ", invalidated)} for locale change.", LogLevel.Trace);
+ }
+
/// <summary>Create a new content manager for temporary use.</summary>
public override LocalizedContentManager CreateTemporary()
{
diff --git a/src/SMAPI/Framework/ContentManagers/IContentManager.cs b/src/SMAPI/Framework/ContentManagers/IContentManager.cs
index 17618edd..66ef9181 100644
--- a/src/SMAPI/Framework/ContentManagers/IContentManager.cs
+++ b/src/SMAPI/Framework/ContentManagers/IContentManager.cs
@@ -52,6 +52,9 @@ namespace StardewModdingAPI.Framework.ContentManagers
/// <param name="asset">The asset to clone.</param>
T CloneIfPossible<T>(T asset);
+ /// <summary>Perform any cleanup needed when the locale changes.</summary>
+ void OnLocaleChanged();
+
/// <summary>Normalise path separators in a file path. For asset keys, see <see cref="AssertAndNormaliseAssetName"/> instead.</summary>
/// <param name="path">The file path to normalise.</param>
[Pure]