Skip to content

Instantly share code, notes, and snippets.

@ashour
Last active April 24, 2020 14:25
Show Gist options
  • Save ashour/8c564911b828da994c8181279a7b8801 to your computer and use it in GitHub Desktop.
Save ashour/8c564911b828da994c8181279a7b8801 to your computer and use it in GitHub Desktop.
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