public static string GetChineseValueByParam(string EnglishValue, string languageCategory, string fileName, string languageType = "zh") { if (languageType.IndexOf("English") >= 0) { return(EnglishValue); } else { string value = MemoryCacheUtils.Get(EnglishValue) as string; if (string.IsNullOrEmpty(value)) { //获取语言数据 string filePath = AppDomain.CurrentDomain.BaseDirectory + @"App_Data\" + fileName + ".json"; String jsonStr = Common.GetFileJson(filePath); value = GetKeyValue(jsonStr, languageCategory, EnglishValue); } return(value); } }
/// <summary> /// 根据中文字符获取对应的英文字符 /// </summary> /// <param name="chineseValue"></param> /// <param name="languageCategory"></param> /// <returns></returns> public static string GetLanguageValueByParam(string chineseValue, string languageCategory, string fileName, string languageType = "zh") { //string ls_lan2 = Request.Headers["Accept-Language"].ToString(); //string languageType = System.Threading.Thread.CurrentThread.CurrentCulture.Name; if (languageType.IndexOf("English") < 0) { return(chineseValue); } else { string value = MemoryCacheUtils.Get(chineseValue) as string; if (string.IsNullOrEmpty(value)) { //获取语言数据 string filePath = AppDomain.CurrentDomain.BaseDirectory + @"App_Data\" + fileName + ".json"; String jsonStr = Common.GetFileJson(filePath); value = GetKeyValue(jsonStr, languageCategory, chineseValue); } return(value); } }
/// <summary> /// 根据chineseValue获取值,并将相关的数据,加入缓存 /// </summary> /// <param name="json"></param> /// <param name="languageType"></param> /// <param name="KeyValue"></param> /// <returns></returns> public static string GetKeyValue(string json, string languageType, string KeyValue) { Dictionary <string, string> keyList = new Dictionary <string, string>(); JObject jsonObj = JObject.Parse(json); JObject BasicObj = ((JObject)jsonObj[languageType]); foreach (var item in BasicObj.Properties()) { string value = MemoryCacheUtils.Get(item.Name) as string; if (string.IsNullOrEmpty(value)) { MemoryCacheUtils.Set(item.Name, ((JValue)BasicObj[item.Name]).Value.ToString()); } } if (((JValue)BasicObj[KeyValue]) != null) { return(((JValue)BasicObj[KeyValue]).Value.ToString()); } else { return(""); } }