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
|
|
|
}
|
}
|