lixiaojun
2024-07-11 8d8cd298ab46aee191baf53ff320fd3290d1ec9a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Reflection;
using System.Text;
 
//界面语言
//zh-CN 简体中文
//zh-CHT 繁体中文
//en-US 美国英语
//ja-JP 日文
//de-GE 德语
//ru-RU 俄语
//ko-KO 韩语
//fr-FR 法语
//de-GE 德国
//es-ES 西班牙
namespace IStation.WinFrmUI
{
    //界面语言辅助类
    public static class Localization
    {
        //
        public static bool IsCN { get { return _currentLocation == IStation.Model.eLocalizationType.zhCN; } }
        public static bool IsEN { get { return _currentLocation == IStation.Model.eLocalizationType.enUS; } }
 
        //界面语言
        private static IStation.Model.eLocalizationType _currentLocation = IStation.Model.eLocalizationType.zhCN;
        public static IStation.Model.eLocalizationType Current
        {
            get
            {
                return _currentLocation;
            }
            set
            {
                //当前语言
                _currentLocation = value;
                //设置进程的语言,以及DEV等设置
                InitialCultureInfo();
                //设置Properties Setting变量
                SetPropertiesSetting(value);
            }
        }
        public static IStation.Model.eLocalizationType LocalizationType//历史遗漏变量, 建议使用Current
        {
            get
            {
                return _currentLocation;
            }
        }
 
        public static IStation.Common.TranslateHelper TranslateHelper = new Common.TranslateHelper();
 
 
        #region 系统语言
        /// <summary>
        /// 从System.Globalization.CultureInfo获取系统语言
        /// </summary>
        /// <returns></returns>
        public static IStation.Model.eLocalizationType GetByCultureInfo()
        {
            string globalUi = System.Globalization.CultureInfo.InstalledUICulture.Name.ToUpper();
 
            if (globalUi == "Zh-TW")
            {
                return IStation.Model.eLocalizationType.zhTW;
            }
            else if (globalUi == "EN")
            {
                return IStation.Model.eLocalizationType.enUS;
            }
            else if (globalUi == "JA")
            {
                return IStation.Model.eLocalizationType.ja;
            }
            else if (globalUi == "KO")
            {
                return IStation.Model.eLocalizationType.ko;
            }
            else if (globalUi == "RU")
            {
                return IStation.Model.eLocalizationType.ru;
            }
            else if (globalUi == "KO")
            {
                return IStation.Model.eLocalizationType.ko;
            }
            else if (globalUi == "ES")
            {
                return IStation.Model.eLocalizationType.es;
            }
            else
            {
                return IStation.Model.eLocalizationType.zhCN;
            }
        }
 
        /// <summary>
        /// 设置进程的语言以及DEV 等语言设置
        /// </summary>
        /// <returns></returns>
        private static bool InitialCultureInfo()
        {
            if (IStation.WinFrmUI.Localization.Current == IStation.Model.eLocalizationType.zhCN)
            {
                var uiCulture = new System.Globalization.CultureInfo("zh-CN");
                uiCulture.NumberFormat.CurrencyDecimalSeparator = ".";//俄文用逗号,表示小数点
                uiCulture.NumberFormat.NumberDecimalSeparator = ".";//俄文用逗号,表示小数点
                System.Threading.Thread.CurrentThread.CurrentUICulture = uiCulture;
 
                var cuurentCulture = new System.Globalization.CultureInfo("zh-CN");
                cuurentCulture.NumberFormat.CurrencyDecimalSeparator = ".";//俄文用逗号,表示小数点
                cuurentCulture.NumberFormat.NumberDecimalSeparator = ".";//俄文用逗号,表示小数点
                System.Threading.Thread.CurrentThread.CurrentCulture = cuurentCulture;
            }
            //          
            //DevExpress.Utils.AppearanceObject.DefaultFont = new System.Drawing.Font("Segoe UI", 8);
 
            return true;
        }
 
        #endregion
 
 
        #region Properties Setting 变量
        /// <summary>
        /// 设置Settings变量
        /// </summary>
        /// <param name="location"></param>
        private static void SetPropertiesSetting(IStation.Model.eLocalizationType location)
        {
            var cul = Model.LoalizationHelper.GetCultureInfoName(location);
            /* IStation.WinFrmUI.GlobalParas.Properties.Settings.Default.CurrentLocationName = cul;
             IStation.WinFrmUI.GlobalParas.Properties.Settings.Default.Save();*/
        }
        #endregion
 
        #region Configuration文件
        /// <summary>
        /// 
        /// </summary>
        /// <param name="location"></param>
        public static void SetConfigurationFile(IStation.Model.eLocalizationType location)
        {
            var cul = Model.LoalizationHelper.GetCultureInfoName(location);
            //读取程序集的配置文件
            string assemblyConfigFile = Assembly.GetEntryAssembly().Location;
            System.Configuration.Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(assemblyConfigFile);
            //获取appSettings节点
            System.Configuration.AppSettingsSection appSettings = (System.Configuration.AppSettingsSection)config.GetSection("appSettings");
 
            //删除name,然后添加新值
            appSettings.Settings.Remove("Location");
            appSettings.Settings.Add("Location", cul);
 
            //保存配置文件
            config.Save();
        }
 
        /// <summary>
        /// 从配置中获取
        /// </summary>
        /// <returns></returns>
        public static IStation.Model.eLocalizationType GetByConfigurationFile()
        {
            string locatSet = ConfigurationManager.AppSettings["Location"];
            if (!string.IsNullOrEmpty(locatSet))
            {//为空就是自由设置
                locatSet = locatSet.ToUpper();//大写
                if ("EN-US" == locatSet)//"en-US"
                {
                    return IStation.Model.eLocalizationType.enUS;
                }
                else if ("ZH-CN" == locatSet)//"ZH-CN"
                {
                    return IStation.Model.eLocalizationType.zhCN;
                }
                else if ("RU-RU" == locatSet)//"ru-RU"
                {
                    return IStation.Model.eLocalizationType.ru;
                }
                else if ("KO-KO" == locatSet)//"ko-KO"
                {
                    return IStation.Model.eLocalizationType.ko;
                }
                else if ("ES-ES" == locatSet)//"es-ES"
                {
                    return IStation.Model.eLocalizationType.es;
                }
            }
            return IStation.Model.eLocalizationType.zhCN;
        }
 
        #endregion
 
 
    }
}