mirror of
https://github.com/chyzy/RSystem-MVC
synced 2024-11-22 15:20:27 +01:00
36 lines
1.2 KiB
C#
36 lines
1.2 KiB
C#
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);
|
|
}
|
|
}
|
|
} |