1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / News categories and localization

News categories and localization

2 posts, 0 answered
  1. Devin
    Devin avatar
    149 posts
    Registered:
    09 Jun 2009
    08 Oct 2009
    Link to this post
    Hi I'm building an alert email based on this post http://www.sitefinity.com/support/forums/sitefinity-3-x/general-discussions/send-alert-email.aspx.  The site has content in English and French and I've set it up based on this webinar http://www.sitefinity.com/support/webinars/multi-language-localization-support-in-sitefinity.aspx.  The alert email is to be sent when an admin creates or updates a news item.  I've created two categories, English News and French News.  Here is my code so far:

        void ContentManager_Executed(object sender, Telerik.ExecutedEventArgs e)  
        {  
            Telerik.News.NewsManager manager = new Telerik.News.NewsManager("News");  
             
            if (e.CommandName == "CreateContent" || e.CommandName == "UpdateContent" && manager.Content.Provider.Name == "News")  
            {                          
                Telerik.Notifications.Newsletters.DataManager dManager = new Telerik.Notifications.Newsletters.DataManager();  
                int count = manager.Content.ContentCount(); 
                IList allcontent = manager.Content.GetContent(count - 1, count - 1);             
     
                if (allcontent.Count <= 0) 
                { 
                    return;  
                } 
                 
                Telerik.Cms.Engine.IContent content =  (Telerik.Cms.Engine.IContent)allcontent[0]; 
                System.Collections.Generic.List<Telerik.Cms.Engine.IMetaSearchInfo> filter = new System.Collections.Generic.List<Telerik.Cms.Engine.IMetaSearchInfo>(); 
                filter.Add(new Telerik.Cms.Engine.MetaSearchInfo(Telerik.Cms.Engine.MetaValueTypes.ShortText, "Category""English News", Telerik.Cms.Engine.SearchCondition.Equal, Telerik.Cms.Engine.JoinType.And)); 
                IList englishContent = manager.Content.GetContent(count - 1, count - 1, filter.ToArray()); 
                
                if (englishContent.Count > 0 && ((Telerik.Cms.Engine.IContent)englishContent[0]).Content.ToString() == content.Content.ToString()) 
                { 
                    // english content 
                    Telerik.Newsletters.IGroup englishGroup = GetGroup("EnglishGroup"); 
                    IList englishSubscribers = dManager.GetSubscribersOfGroup(englishGroup.GroupId, "");                 
                     
                    if (englishSubscribers.Count > 0) 
                    { 
                        foreach (Telerik.Notifications.Data.GroupSubscriber sub in englishSubscribers) 
                        { 
                            System.Web.Mail.SmtpMail.Send("example@example.com", sub.Subscriber.Email, "news update", content.Content.ToString()); 
                        } 
                        return
                    } 
                } 
     
                filter = new System.Collections.Generic.List<Telerik.Cms.Engine.IMetaSearchInfo>(); 
                filter.Add(new Telerik.Cms.Engine.MetaSearchInfo(Telerik.Cms.Engine.MetaValueTypes.ShortText, "Category""French News", Telerik.Cms.Engine.SearchCondition.Equal, Telerik.Cms.Engine.JoinType.And)); 
                IList frenchContent = manager.Content.GetContent(count - 1, count - 1, filter.ToArray()); 
     
                if (frenchContent.Count > 0 && ((Telerik.Cms.Engine.IContent)frenchContent[0]).Content.ToString() == content.Content.ToString()) 
                {                 
                    // french content 
                    Telerik.Newsletters.IGroup frenchGroup = GetGroup("FrenchGroup");                 
                    IList frenchSubscribers = dManager.GetSubscribersOfGroup(frenchGroup.GroupId, ""); 
     
                    if (frenchSubscribers.Count > 0) 
                    { 
                        foreach (Telerik.Notifications.Data.GroupSubscriber sub in frenchSubscribers) 
                        { 
                            System.Web.Mail.SmtpMail.Send("example@example.com", sub.Subscriber.Email, "news update", content.Content.ToString()); 
                        } 
                        return
                    } 
                } 
            }  
        } 
     
        Telerik.Newsletters.IGroup GetGroup(string strGroup)         
        { 
            Telerik.Notifications.Newsletters.DataManager dManager = new Telerik.Notifications.Newsletters.DataManager();  
            Telerik.Newsletters.IGroup subscriberGroup = null ;  
            IList allGroups = dManager.GetGroups(""); 
            int i = 0; 
            while (subscriberGroup == null && i < allGroups.Count) 
            {             
                if (((Telerik.Newsletters.IGroup)allGroups[i]).GroupName == strGroup) 
                { 
                    subscriberGroup = (Telerik.Newsletters.IGroup)allGroups[i]; 
                } 
                i++;  
            } 
            return subscriberGroup; 
        } 
     

    Is there a way to grab content based on a category and localization?
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    Registered:
    01 Feb 2016
    08 Oct 2009
    Link to this post
    Hi Devin,

    Thank you for using our services.

    Basically each content item has a property Language. If you have localization enabled for your News Module, you can do a similar thing to what you are trying, but with checking the Language property of the item. If it is French send to French subscribers, if English send to English subscribers. Here is sample code how to check content items language. Please note that if content is created in default language for a site, the language property will be "":
    void ContentManager_Executed(object sender, Telerik.ExecutedEventArgs e) 
        { 
            Telerik.News.NewsManager manager = new Telerik.News.NewsManager("News"); 
     
            if (e.CommandName == "CreateContent" || e.CommandName == "UpdateContent" && manager.Content.Provider.Name == "News"
            { 
                Guid id = e.ItemID; 
                Telerik.Cms.Engine.IContent content = manager.Content.GetContent(id); 
                string language = content.Language; 
                //on my site English is default, so English content will have Language="" 
                if (language == ""
                { 
                    //do something  
                } 
                else if (language == "fr"
                {  
                    //do something 
                } 
            }     
        } 


    All the best,
    Radoslav Georgiev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
2 posts, 0 answered