4

I would like to be able to query the current variation from within a web part or a control template so as to determine which language to use. If there is no variation then I will pick up the language from the request.

Is this possible?

Daniel Widdis
  • 8,424
  • 13
  • 41
  • 63
paul
  • 13,312
  • 23
  • 81
  • 144

1 Answers1

3

Yep - you can find the information in the Variations class.

// found here: http://weblogs.asp.net/davidmccollough/archive/2009/05/12/multilingual-sharepoint-publishing-sites.aspx
string currentUrl = SPContext.Current.Web.Url;
ReadOnlyCollection<VariationLabel> variationLabels = Variations.Current.UserAccessibleLabels;

foreach (VariationLabel vl in variationLabels)
{
   if (currentUrl.StartsWith(vl.TopWebUrl, StringComparison.CurrentCultureIgnoreCase))
   {
      variationUrl = "/" + vl.Title;

      break;
   }
}
Henrik
  • 568
  • 4
  • 10