0

I am creating an item as well as its version in specific language (let's say Arabic) and then creating a clone of the newly created item in that particular language (Arabic). The issue is that the item as well as it's clone both are getting created in "en" as well as in "ar" language. However, I don't want the "en" version. Not sure why the English version is being added.

I also have tried to remove the unwanted version but this is not feasible for us because of performance issue as we are going to have lot many items.

Below is code snippet for example.

Sitecore.Globalization.Language language = LanguageManager.GetLanguage("ar"); //arabic language
using (new LanguageSwitcher(language))
{
    var  videoItem = ItemManager.AddFromTemplate("SampleName", "<<template ID>>", "<<parent item>>", "<<GUID>>");
    videoItem = videoItem.Database.GetItem(videoItem.ID, language);
    if (videoItem.Versions.Count < 1)
    {
        videoItem = videoItem.Versions.AddVersion();
    }
    videoItem.CloneTo("<<sitecore item where the item to be cloned>>");
}
1

ItemManager.AddFromTemplate method creates an item with 1 version already. And from what I remember, it creates the child item in the language of the destination parameter (3rd one), where you pass parent item.

It means that if you pass en version of the parent to the AddFromTemplate method, it will create en version of the item.

Try to get ar version of the parent item first and pass that item to AddFromTemplate method:

var arParent = parent.Database.GetItem(parent.ID, arLanguage);
var videoItem = ItemManager.AddFromTemplate("SampleName", "<<template ID>>", arParent , "<<GUID>>");
  • Thanks @Marek, now parent item is creating in arabic only. However, it's still creating clone in all languages. – ehsan Jun 25 at 9:12
  • The item which is passed in videoItem.CloneTo("<<sitecore item where the item to be cloned>>"); method should also be in arLanguage. – Marek Musielak Jun 25 at 9:21
  • Thanks @Marek. It's working fine for cloning the item in one language. However, when I am creating clone of the same videoItem(under other parent) in second language. i.e. "fr" . Then again its creating "en" version of the same cloned item. So, after this step - the cloned item is in three language version ("ar", "fr", "en") – ehsan Jun 27 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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