I am new to ASP.NET and I want to design a multilingual Website.
I want to let users select their language from a menu bar on top of the home page and let them also see it on address bar of web browser.
to do so I added below codes to \[code\]RouteConfig\[/code\] Class :\[code\]routes.MapRoute( name; "Default", url: "{lang}/{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional } )\[/code\]First of all I can't Set \[code\]CultureInfo\[/code\] in \[code\]CurrentThread\[/code\]. I created \[code\]CultureController\[/code\] and In there I set the Language based on user's choice. It won't change in other Views and Controllers. (I have heard every user get one thread when they enter website )\[code\] public ActionResult ChangeLanguage ( string lang, String returnUrl = null ) { if ( !new[] { "en", "fr", "ar" }.Contains( lang ) ) throw new ArgumentException( "Language not supported." ); Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo( lang ); if ( returnUrl == null ) return RedirectToAction( "Index", "Home" ); return Redirect( returnUrl ); }\[/code\]Second Problem: now I should pass lang in my links too and I don't want to. for example:\[code\]@Html.ActionLink("About", "About", "Home")\[/code\]doesn't work anymore. I want the lang param get filled based on \[code\]CultureInfo\[/code\] stored in \[code\]CurrentThread\[/code\] or Session. ( I currently use Session ). ( Is It even possible??!! )
I appreciate any help.
I want to let users select their language from a menu bar on top of the home page and let them also see it on address bar of web browser.
to do so I added below codes to \[code\]RouteConfig\[/code\] Class :\[code\]routes.MapRoute( name; "Default", url: "{lang}/{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional } )\[/code\]First of all I can't Set \[code\]CultureInfo\[/code\] in \[code\]CurrentThread\[/code\]. I created \[code\]CultureController\[/code\] and In there I set the Language based on user's choice. It won't change in other Views and Controllers. (I have heard every user get one thread when they enter website )\[code\] public ActionResult ChangeLanguage ( string lang, String returnUrl = null ) { if ( !new[] { "en", "fr", "ar" }.Contains( lang ) ) throw new ArgumentException( "Language not supported." ); Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo( lang ); if ( returnUrl == null ) return RedirectToAction( "Index", "Home" ); return Redirect( returnUrl ); }\[/code\]Second Problem: now I should pass lang in my links too and I don't want to. for example:\[code\]@Html.ActionLink("About", "About", "Home")\[/code\]doesn't work anymore. I want the lang param get filled based on \[code\]CultureInfo\[/code\] stored in \[code\]CurrentThread\[/code\] or Session. ( I currently use Session ). ( Is It even possible??!! )
I appreciate any help.