Sitecore Single Language Publish in multilingual Sitecore Environment

784 views Asked by At

Is there any way to publish items in sitecore for some specific language that we get from API associated with the item?

Language[] languages = new Language[] { LanguageManager.GetLanguage("en") };
....
...
Sitecore.Publishing.PublishManager.PublishSmart(master, targetDbs, languages);

I have three language in Sitecore Env Here but I want one item to publish for just "en" language and other for just "en-ca" and other for just "fr-ca".

1

There are 1 answers

5
Hishaam Namooya On

You need to make use of the PublishItem method and proceed as follows:

  1. Get the items that needs to be published.
  2. Get the language versions of each item to know in which language the items need to be published.

Sample Code

//Get your Item list here
var itemList = GetItemList();

//Loop in the Item list to get the languages
//Publish the item based on the languages
foreach (var item in itemList)
{
    var languageVersions = item.Languages;

    Sitecore.Publishing.PublishManager.PublishItem(item, targetDb, languageVersions, true, false);
}

Thanks