在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1 public static class LangHelper 2 { 3 /// <summary> 4 /// 根据关键字获取当前语言环境下的提示信息 5 /// </summary> 6 /// <param name="key"></param> 7 /// <param name="resourceFileName"></param> 8 /// <param name="addSpaceAfter"></param> 9 /// <returns></returns> 10 public static string GetLocalizedString(string key, string resourceFileName = "Langs", bool addSpaceAfter = false) 11 { 12 var localizedString = String.Empty; 13 14 // Build up the fully-qualified name of the key 15 var assemblyName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name; 16 var fullKey = assemblyName + ":" + resourceFileName + ":" + key; 17 var locExtension = new LocExtension(fullKey); 18 locExtension.ResolveLocalizedValue(out localizedString); 19 20 // Add a space to the end, if requested 21 if (addSpaceAfter) 22 { 23 localizedString += " "; 24 } 25 26 return localizedString; 27 } 28 } 1 <Window 2 ... 3 xmlns:lex="http://wpflocalizeextension.codeplex.com" 4 lex:LocalizeDictionary.DesignCulture="en-US" 5 lex:ResxLocalizationProvider.DefaultAssembly="AppSample" 6 lex:ResxLocalizationProvider.DefaultDictionary="Langs"> 7 <!-- 解释一下 --> 8 <!-- 9 lex:LocalizeDictionary.DesignCulture="en-US" 默认en-US英文,zh-CN中文,这里采用英文 10 lex:ResxLocalizationProvider.DefaultAssembly="AppSample" AppSample为程序集名称 11 lex:ResxLocalizationProvider.DefaultDictionary="Langs" 找不到时,去找Langs资源下 12 --> 13 <!-- 其他代码 --> 14 </Window> 4 GitHub4.1 LocalizeExtension开源地址https://github.com/XAMLMarkupExtensions/WPFLocalizationExtension 4.2 测试Demo地址https://github.com/JeremyWu917/DynamicChangeLanguageSample https://www.cnblogs.com/jeremywucnblog/
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论