1
0
mirror of https://github.com/chyzy/RSystem-MVC synced 2024-12-25 02:15:28 +01:00
RSystem-MVC-Fork/RSystem/Controllers/LangBaseController.cs

36 lines
1.2 KiB
C#
Raw Normal View History

2018-04-17 11:20:49 +02:00
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace RSystem.Controllers
{
public abstract class LangBaseController : Controller
{
private string CurrentLanguageCode { get; set; }
protected override void Initialize(RequestContext requestContext)
{
if (requestContext.RouteData.Values["lang"] != null && requestContext.RouteData.Values["lang"] as string != "null")
{
CurrentLanguageCode = (string)requestContext.RouteData.Values["lang"];
if (CurrentLanguageCode != null)
{
try
{
Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = new CultureInfo(CurrentLanguageCode);
}
catch (Exception)
{
throw new NotSupportedException($"Invalid language code '{CurrentLanguageCode}'.");
}
}
}
base.Initialize(requestContext);
}
}
}