From d6d105fbc893cd40aa930a3d7bb39dae2224e220 Mon Sep 17 00:00:00 2001 From: database64128 Date: Sun, 18 Oct 2020 14:29:51 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=90=20Set=20culture=20to=20LocalizeDic?= =?UTF-8?q?tionary=20instance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Workaround for ElementHost bug --- shadowsocks-csharp/Controller/ShadowsocksController.cs | 3 +++ shadowsocks-csharp/Program.cs | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/shadowsocks-csharp/Controller/ShadowsocksController.cs b/shadowsocks-csharp/Controller/ShadowsocksController.cs index d1491cbd..06238c04 100644 --- a/shadowsocks-csharp/Controller/ShadowsocksController.cs +++ b/shadowsocks-csharp/Controller/ShadowsocksController.cs @@ -16,6 +16,7 @@ using Shadowsocks.Controller.Service; using Shadowsocks.Controller.Strategy; using Shadowsocks.Model; using Shadowsocks.Util; +using WPFLocalizeExtension.Engine; namespace Shadowsocks.Controller { @@ -172,6 +173,8 @@ namespace Shadowsocks.Controller NLogConfig.LoadConfiguration(); + logger.Info($"WPF Localization Extension|Current culture: {LocalizeDictionary.CurrentCulture}"); + // set User-Agent for httpClient try { diff --git a/shadowsocks-csharp/Program.cs b/shadowsocks-csharp/Program.cs index a76633fd..520f4676 100755 --- a/shadowsocks-csharp/Program.cs +++ b/shadowsocks-csharp/Program.cs @@ -17,6 +17,7 @@ using Shadowsocks.Controller.Hotkeys; using Shadowsocks.Util; using Shadowsocks.View; using Splat; +using WPFLocalizeExtension.Engine; namespace Shadowsocks { @@ -116,6 +117,12 @@ namespace Shadowsocks // Parameters would have to be dropped from views' constructors (VersionUpdatePromptView) //Locator.CurrentMutable.RegisterViewsForViewModels(Assembly.GetCallingAssembly()); + // Workaround for hosting WPF controls in a WinForms app. + // We have to manually set the culture for the LocalizeDictionary instance. + // https://stackoverflow.com/questions/374518/localizing-a-winforms-application-with-embedded-wpf-user-controls + // https://stackoverflow.com/questions/14668640/wpf-localize-extension-translate-window-at-run-time + LocalizeDictionary.Instance.Culture = Thread.CurrentThread.CurrentCulture; + #if DEBUG // truncate privoxy log file while debugging string privoxyLogFilename = Utils.GetTempPath("privoxy.log");