Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mila Pandurska 43 posts 190 karma points
    May 03, 2018 @ 05:00
    Mila Pandurska
    1

    Get Culture from IContent in ContentService_Published method

    Hi, I have a multilingual website and I use ContentService_Published method to do some custom logic when I publish a node - I need to do

    ExamineManager.Instance.IndexProviderCollection["IndexPrivider"].ReIndexNode(child.ToXml(applicationContext.Services.PackagingService), "content");
    

    I have different searchIndexes for the different languages so I need to know which index to ReIndex. The code that I have so far is:

     public void ContentService_Published(IPublishingStrategy sender, PublishEventArgs<IContent> e)
        {
            var culture = System.Threading.Thread.CurrentThread.CurrentUICulture.Name;
            foreach (var content in e.PublishedEntities)
            {
                if (content.ContentType.Alias == "node")
                {                 
                    foreach (var child in content.Descendants().Where(c => c.ContentType.Alias == "subNode"))
                    {
                        ExamineManager.Instance.IndexProviderCollection[GetIndexer(culture)].ReIndexNode(child.ToXml(applicationContext.Services.PackagingService), "content");
    
    
                    }
    }
    

    The method GetIndexer() check the culture and returns the respective value. The problem is that var culture = System.Threading.Thread.CurrentThread.CurrentUICulture.Name; is always "en-US" which is (I guess) the culture of the logged in in Umbraco user. Is there a way to get the culture of the item that I am publishing?

    Mila

  • kows 81 posts 151 karma points c-trib
    May 07, 2018 @ 13:39
    kows
    0

    You could get the node from cache & get the culture from there.

    var node = UmbracoContext.Current.ContentCache.GetById(content.Id);
    var culture = node.GetCulture();
    
  • Sotiris Filippidis 286 posts 1501 karma points
    Jun 15, 2019 @ 23:12
    Sotiris Filippidis
    1

    Isn't there any way to get the culture from the IContent object instead? I mean, when publishing you can only publish one culture so shouldn't the IContent object contain this information? (Asking because I haven't managed to find it yet :) )

  • Rihab 104 posts 388 karma points
    Jul 31, 2019 @ 11:36
    Rihab
    0

    Hi, Searching for the same thing..... any luck? thanks. Rihab.

  • Rosen Petrov 8 posts 28 karma points
    Apr 22, 2021 @ 11:34
    Rosen Petrov
    0

    Searching for the same thing.. :D Anybody?

  • Steve Morgan 1349 posts 4458 karma points c-trib
    Aug 01, 2024 @ 07:52
    Steve Morgan
    0

    An old thread but the answer is that culture info can be found in IContent under

    .PublishCultureInfos

Please Sign in or register to post replies

Write your reply to:

Draft