How can I access the site's current culture from within a view?

Topics: General, Localization
Jul 22, 2013 at 4:26 PM
I need to be able access the current culture of a site from within a view so we can load css dynamically. Example below:
    var culture = System.Threading.Thread.CurrentThread.CurrentCulture.Name; // I assume this needs to be _cultureManager.GetSiteCulture()
    switch (culture) {
        case "de-DE":
            Style.Include("site-de.css");
            break;
        case "fr-FR":
            Style.Include("site-fr.css");
            break;
        default:
            Style.Include("site.css");
            break;
    }
I assume I need to use _cultureManager.GetSiteCulture() but not sure how to access this from within the view as _cultureManager is injected via DI.

Any tips greatly appreciated.
Developer
Jul 22, 2013 at 4:33 PM
WorkContext is your friend:
@{
    var culture = WorkContext.CurrentCulture;
}
Jul 22, 2013 at 5:15 PM
Thanks Sipke - works perfectly