我所在的公司是做SAAS软件,用户群体是面向全球的,因此对应业务系统国际化就是顺理成章的事情。
其实国际化重点在于多语言支持,本文就从这方面入手。
多语言
如上解决方案截图,BQoolCommon.Resource是多语言资源工程,下面来看看具体怎么实现:
2.1、定义多语言资源文件
以支持中(繁体、简体)英文为例,定义如下图资源文件
资源文件中定义的资源配置项如下:
生成对应的键值对属性
/// <summary>/// 查詢類似 01:00 的當地語系化字串。/// </summary>public static string SettingDailyAt_1 {get {return ResourceManager.GetString("SettingDailyAt_1", resourceCulture);}}/// <summary>/// 查詢類似 10:00 的當地語系化字串。/// </summary>public static string SettingDailyAt_10 {get {return ResourceManager.GetString("SettingDailyAt_10", resourceCulture);}}/// <summary>/// 查詢類似 11:00 的當地語系化字串。/// </summary>public static string SettingDailyAt_11 {get {return ResourceManager.GetString("SettingDailyAt_11", resourceCulture);}}/// <summary>/// 查詢類似 12:00 的當地語系化字串。/// </summary>public static string SettingDailyAt_12 {get {return ResourceManager.GetString("SettingDailyAt_12", resourceCulture);}}/// <summary>/// 查詢類似 13:00 的當地語系化字串。/// </summary>public static string SettingDailyAt_13 {get {return ResourceManager.GetString("SettingDailyAt_13", resourceCulture);}}/// <summary>/// 查詢類似 14:00 的當地語系化字串。/// </summary>public static string SettingDailyAt_14 {get {return ResourceManager.GetString("SettingDailyAt_14", resourceCulture);}}/// <summary>/// 查詢類似 15:00 的當地語系化字串。/// </summary>public static string SettingDailyAt_15 {get {return ResourceManager.GetString("SettingDailyAt_15", resourceCulture);}}/// <summary>/// 查詢類似 16:00 的當地語系化字串。/// </summary>public static string SettingDailyAt_16 {get {return ResourceManager.GetString("SettingDailyAt_16", resourceCulture);}}/// <summary>/// 查詢類似 17:00 的當地語系化字串。/// </summary>public static string SettingDailyAt_17 {get {return ResourceManager.GetString("SettingDailyAt_17", resourceCulture);}}/// <summary>/// 查詢類似 18:00 的當地語系化字串。/// </summary>public static string SettingDailyAt_18 {get {return ResourceManager.GetString("SettingDailyAt_18", resourceCulture);}}/// <summary>/// 查詢類似 19:00 的當地語系化字串。/// </summary>public static string SettingDailyAt_19 {get {return ResourceManager.GetString("SettingDailyAt_19", resourceCulture);}}/// <summary>/// 查詢類似 02:00 的當地語系化字串。/// </summary>public static string SettingDailyAt_2 {get {return ResourceManager.GetString("SettingDailyAt_2", resourceCulture);}}/// <summary>/// 查詢類似 20:00 的當地語系化字串。/// </summary>public static string SettingDailyAt_20 {get {return ResourceManager.GetString("SettingDailyAt_20", resourceCulture);}}/// <summary>/// 查詢類似 21:00 的當地語系化字串。/// </summary>public static string SettingDailyAt_21 {get {return ResourceManager.GetString("SettingDailyAt_21", resourceCulture);}}/// <summary>/// 查詢類似 22:00 的當地語系化字串。/// </summary>public static string SettingDailyAt_22 {get {return ResourceManager.GetString("SettingDailyAt_22", resourceCulture);}}/// <summary>/// 查詢類似 23:00 的當地語系化字串。/// </summary>public static string SettingDailyAt_23 {get {return ResourceManager.GetString("SettingDailyAt_23", resourceCulture);}}/// <summary>/// 查詢類似 24:00 的當地語系化字串。/// </summary>public static string SettingDailyAt_24 {get {return ResourceManager.GetString("SettingDailyAt_24", resourceCulture);}}/// <summary>/// 查詢類似 03:00 的當地語系化字串。/// </summary>public static string SettingDailyAt_3 {get {return ResourceManager.GetString("SettingDailyAt_3", resourceCulture);}}/// <summary>/// 查詢類似 04:00 的當地語系化字串。/// </summary>public static string SettingDailyAt_4 {get {return ResourceManager.GetString("SettingDailyAt_4", resourceCulture);}}/// <summary>/// 查詢類似 05:00 的當地語系化字串。/// </summary>public static string SettingDailyAt_5 {get {return ResourceManager.GetString("SettingDailyAt_5", resourceCulture);}}/// <summary>/// 查詢類似 06:00 的當地語系化字串。/// </summary>public static string SettingDailyAt_6 {get {return ResourceManager.GetString("SettingDailyAt_6", resourceCulture);}}/// <summary>/// 查詢類似 07:00 的當地語系化字串。/// </summary>public static string SettingDailyAt_7 {get {return ResourceManager.GetString("SettingDailyAt_7", resourceCulture);}}/// <summary>/// 查詢類似 08:00 的當地語系化字串。/// </summary>public static string SettingDailyAt_8 {get {return ResourceManager.GetString("SettingDailyAt_8", resourceCulture);}}/// <summary>/// 查詢類似 09:00 的當地語系化字串。/// </summary>public static string SettingDailyAt_9 {get {return ResourceManager.GetString("SettingDailyAt_9", resourceCulture);}}
2.2、使用
项目当中引用对应的资源类库
使用翻译文本
<div class="line01"></div>
<div class="button_area align_r">@CommonUIHelper.BuildCloseColorboxButton(PreferenceElement.Cancel)<button class="button02 jqAddFilter">@FavoriteFilterElement.Save</button>
</div>
设置可供用户设置的语言选项
用户选择对应语系的时候,进行语系切换,如下英文切换
#region set Culture en-USThread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");#endregion set Culture en-US
效果如下