/// <summary> /// This method is called by ASP.NET system when a request starts. /// </summary> protected virtual void Application_BeginRequest(object sender, EventArgs e) { //获取cookie语言环境值 var langCookie = Request.Cookies["Abp.Localization.CultureName"]; if (langCookie != null && GlobalizationHelper.IsValidCultureCode(langCookie.Value)) { //设置当前语言环境 Thread.CurrentThread.CurrentCulture = new CultureInfo(langCookie.Value); Thread.CurrentThread.CurrentUICulture = new CultureInfo(langCookie.Value); } else if (!Request.UserLanguages.IsNullOrEmpty()) { //获取客户端默认语言环境 var firstValidLanguage = Request .UserLanguages .FirstOrDefault(GlobalizationHelper.IsValidCultureCode); if (firstValidLanguage != null) { Thread.CurrentThread.CurrentCulture = new CultureInfo(firstValidLanguage); Thread.CurrentThread.CurrentUICulture = new CultureInfo(firstValidLanguage); } } }
public async virtual Task <IActionResult> ChangeScheduler(string schedulerName) { if (!await GlobalizationHelper.IsValidSchedulerName(schedulerName)) { throw new Exception("Unknown scheduler: " + schedulerName + ". It must be a valid scheduler!"); } string cookieValue = Crypto.DesEncrypt(schedulerName); Response.Cookies.Append( HybridConsts.SchedulerCookieName, cookieValue, new CookieOptions { Expires = DateTime.UtcNow.AddYears(2), HttpOnly = true } ); if (Request.IsAjaxRequest()) { return(Json(new AjaxResult())); } string queryString = Request.QueryString.Value; string returnUrl = queryString.Split("returnUrl=")[1]; if (!string.IsNullOrWhiteSpace(returnUrl) && returnUrl.IsLocalUrl(Request)) { return(Redirect(returnUrl)); } return(Redirect("/")); //: Go to app root }
/// <summary> /// Returns a dictionary translation for the specified dictionary term. /// </summary> /// <param name="term"> /// The Umbraco dictionary term. /// </param> /// <returns> /// The translation. /// </returns> public static string GetDictionaryTranslation(string term) { var requestUrl = HttpContext.Current.Request.Url.ToString(); var culture = GlobalizationHelper.GetCulture(requestUrl); return(GetDictionaryTranslation(term, culture)); }
public virtual ActionResult ChangeCulture(string cultureName, string returnUrl = "") { if (!GlobalizationHelper.IsValidCultureCode(cultureName)) { throw new AbpException("Unknown language: " + cultureName + ". It must be a valid culture!"); } Response.Cookies.Add( new HttpCookie(_webLocalizationConfiguration.CookieName, cultureName) { Expires = Clock.Now.AddYears(2) } ); if (AbpSession.UserId.HasValue) { SettingManager.ChangeSettingForUser( AbpSession.ToUserIdentifier(), LocalizationSettingNames.DefaultLanguage, cultureName ); } if (Request.IsAjaxRequest()) { return(Json(new AjaxResponse(), JsonRequestBehavior.AllowGet)); } if (!string.IsNullOrWhiteSpace(returnUrl) && Request.Url != null && AbpUrlHelper.IsLocalUrl(Request.Url, returnUrl)) { return(Redirect(returnUrl)); } return(Redirect(Request.ApplicationPath)); }
public virtual ActionResult ChangeCulture(string cultureName, string returnUrl = "") { if (!GlobalizationHelper.IsValidCultureCode(cultureName)) { throw new AbpException("Unknown language: " + cultureName + ". It must be a valid culture!"); } var cookieValue = CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(cultureName, cultureName)); Response.Cookies.Append( CookieRequestCultureProvider.DefaultCookieName, cookieValue, new CookieOptions { Expires = Clock.Now.AddYears(2) } ); if (Request.IsAjaxRequest()) { return(Json(new MvcAjaxResponse())); } if (!string.IsNullOrWhiteSpace(returnUrl)) { return(Redirect(returnUrl)); } return(Redirect("/")); //TODO: Go to app root }
/// <summary> /// Gets the node containing the translations. /// </summary> /// <param name="page"> /// The node to get the translation node for. /// </param> /// <returns> /// The node containing the translations. /// </returns> public static IPublishedContent GetTranslationNode(IPublishedContent page) { // Variables. var requestUrl = HttpContext.Current.Request.Url.ToString(); var culture = GlobalizationHelper.GetCulture(requestUrl); // Return translation node. return(GetTranslationNode(page, culture)); }
protected virtual string GetCultureFromHeader(HttpContext httpContext) { var culture = httpContext.Request.Headers[_webLocalizationConfiguration.CookieName]; if (culture.IsNullOrEmpty() || !GlobalizationHelper.IsValidCultureCode(culture)) { return(null); } return(culture); }
/// <summary> /// This method is called by ASP.NET system when a request starts. /// </summary> protected virtual void Application_BeginRequest(object sender, EventArgs e) { var langCookie = Request.Cookies["Abp.Localization.CultureName"]; if (langCookie != null && GlobalizationHelper.IsValidCultureCode(langCookie.Value)) { Thread.CurrentThread.CurrentCulture = new CultureInfo(langCookie.Value); Thread.CurrentThread.CurrentUICulture = new CultureInfo(langCookie.Value); } }
protected virtual string GetDefaultCulture() { var culture = _settingManager.GetSettingValue(LocalizationSettingNames.DefaultLanguage); if (culture.IsNullOrEmpty() || !GlobalizationHelper.IsValidCultureCode(culture)) { return(null); } return(culture); }
protected virtual string GetCultureFromQueryString(HttpContext httpContext) { // var culture = httpContext.Request.QueryString[_webLocalizationConfiguration.CookieName]; var culture = httpContext.Request["cultureName"]; if (culture.IsNullOrEmpty() || !GlobalizationHelper.IsValidCultureCode(culture)) { return(null); } return(culture); }
public override Task <ProviderCultureResult> DetermineProviderCultureResult(HttpContext httpContext) { var defaultLanguage = _settingManager.GetSettingValue(LocalizationSettingNames.DefaultLanguage); if (defaultLanguage.IsNullOrEmpty() || !GlobalizationHelper.IsValidCultureCode(defaultLanguage)) { return(Task.FromResult((ProviderCultureResult)null)); } var providerResultCulture = new ProviderCultureResult(defaultLanguage, defaultLanguage); return(Task.FromResult(providerResultCulture)); }
/// <include file='Doc/en_EN/FbParameterCollection.xml' path='doc/class[@name="FbParameterCollection"]/method[@name="IndexOf(System.String)"]/*'/> public int IndexOf(string parameterName) { int index = 0; foreach (FbParameter item in this.parameters) { if (GlobalizationHelper.CultureAwareCompare(item.ParameterName, parameterName)) { return(index); } index++; } return(-1); }
/// <include file='Doc/en_EN/FbDataReader.xml' path='doc/class[@name="FbDataReader"]/method[@name="GetOrdinal(System.String)"]/*'/> public int GetOrdinal(string name) { this.CheckState(); for (int i = 0; i < this.fields.Count; i++) { if (GlobalizationHelper.CultureAwareCompare(name, this.fields[i].Alias)) { return(i); } } throw new IndexOutOfRangeException("Could not find specified column in results."); }
public virtual ActionResult ChangeCulture(string cultureName, string returnUrl = "") { if (!GlobalizationHelper.IsValidCultureCode(cultureName)) { throw new AbpException("Unknown language: " + cultureName + ". It must be a valid culture!"); } var cookieValue = CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(cultureName, cultureName)); Response.Cookies.Append( CookieRequestCultureProvider.DefaultCookieName, cookieValue, new CookieOptions { Expires = Clock.Now.AddYears(2), HttpOnly = true } ); if (AbpSession.UserId.HasValue) { SettingManager.ChangeSettingForUser( AbpSession.ToUserIdentifier(), LocalizationSettingNames.DefaultLanguage, cultureName ); } if (Request.IsAjaxRequest()) { return(Json(new AjaxResponse())); } if (!string.IsNullOrWhiteSpace(returnUrl)) { var escapedReturnUrl = Uri.EscapeDataString(returnUrl); var localPath = UrlHelper.LocalPathAndQuery(escapedReturnUrl, Request.Host.Host, Request.Host.Port); if (!string.IsNullOrWhiteSpace(localPath)) { var unescapedLocalPath = Uri.UnescapeDataString(localPath); if (Url.IsLocalUrl(unescapedLocalPath)) { return(LocalRedirect(unescapedLocalPath)); } } } return(LocalRedirect("/")); //TODO: Go to app root }
internal int IndexOf(string errorMessage) { int index = 0; foreach (FbError item in this) { if (GlobalizationHelper.CultureAwareCompare(item.Message, errorMessage)) { return(index); } index++; } return(-1); }
public virtual ActionResult ChangeCulture(string cultureName, string returnUrl = "") { if (!GlobalizationHelper.IsValidCultureCode(cultureName)) { throw new AbpException("Unknown language: " + cultureName + ". It must be a valid culture!"); } Response.Cookies.Add( new HttpCookie(WebLocalizationConfiguration.CookieName, cultureName) { Expires = Clock.Now.AddYears(2), Path = Request.ApplicationPath } ); if (AbpSession.UserId.HasValue) { SettingManager.ChangeSettingForUser( AbpSession.ToUserIdentifier(), LocalizationSettingNames.DefaultLanguage, cultureName ); } if (Request.IsAjaxRequest()) { return(Json(new AjaxResponse(), JsonRequestBehavior.AllowGet)); } if (!string.IsNullOrWhiteSpace(returnUrl)) { var escapedReturnUrl = Uri.EscapeUriString(returnUrl); var localPath = UrlHelper.LocalPathAndQuery(escapedReturnUrl, Request.Url.Host, Request.Url.Port); if (!string.IsNullOrWhiteSpace(localPath)) { var unescapedLocalPath = Uri.UnescapeDataString(localPath); if (Url.IsLocalUrl(unescapedLocalPath)) { return(Redirect(unescapedLocalPath)); } } } return(Redirect(Request.ApplicationPath)); }
/// <summary> /// Searches for cities that match the given cityName, countryCode and countyName, /// returning a list of matching cities. /// </summary> /// <param name="cityName">Mandatory. Name of the city to search for.</param> /// <param name="countryCode">Optional. Two letter country code for the city to search for.</param> /// <param name="countryName">Optional. Name of the country to search for. </param> public async Task <IList <City> > SearchForCities(string cityName, string countryCode = null, string countryName = null) { string requestUri = string.Empty; if (countryCode == null && countryName != null) { GlobalizationHelper globalizationHelper = new GlobalizationHelper(); countryCode = globalizationHelper.GetCountryCode(countryName); } if (countryCode != null) { requestUri = $"{_serachBaseUrl}{cityName},{countryCode}&type=like&appid={_searchApiKey}"; } else { requestUri = $"{_serachBaseUrl}{cityName}&type=like&appid={_searchApiKey}"; } HttpClient client = new HttpClient { BaseAddress = new Uri(requestUri) }; client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = await client.GetAsync(requestUri); if (response.IsSuccessStatusCode) { string responseJsonString = await response.Content.ReadAsStringAsync(); WeatherSearchResultDto deserializedProduct = JsonConvert.DeserializeObject <WeatherSearchResultDto>(responseJsonString); IDomainMapper <WeatherSearchResultDto, IList <City> > cityMapper = new CityMap(); IList <City> cityList = cityMapper.MapTo(deserializedProduct); return(cityList); } return(null); }
protected virtual void SetCurrentCulture() { var langCookie = Request.Cookies["Abp.Localization.CultureName"]; if (langCookie != null && GlobalizationHelper.IsValidCultureCode(langCookie.Value)) { Thread.CurrentThread.CurrentCulture = new CultureInfo(langCookie.Value); Thread.CurrentThread.CurrentUICulture = new CultureInfo(langCookie.Value); } else if (!Request.UserLanguages.IsNullOrEmpty()) { var firstValidLanguage = Request?.UserLanguages?.FirstOrDefault(GlobalizationHelper.IsValidCultureCode); if (firstValidLanguage != null) { Thread.CurrentThread.CurrentCulture = new CultureInfo(firstValidLanguage); Thread.CurrentThread.CurrentUICulture = new CultureInfo(firstValidLanguage); } } }
/// <summary> /// 设置当前区域信息 /// </summary> protected virtual void SetCurrentCulture() { var globalizationSection = WebConfigurationManager.GetSection("globalization") as GlobalizationSection; if (globalizationSection != null && !globalizationSection.UICulture.IsNullOrEmpty() && !string.Equals(globalizationSection.UICulture, "auto", StringComparison.InvariantCultureIgnoreCase)) { return; } var langCookie = Request.Cookies[_webLocalizationConfiguration.CookieName]; if (langCookie != null && GlobalizationHelper.IsValidCultureCode(langCookie.Value)) { Thread.CurrentThread.CurrentCulture = new CultureInfo(langCookie.Value); Thread.CurrentThread.CurrentUICulture = new CultureInfo(langCookie.Value); return; } var defaultLanguage = AbpBootstrapper.IocManager.Using <ISettingManager, string>(settingManager => settingManager.GetSettingValue(LocalizationSettingNames.DefaultLanguage)); if (!defaultLanguage.IsNullOrEmpty() && GlobalizationHelper.IsValidCultureCode(defaultLanguage)) { Thread.CurrentThread.CurrentCulture = new CultureInfo(defaultLanguage); Thread.CurrentThread.CurrentUICulture = new CultureInfo(defaultLanguage); Response.SetCookie(new HttpCookie(_webLocalizationConfiguration.CookieName, defaultLanguage)); return; } if (!Request.UserLanguages.IsNullOrEmpty()) { var firstValidLanguage = Request?.UserLanguages?.FirstOrDefault(GlobalizationHelper.IsValidCultureCode); if (firstValidLanguage != null) { Thread.CurrentThread.CurrentCulture = new CultureInfo(firstValidLanguage); Thread.CurrentThread.CurrentUICulture = new CultureInfo(firstValidLanguage); Response.SetCookie(new HttpCookie(_webLocalizationConfiguration.CookieName, firstValidLanguage)); } } }
private string GetCultureFromUserSetting() { if (_CodeZeroSession.UserId == null) { return(null); } var culture = _settingManager.GetSettingValueForUser( LocalizationSettingNames.DefaultLanguage, _CodeZeroSession.TenantId, _CodeZeroSession.UserId.Value, fallbackToDefault: false ); if (culture.IsNullOrEmpty() || !GlobalizationHelper.IsValidCultureCode(culture)) { return(null); } return(culture); }
public virtual ActionResult ChangeCulture(string cultureName, string returnUrl = "") { if (!GlobalizationHelper.IsValidCultureCode(cultureName)) { throw new CodeZeroException("Unknown language: " + cultureName + ". It must be a valid culture!"); } var cookieValue = CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(cultureName, cultureName)); Response.Cookies.Append( CookieRequestCultureProvider.DefaultCookieName, cookieValue, new CookieOptions { Expires = Clock.Now.AddYears(2), HttpOnly = true } ); if (CodeZeroSession.UserId.HasValue) { SettingManager.ChangeSettingForUser( CodeZeroSession.ToUserIdentifier(), LocalizationSettingNames.DefaultLanguage, cultureName ); } if (Request.IsAjaxRequest()) { return(Json(new AjaxResponse())); } if (!string.IsNullOrWhiteSpace(returnUrl) && CodeZeroUrlHelper.IsLocalUrl(Request, returnUrl)) { return(Redirect(returnUrl)); } return(Redirect("/")); //TODO: Go to app root }
public virtual ActionResult ChangeCulture(string cultureName, string returnUrl = "") { if (!GlobalizationHelper.IsValidCultureCode(cultureName)) { throw new Exception("Unknown language: " + cultureName + ". It must be a valid culture!"); } Response.Cookies.Add( new HttpCookie(_webLocalizationConfiguration.CookieName, cultureName) { Expires = DateTime.Now.AddYears(2), Path = Request.ApplicationPath } ); ValidatorOptions.LanguageManager.Enabled = true; ValidatorOptions.LanguageManager.Culture = new System.Globalization.CultureInfo(cultureName); if (!string.IsNullOrWhiteSpace(returnUrl) && Request.Url != null)// && AbpUrlHelper.IsLocalUrl(Request.Url, returnUrl)) { return(Redirect(returnUrl)); } return(Redirect(Request.ApplicationPath)); }
public virtual ActionResult ChangeCulture(string cultureName, string returnUrl = "") { if (!GlobalizationHelper.IsValidCultureCode(cultureName)) { throw new AbpException("Unknown language: " + cultureName + ". It must be a valid culture!"); } Response.Cookies.Append("Abp.Localization.CultureName", cultureName, new CookieOptions { Expires = Clock.Now.AddYears(2) }); //if (Request.IsAjaxRequest()) //{ // return Json(new MvcAjaxResponse(), JsonRequestBehavior.AllowGet); //} if (!string.IsNullOrWhiteSpace(returnUrl)) { return(Redirect(returnUrl)); } return(Redirect("/")); //return Redirect(Request.ApplicationPath); }
public ActionResult ChangeCulture(string cultureName, string returnUrl = "") { if (!GlobalizationHelper.IsValidCultureCode(cultureName)) { throw new AbpException("Unknown language: " + cultureName + ". It must be a valid culture!"); } Response.Cookies.Add(new HttpCookie("Abp.Localization.CultureName", cultureName) { Expires = DateTime.Now.AddYears(2) }); if (Request.IsAjaxRequest()) { return(Json(new AbpMvcAjaxResponse(), JsonRequestBehavior.AllowGet)); } if (!string.IsNullOrWhiteSpace(returnUrl)) { return(Redirect(returnUrl)); } return(Redirect("/")); }
/// <summary> /// Initialize page helpers. /// </summary> public override void InitHelpers() { /* * Base helpers */ base.InitHelpers(); /* * Feedback helper */ Feedback = new FeedbackHelper(Html); /* * Globalization helper */ var globalizationContext = (ViewContext.HttpContext.Items[nameof(GlobalizationContext)] as GlobalizationContext); if (globalizationContext == null) { throw new ArgumentException(nameof(InitHelpers), new ArgumentNullException(nameof(globalizationContext))); } Globalization = new GlobalizationHelper(globalizationContext.RegionCulture, globalizationContext.LanguageCulture, globalizationContext.TimeZoneInfo); }
public static string GetCultureDirection(this HtmlHelper helper) { return(GlobalizationHelper.GetCurrentCulture().TextInfo.IsRightToLeft ? "right" : "left"); }
public static string GetCultureReverseDirectionShort(this HtmlHelper helper) { return(GlobalizationHelper.GetCurrentCulture().TextInfo.IsRightToLeft ? "ltr" : "rtl"); }
public static void SetCulture(this HtmlHelper helper, CultureInfo culture) { GlobalizationHelper.SetSessionCulture(culture); //?? }
/// <summary> /// Creates a Complex32 dense vector based on a string. The string can be in the following formats (without the /// quotes): 'n', 'n;n;..', '(n;n;..)', '[n;n;...]', where n is a double. /// </summary> /// <returns> /// A Complex32 dense vector containing the values specified by the given string. /// </returns> /// <param name="value"> /// the string to parse. /// </param> /// <param name="formatProvider"> /// An <see cref="IFormatProvider"/> that supplies culture-specific formatting information. /// </param> public static DenseVector Parse(string value, IFormatProvider formatProvider) { if (value == null) { throw new ArgumentNullException(value); } value = value.Trim(); if (value.Length == 0) { throw new FormatException(); } // strip out parens if (value.StartsWith("(", StringComparison.Ordinal)) { if (!value.EndsWith(")", StringComparison.Ordinal)) { throw new FormatException(); } value = value.Substring(1, value.Length - 2).Trim(); } if (value.StartsWith("[", StringComparison.Ordinal)) { if (!value.EndsWith("]", StringComparison.Ordinal)) { throw new FormatException(); } value = value.Substring(1, value.Length - 2).Trim(); } // keywords var textInfo = formatProvider.GetTextInfo(); var keywords = new[] { textInfo.ListSeparator }; // lexing var tokens = new LinkedList <string>(); GlobalizationHelper.Tokenize(tokens.AddFirst(value), keywords, 0); var token = tokens.First; if (token == null || tokens.Count.IsEven()) { throw new FormatException(); } // parsing var data = new Complex32[(tokens.Count + 1) >> 1]; for (var i = 0; i < data.Length; i++) { if (token == null || token.Value == textInfo.ListSeparator) { throw new FormatException(); } data[i] = token.Value.ToComplex32(formatProvider); token = token.Next; if (token != null) { token = token.Next; } } return(new DenseVector(data)); }
public static System.Globalization.CultureInfo GetCurrentCulture(this HtmlHelper helper) { return(GlobalizationHelper.GetCurrentCulture()); }