Is there a way in Sitecore Powershell Extensions to create new language versions of a branch in the content tree? I need it to copy exactly the presentation details set on the current language to the new language.

I've found this article https://www.cognifide.com/our-blogs/sitecore/quickly-create-new-language-versions-on-your-sitecore-cms/ so would like to do the same but with SPE.


There is already one blog post on this topic on Internet

Code snippet from the blog as below:

Add-ItemLanguage -Path "master:\sitecore\content" -Language "en" -TargetLanguage "de-DE" -IfExist OverwriteLatest  -IgnoredFields ""

For recursive you can try below PowerShell script

Get-ChildItem /sitecore/content/home -Recurse |
  Where-Object { $_."TemplateName" = "Sample Item" } |
  ForEach-Object { Add-ItemLanguage $_ -Language "en" -TargetLanguage "de-DE" -IfExist OverwriteLatest  -IgnoredFields "" }
| improve this answer | |

Another attempt with creation of new language versions of both items in the branch as well as items referenced through datasources:

#Delete the following line to perform the operation
# otherwise it only shows what it will do and not perform any changes
$WhatIfPreference = $true

function Add-TranslationForItemAndDataSources {

    # change the -IfExists From "Skip" to "Append" 
    # if you want to create a new version even if it exists
    Add-ItemLanguage -Item $item -Language $Language -TargetLanguage $TargetLanguage -IfExist Skip

    Get-Rendering -Item $item -FinalLayout -Device (Get-LayoutDevice -Default) | 
        Where-Object { -not [string]::IsNullOrEmpty($_.Datasource)} | 
        ForEach-Object { Get-Item "$($item.Database):" -ID $_.Datasource }
        Add-ItemLanguage -Item $item -Language $Language -TargetLanguage $TargetLanguage -IfExist Skip

Get-ChildItem master:\content -Recurse |
  Where-Object { $_.TemplateName -eq "Sample Item" } |
  ForEach-Object { Add-TranslationForItemAndDataSources -Item $_ -Language "en" -TargetLanguage "de-DE" }
| improve this answer | |

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.