public CultureInfo FetchCultureInfo()
{
CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
CultureInfo currentLocale = CultureInfo.GetCultureInfo(currentCulture.Name);
if (currentLocale.IsNeutralCulture)
{
currentLocale = CultureInfo.CreateSpecificCulture(currentLocale.Name);
}
// Set OrderCurrencyLocaleName and then in LocalizationDataLoader load resource into session
string orderCurrencyResource;
string orderCurrencyCode = "SEK";
if (HttpContext.Current.Session["resellerAccountData"] == null)
{
orderCurrencyResource = LocalizationHelpers.GlobalResource(String.Format("{0}Common, Currency" + currentLocale.Name, HttpContext.Current.Session["Theme"]))
?? LocalizationHelpers.GlobalResource(String.Format("{0}Common, Currency", HttpContext.Current.Session["Theme"]));
if (HttpContext.Current.Application["CurrencyCode" + currentLocale.Name] != null &&
!String.IsNullOrEmpty((string)HttpContext.Current.Application["CurrencyCode" + currentLocale.Name]))
{
orderCurrencyCode = (string)HttpContext.Current.Application["CurrencyCode" + currentLocale.Name];
}
}
else
{
orderCurrencyResource =
orderCurrencyCode =
((AccountData)HttpContext.Current.Session["resellerAccountData"]).DefaultCurrencyCode;
}
HttpContext.Current.Session["OrderCurrencyResource"] = orderCurrencyResource;
HttpContext.Current.Session["OrderCurrencyCode"] = orderCurrencyCode;
// Check if there is locale settings in cookie and set if there is
if (System.Web.HttpContext.Current.Request != null &&
System.Web.HttpContext.Current.Request.Cookies != null &&
System.Web.HttpContext.Current.Request.Cookies["AtomiaCookieCollection"] != null &&
!String.IsNullOrEmpty(System.Web.HttpContext.Current.Request.Cookies["AtomiaCookieCollection"].Value))
{
JavaScriptSerializer js = new JavaScriptSerializer();
AtomiaCookieCollection cookieCollection = js.Deserialize<AtomiaCookieCollection>(System.Web.HttpContext.Current.Request.Cookies["AtomiaCookieCollection"].Value);
AtomiaCookie localeCookie = cookieCollection.GetAtomiaCookie(
"OrderLocaleCookie",
System.Web.HttpContext.Current.Request.ApplicationPath,
System.Web.HttpContext.Current.Request.Url.Host);
if (localeCookie != null && !String.IsNullOrEmpty(localeCookie.CookieValue))
{
string cookieCountryCode = localeCookie.CookieValue;
if (currentCulture.TwoLetterISOLanguageName != cookieCountryCode)
{
CultureInfo cookieCulture = CultureInfo.GetCultureInfo(cookieCountryCode);
if (cookieCulture.IsNeutralCulture)
{
cookieCulture = CultureInfo.CreateSpecificCulture(cookieCulture.Name);
}
// CurrencyFormat
System.Web.HttpContext.Current.Session["CurrencyFormat"] = CultureHelper.CURRENCY_FORMAT;
// ShortDateFormat
System.Web.HttpContext.Current.Session["ShortDateFormat"] = cookieCulture.DateTimeFormat.ShortDatePattern;
currentLocale.DateTimeFormat.ShortDatePattern = cookieCulture.DateTimeFormat.ShortDatePattern;
currentLocale.NumberFormat.CurrencySymbol = string.Empty;
currentLocale.NumberFormat.NumberDecimalDigits = 2;
System.Web.HttpContext.Current.Session["OrderCurrencyResource"] = LocalizationHelpers.GlobalResource(String.Format("{0}Common, Currency" + cookieCountryCode, System.Web.HttpContext.Current.Session["Theme"]));
System.Web.HttpContext.Current.Session["OrderCurrencyCode"] = System.Web.HttpContext.Current.Application["CurrencyCode" + cookieCountryCode];
}
}
}
return currentLocale;
}