Skip to content

Commit

Permalink
Merge pull request #18 from SamLangTen/develop
Browse files Browse the repository at this point in the history
enable embed resource manager
  • Loading branch information
SamLangTen authored Apr 16, 2020
2 parents 287db6b + c1e2902 commit af9d6b4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
25 changes: 24 additions & 1 deletion KaraokeShow/Internationalization/EmbedResourceManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
Expand All @@ -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;
Expand All @@ -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);
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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());
Expand Down
3 changes: 2 additions & 1 deletion KaraokeShow/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using MusicBeePlugin.Window;
using MusicBeePlugin.Parser;
using MusicBeePlugin.Internationalization;
using System.Resources;

namespace MusicBeePlugin
{
Expand All @@ -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;
Expand Down

0 comments on commit af9d6b4

Please sign in to comment.