Last active
September 18, 2016 10:08
-
-
Save nordinrahman/b0f017711ba2f57cac789c501b078df2 to your computer and use it in GitHub Desktop.
Global.asax code to set current thread's CultureInfo with CustomCultureUI instance
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public override void Init() | |
| { | |
| base.Init(); | |
| BeginRequest -= OnBeginRequest; | |
| BeginRequest += OnBeginRequest; | |
| } | |
| private void OnBeginRequest(object sender, EventArgs eventArgs) | |
| { | |
| var locale = Request.QueryString["locale"]; | |
| if (!string.IsNullOrEmpty(locale)) | |
| { | |
| CultureInfo localeCulture = null; | |
| try | |
| { | |
| localeCulture = new CultureInfo(locale); | |
| } | |
| catch (CultureNotFoundException) | |
| { | |
| var m = Regex.Match(locale, @"^\w+-(\w+)"); | |
| var countryCode = m.Groups[1].Value; | |
| if (!string.IsNullOrEmpty(countryCode)) | |
| { | |
| localeCulture = new CustomCultureInfo(locale); | |
| } | |
| } | |
| if (localeCulture != null) | |
| { | |
| Thread.CurrentThread.CurrentCulture = localeCulture; | |
| Thread.CurrentThread.CurrentUICulture = localeCulture; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment