Getting selected culture from a drop-down in another zone

Topics: Customizing Orchard, General, Localization
Oct 17, 2011 at 10:23 PM

Pretty much what's in the title. I need to test each item of a list against a value out of a drop-down in the CulturePicker zone. My initial attempts of WorkContext.Layout.CulturePickerZone.Widgets[0].CulturePickerPart.UserCulture.Value aren't exactly working... so what's the proper way to access this data?

Oct 17, 2011 at 10:49 PM

Yes, that would be too brittle anyways. You should probably have something playing the role of intermediary there. Maybe a handler could watch the creation of the shape and put the data you need on context.Items for example?

Oct 17, 2011 at 10:59 PM

Brittle because... I might request the value before the content part has rendered? This site's layout is pretty rigid, and the CulturePicker is always at the very top. First zone, first widget.

Oct 17, 2011 at 11:21 PM

Brittle because I can think of at least half a dozen ways this could get broken, leaving the user wondering why this other, unrelated thing started to break all of a sudden.

In any case, there is such a simpler solution that I want to kick myslef for not thinking about it first. What you need here is just the current culture, so just ask the work context to give you an instance of ICultureSelector and get the culture from there. It will work with Culture Picker, or with any other implementation.

Oct 18, 2011 at 5:20 PM

I guess I really need to do this work within a proper build of Orchard in VS.. Intellisense led me to WorkContext.CurrentCulture, which seems to be giving me just what I want.. is this a "stable" solution?

Oct 18, 2011 at 6:04 PM

WorkContext.CurrentCulture is nore that stable.

Oct 18, 2011 at 6:07 PM

He means more than stable, but he's got fat fingers.

Oct 18, 2011 at 6:46 PM

Excellent. I think we've figured out just about everything we need for this site... convenient, as it's a Microsoft site...