You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
4.1 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICSharpCode.Core;
namespace Mesnac.Basic
{
/// <summary>
/// 国际化语言区域处理辅助类
/// </summary>
public class LanguageHelper
{
#region 事件定义
public static event EventHandler LanguageChanged;
#endregion
#region 属性定义
/// <summary>
/// 提示
/// </summary>
public static string Caption
{
get
{
string caption = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_Caption")); //提示
return caption;
}
}
/// <summary>
/// 警告
/// </summary>
public static string WarnCaption
{
get
{
string warnCption = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_WarnCaption")); //警告
return warnCption;
}
}
/// <summary>
/// 错误
/// </summary>
public static string ErrorCaption
{
get
{
string errorCption = StringParser.Parse(ResourceService.GetString("Mesnac_Dialog_ErrorCaption")); //错误
return errorCption;
}
}
/// <summary>
/// 数据库连接失败信息
/// </summary>
public static string DataBaseConnectError
{
get
{
string databaseconnecterror = StringParser.Parse(ResourceService.GetString("Mesnac_Msg_DataBaseConnect_Error")); //获取数据连接失败,请检查数据库连接字符串是否正确!
return databaseconnecterror;
}
}
/// <summary>
/// 请选择
/// </summary>
public static string PleaseSelect
{
get
{
string pleaseSelectText = StringParser.Parse(ResourceService.GetString("Mesnac_Msg_PleaseSelect_Text")); //--请选择--
return pleaseSelectText;
}
}
#endregion
#region 方法定义
/// <summary>
/// 设置语言区域信息
/// </summary>
/// <param name="cultureName">区域语言en/zh</param>
public static void SetCurrentCultureInfo(string cultureName)
{
if (!String.IsNullOrEmpty(cultureName))
{
try
{
string currCultureName = System.Threading.Thread.CurrentThread.CurrentUICulture.Name;
if (currCultureName != cultureName)
{
System.Globalization.CultureInfo currentUICulture = new System.Globalization.CultureInfo(cultureName);
System.Threading.Thread.CurrentThread.CurrentUICulture = currentUICulture;
ICSharpCode.Core.PropertyService.Set<string>(ResourceService.CultureProperty, cultureName);
#region 触发语言切换事件
if (LanguageChanged != null)
{
LanguageChanged(null, System.EventArgs.Empty);
}
#endregion
}
}
catch (Exception e)
{
ICSharpCode.Core.LoggingService<LanguageHelper>.Error(e.Message);
}
}
}
/// <summary>
/// 刷新新线程的语言区域信息
/// </summary>
public static void RefreshCultureInfo()
{
string cultureName = ICSharpCode.Core.PropertyService.Get<string>(ResourceService.CultureProperty, "zh-CN");
if (!String.IsNullOrEmpty(cultureName))
{
System.Globalization.CultureInfo currentUICulture = new System.Globalization.CultureInfo(cultureName);
System.Threading.Thread.CurrentThread.CurrentUICulture = currentUICulture;
}
}
#endregion
}
}