Skip to content

Commit d6d105f

Browse files
committed
🌐 Set culture to LocalizeDictionary instance
- Workaround for ElementHost bug
1 parent 01f7882 commit d6d105f

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

shadowsocks-csharp/Controller/ShadowsocksController.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using Shadowsocks.Controller.Strategy;
1717
using Shadowsocks.Model;
1818
using Shadowsocks.Util;
19+
using WPFLocalizeExtension.Engine;
1920

2021
namespace Shadowsocks.Controller
2122
{
@@ -172,6 +173,8 @@ protected void Reload()
172173

173174
NLogConfig.LoadConfiguration();
174175

176+
logger.Info($"WPF Localization Extension|Current culture: {LocalizeDictionary.CurrentCulture}");
177+
175178
// set User-Agent for httpClient
176179
try
177180
{

shadowsocks-csharp/Program.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using Shadowsocks.Util;
1818
using Shadowsocks.View;
1919
using Splat;
20+
using WPFLocalizeExtension.Engine;
2021

2122
namespace Shadowsocks
2223
{
@@ -116,6 +117,12 @@ private static void Main(string[] args)
116117
// Parameters would have to be dropped from views' constructors (VersionUpdatePromptView)
117118
//Locator.CurrentMutable.RegisterViewsForViewModels(Assembly.GetCallingAssembly());
118119

120+
// Workaround for hosting WPF controls in a WinForms app.
121+
// We have to manually set the culture for the LocalizeDictionary instance.
122+
// https://stackoverflow.com/questions/374518/localizing-a-winforms-application-with-embedded-wpf-user-controls
123+
// https://stackoverflow.com/questions/14668640/wpf-localize-extension-translate-window-at-run-time
124+
LocalizeDictionary.Instance.Culture = Thread.CurrentThread.CurrentCulture;
125+
119126
#if DEBUG
120127
// truncate privoxy log file while debugging
121128
string privoxyLogFilename = Utils.GetTempPath("privoxy.log");

0 commit comments

Comments
 (0)