diff --git a/KaraokeShow/Internationalization/EmbedResourceManager.cs b/KaraokeShow/Internationalization/EmbedResourceManager.cs index b864ac3..305780e 100644 --- a/KaraokeShow/Internationalization/EmbedResourceManager.cs +++ b/KaraokeShow/Internationalization/EmbedResourceManager.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Globalization; @@ -22,7 +23,7 @@ public EmbedResourceManager(Type t) : base(t) protected override ResourceSet InternalGetResourceSet(CultureInfo culture, bool createIfNotExists, bool tryParents) { - var rs = base.InternalGetResourceSet(culture, createIfNotExists, tryParents); + var rs = (ResourceSet)ResourceSets[culture]; if (rs == null) { Stream store = null; @@ -34,12 +35,34 @@ protected override ResourceSet InternalGetResourceSet(CultureInfo culture, bool resourceFilename = GetResourceFileName(culture); store = MainAssembly.GetManifestResourceStream(_contextTypeInfo, resourceFilename); if (store != null) + { rs = new ResourceSet(store); + AddResourceSet(ResourceSets, culture, ref rs); + } else rs = base.InternalGetResourceSet(culture, createIfNotExists, tryParents); } return rs; } + private static void AddResourceSet(Hashtable localResourceSets, CultureInfo culture, ref ResourceSet rs) + { + lock (localResourceSets) + { + ResourceSet objA = (ResourceSet)localResourceSets[culture]; + if (objA != null) + { + if (!object.Equals(objA, rs)) + { + rs.Dispose(); + rs = objA; + } + } + else + { + localResourceSets.Add(culture, rs); + } + } + } } } diff --git a/KaraokeShow/Internationalization/InternationalizationManager.cs b/KaraokeShow/Internationalization/InternationalizationManager.cs index f137a5a..1a53858 100644 --- a/KaraokeShow/Internationalization/InternationalizationManager.cs +++ b/KaraokeShow/Internationalization/InternationalizationManager.cs @@ -5,11 +5,13 @@ using System.Threading; using System.Globalization; using System.Windows.Forms; +using System.Resources; namespace MusicBeePlugin.Internationalization { class InternationalizationManager { + private static ResourceManager resMan = new EmbedResourceManager(typeof(Properties.Resources)); public static string CultureText { get; set; } = "en"; public static void SetCurrentLanguage(string mbMainField173Text) { @@ -26,6 +28,11 @@ public static void EnableLanguage() Thread.CurrentThread.CurrentUICulture = new CultureInfo(CultureText); } + public static string GetResourceString(string stringName) + { + return resMan.GetString(stringName, new CultureInfo(CultureText)); + } + public static void ApplyResourceToWinForm(Control c) { var res = new EmbedResourceManager(c.GetType()); diff --git a/KaraokeShow/Plugin.cs b/KaraokeShow/Plugin.cs index e3f0d93..947f6af 100644 --- a/KaraokeShow/Plugin.cs +++ b/KaraokeShow/Plugin.cs @@ -9,6 +9,7 @@ using MusicBeePlugin.Window; using MusicBeePlugin.Parser; using MusicBeePlugin.Internationalization; +using System.Resources; namespace MusicBeePlugin { @@ -31,7 +32,7 @@ public PluginInfo Initialise(IntPtr apiInterfacePtr) about.PluginInfoVersion = PluginInfoVersion; about.Name = "KaraokeShow"; - about.Description = Properties.Resources.Plugin_PluginDescription; + about.Description = InternationalizationManager.GetResourceString("Plugin.PluginDescription"); about.Author = "Samersions"; about.TargetApplication = ""; // the name of a Plugin Storage device or panel header for a dockable panel about.Type = PluginType.General;