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