Last active
April 24, 2020 14:25
-
-
Save ashour/8c564911b828da994c8181279a7b8801 to your computer and use it in GitHub Desktop.
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
using System.Globalization; | |
using System.Threading; | |
using System.Web.Mvc; | |
namespace Heaventure.Controllers | |
{ | |
public class BaseController : Controller | |
{ | |
protected override void OnActionExecuting( | |
ActionExecutingContext filterContext) | |
{ | |
// Grab the culture route parameter | |
string culture = filterContext.RouteData.Values["culture"]?.ToString() | |
?? "en"; | |
// Set the action parameter just in case we didn't get one | |
// from the route. | |
filterContext.ActionParameters["culture"] = culture; | |
var cultureInfo = CultureInfo.GetCultureInfo(culture); | |
Thread.CurrentThread.CurrentCulture = cultureInfo; | |
Thread.CurrentThread.CurrentUICulture = cultureInfo; | |
// Because we've overwritten the ActionParameters, we | |
// make sure we provide the override to the | |
// base implementation. | |
base.OnActionExecuting(filterContext); | |
} | |
public ActionResult RedirectToLocalized() | |
{ | |
return RedirectPermanent("/en"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment