public JsonResult Create(LanguageType obj) { try { NSession.SaveOrUpdate(obj); NSession.Flush(); Language.ReLoadLanguage(); } catch (Exception ee) { return Json(new { IsSuccess = false, ErrorMsg = "出错了" }); } return Json(new { IsSuccess = true }); }
public static string GetString(string language, string nativeText) { string nativeLanguage = "zh-Hans"; if (language.Equals("zh-CN", StringComparison.OrdinalIgnoreCase)) { language = nativeLanguage; } if (nativeText == "ShowLanguageLocale123") { return language; } if (string.IsNullOrWhiteSpace(language)) { //没有指定显示语言的情况下 language = System.Web.HttpContext.Current.Request.UserLanguages.Length > 0 ? System.Web.HttpContext.Current.Request.UserLanguages[0] : nativeLanguage; } //System.Web.UI.Page page=System.Web.HttpContext.Current.CurrentHandler as System.Web.UI.Page; //page.ClientScript.RegisterClientScriptBlock(page.GetType(), "language", "alert('sss')", true); if (string.IsNullOrWhiteSpace(nativeText)) { nativeText = string.Empty; } else { nativeText = nativeText.Trim(); } if (language.Equals(nativeLanguage, StringComparison.OrdinalIgnoreCase)) { //如果是默认语言,则返回母语 return nativeText; } else { if (languageList == null) { ReLoadLanguage(); } List<LanguageType> rl = languageList.Where(l => l.Language.Equals(language, StringComparison.OrdinalIgnoreCase) && l.NativeLanguage.Equals(nativeText, StringComparison.OrdinalIgnoreCase)).ToList(); if (rl.Any()) { return rl[0].Enable ? rl[0].Text : "#" + nativeText; } else { LanguageType ttt = new LanguageType() { //Id="ID_"+language+"_"+nativeText, Language = language, NativeLanguage = nativeText, Text = nativeText, Enable = false }; ISession NSession = NhbHelper.OpenSession(); NSession.SaveOrUpdate(ttt); NSession.Flush(); NSession.Close(); NSession.Dispose(); ReLoadLanguage(); return "#" + nativeText; } } }