Search code examples
sharepointweb-partscontroltemplatemoss

How to get current language or variation in Sharepoint (MOSS) 2007?


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?


Solution

  • 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;
       }
    }