/// <summary> /// Returns default culture name which is the first name decalared (e.g. en-US) /// </summary> /// <returns></returns> public static string GetDefaultCulture() { CacheProviderUtility cacheProvider = new CacheProviderUtility(); string cacheValue = cacheProvider.Get<string>("DefaultCulture"); if (cacheValue == null) { cacheValue = string.Empty; BOCultureCollection cultures = BOCulture.All; foreach (BOCulture culture in cultures) { if (culture.Default) { cacheValue = culture.Name; cacheProvider.Add("DefaultCulture", cacheValue, Times.TwentyFourHoursInMinutes); break; } } } return cacheValue; // return Default culture }
public static string GetResourceValueFromDb(containerType containerType, string container, string property, string type, string key, string defaultValue) { string localizedValue = string.Empty; string culture = string.Empty; if (HttpContext.Current.Session["culture"] == null) { culture = BOCulture.GetDefault().Name; HttpContext.Current.Session["culture"] = culture; } else { culture = HttpContext.Current.Session["culture"].ToString(); } string hash = BOLocalizationResource.Md5Hash(culture, containerType.ToString(), container, property, type, key); //Prevent caching for test CacheProviderUtility cacheProvider = new CacheProviderUtility(); string cacheValue = cacheProvider.Get<string>(hash); if (cacheValue == null) { // Add logic to retrieve key from DB BOLocalizationResource localizationResource = BOLocalizationResource.Get(culture, containerType.ToString(), container, property, type, key, defaultValue); localizedValue = localizationResource.Value; if (localizedValue != defaultValue && !localizationResource.Modified) { localizationResource.Modified = true; localizationResource.Save(); } // cacheProvider.Add(hash, localizedValue, Times.TwentyFourHoursInMinutes); } else { localizedValue = cacheValue; } return localizedValue; }