CurrentUICulture and CurrentCulture in Litium

CurrentUICulture and CurrentCulture in Litium

You see a lot of CultureInfo.CurrentUICulture and CultureInfo.CurrentCulture references in the Accelerator. Those are connected to two channel fields called Language for pages and block and Language for products. Lets have a look at when to use which!

Language for pages and blocks and language for products on a channel

Language for pages and blocks and language for products on a channel

Usage

Language for pages and block sets the value for CultureInfo.CurrentUICulture. Language for products sets the value for CultureInfo.CurrentCulture. This means you can do like this when getting a value for a field that is multiculture for proucts:

var baseProductFieldValue = baseProduct.Fields.GetValue<string>("FieldId", CultureInfo.CurrentCulture);

And for blocks and pages you instead get field values like this:

var pageFieldValue = page.Fields.GetValue<string>("FieldId", CultureInfo.CurrentUICulture);

Conclusion

In the Litium projects I’ve worked these fields mentioned above are almost always pointing to the same language. So it often times won’t make much difference. However, if you only use CultureInfo.CurrentCulture when working with products and CultureInfo.CurrentUICulture when working with pages and blocks you’ll be future proof if an editor decides to change those fields.