using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using System.Threading;
using System.Globalization;
public static partial class Config
{
public partial class CultureManager
{
protected HttpSessionState session;
public CultureManager(HttpSessionState httpSessionState)
{
session = httpSessionState;
}
public static int CurrentCulture
{
/*en-US th-TH */
get
{
if (Thread.CurrentThread.CurrentUICulture.Name == "en-US") return 0; /*english*/
else if (Thread.CurrentThread.CurrentUICulture.Name == "th-TH") return 1; /*thai*/
else return 0;
}
set
{
//
// Set the thread's CurrentUICulture.
//
if (value == 0)
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
else if (value == 1)
Thread.CurrentThread.CurrentUICulture = new CultureInfo("th-TH");
else
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
//
// Set the thread's CurrentCulture the same as CurrentUICulture.
//
Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture;
}
}
}
}
2. create basecontroller
Code (C#)
public abstract class BaseController : Controller
{
#region OnActionExecuting
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
}
#endregion
/// <summary>
/// Manage the internationalization before to invokes the action in the current controller context.
/// </summary>
protected override void ExecuteCore()
{
int culture = 0;
if (this.Session == null || this.Session["CurrentCulture"] == null)
{
int.TryParse(System.Configuration.ConfigurationManager.AppSettings["Culture"], out culture);
this.Session["CurrentCulture"] = culture;
}
else
{
culture = (int)this.Session["CurrentCulture"];
}
//
Common.Helpers.Config.CultureManager.CurrentCulture = culture;
//
// Invokes the action in the current controller context.
//
base.ExecuteCore();
}
protected override bool DisableAsyncSupport
{
get { return true; }
}
#region "JsonResult"
protected override JsonResult Json(object data, string contentType,
Encoding contentEncoding, JsonRequestBehavior behavior)
{
return new Api.JsonNetResult
{
Data = data,
ContentType = contentType,
ContentEncoding = contentEncoding,
JsonRequestBehavior = behavior
};
}
#endregion
}