0

When I publish the Home item, the selected language is English. But in code, the Root Item is coming as da (Danish).

enter image description here

On publish, for languages, I selected both Danish & English. So, is it taking the first language in that list?

enter image description here

How can I get the language that was selected, when the item was being published, i.e English in this case.

patch.config:

<pipelines>
  <publish>
    <processor type="MyCode.Handlers.AuditPublish, MyCode"/>
  </publish>
</pipelines>

AuditPublish.cs

public class AuditPublish:PublishProcessor
    {
        public override void Process(PublishContext context)
        {
            var rootItem = context.PublishOptions.RootItem;
        }
    }

2 Answers 2

1

You cannot. The publish job operation is independent from the context language/language selection the user has going on in the Content Editor.

2
  • So, I see da in the RootItem. Is it because is it the first language in the list of the publish languages.
    – sukesh
    Commented Jul 11, 2023 at 7:57
  • Probably, yes. I don't think anyone has ever paid particular attention to the order these languages go out in since it won't really make any difference once the process is completed.
    – Mark Cassidy
    Commented Jul 11, 2023 at 15:04
0

If you want to get languages which are selected in Publish window, e.g. get Croatian, Dutch and French in this scenario:

enter image description here

you can check context.PublishOptions.Language. Be aware, that if you publish in multiple languages, Sitecore will create multiple publish options and will process them one by one (it may be different if you use Publish Service).

If you need to get the root item which is being published in one of those languages, you can call

var languageVersion = context.PublishOptions.RootItem.Database.GetItem(context.PublishOptions.RootItem.ID, context.PublishOptions.Language);
2
  • Sorry, I'm not trying to get the selected languages. The RootItem is coming as Home da but I selected English as shown in first snap. So, is there way to get Home en
    – sukesh
    Commented Jul 11, 2023 at 8:08
  • 1
    You can try calling Language.Current but the output of this one may be different depending on where the publish call is being executed
    – Marek Musielak
    Commented Jul 11, 2023 at 9:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.