From 333ad2516f6cc488b7b75695ac9736c0bd44f644 Mon Sep 17 00:00:00 2001 From: Syrone Wong Date: Sat, 31 Dec 2016 19:35:37 +0800 Subject: [PATCH] Fix language detection Signed-off-by: Syrone Wong --- shadowsocks-csharp/Controller/I18N.cs | 36 ++++++++++----------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/shadowsocks-csharp/Controller/I18N.cs b/shadowsocks-csharp/Controller/I18N.cs index 6fd0ba0f..28738fe0 100755 --- a/shadowsocks-csharp/Controller/I18N.cs +++ b/shadowsocks-csharp/Controller/I18N.cs @@ -7,11 +7,11 @@ namespace Shadowsocks.Controller { using Shadowsocks.Properties; - public class I18N + public static class I18N { - protected static Dictionary Strings; + private static Dictionary _strings = new Dictionary(); - static void Init(string res) + private static void Init(string res) { using (var sr = new StringReader(res)) { @@ -23,38 +23,28 @@ namespace Shadowsocks.Controller var pos = line.IndexOf('='); if (pos < 1) continue; - Strings[line.Substring(0, pos)] = line.Substring(pos + 1); + _strings[line.Substring(0, pos)] = line.Substring(pos + 1); } } } static I18N() { - Strings = new Dictionary(); - string name = CultureInfo.CurrentCulture.Name; - if (name.StartsWith("zh")) + string name = CultureInfo.CurrentCulture.EnglishName; + if (name.StartsWith("Chinese", StringComparison.OrdinalIgnoreCase)) { - if (name == "zh" || name == "zh-CN") - { - Init(Resources.cn); - } - else - { - Init(Resources.zh_tw); - } + // choose Traditional Chinese only if we get explicit indication + Init(name.Contains("Traditional") + ? Resources.zh_tw + : Resources.cn); } } public static string GetString(string key) { - if (Strings.ContainsKey(key)) - { - return Strings[key]; - } - else - { - return key; - } + return _strings.ContainsKey(key) + ? _strings[key] + : key; } } }