Create A Custom Context Menu Using Sitecore Powershell Extension In SXA Within 10mins

When you are using SXA 1.7.1, right click on a site node, you will be able to see a "Add Site Language" option under "Scripts" section. You can add a new language version to your whole site via a interactive UI:

This script context menu is rely on the Sitecore Powershell Extension module and installed with Sitecore SXA. It will create a new language version of all the items under your site node and use the source language version's value as default. It is very convenient if you start with only one language version and before go live, you want to add another language version for good for all.

But......what if various people are working on the same content tree and they added new items after you click the magic "Add Site Language" button? Sure, you can still click the "Add Site Language", however, it will add an extra language version even if the previous version might be the latest one (translated...). 

By looking at how the "Add Site Language" button works, I figured out that we can add our own script context menu to only add language version to one specific item and yet, still have the source language content copied over to new language version.

Here are few steps:

1. Take look at menu item at "/sitecore/system/Modules/PowerShell/Script Library/SXA/SXA - Multisite/Content Editor/Context Menu/Add Site Language". Duplicate & rename it as "Add Item Language" and change the "Show rule" to condition that identify itself a descendent node of the Site. 

2. Update the "Script body" as follow:

As you can see, we will need to create a "Show-AddItemLanguageDialog" function. Then we use the "$result" as one of the parameters in "Add-ItemLanguage" function which is a Sitecore Powershell Extension method:

This method does the magic for "Add Site Language" as well :)

3. For "Show-AddItemLanguageDialog", I use the "/sitecore/system/Modules/PowerShell/Script Library/SXA/SXA - Multisite/Functions/Site language/Show-AddSiteLanguageDialog" as a reference. The differences are just the texting.

After all these, you will be able to add a language version to one specific item under Site node~


Peng Song

I Started using Sitecore from its version 5.5. Based in China or Australia, I do enjoy moving ;) After many years working as a Web Developer, I got used to learn new skills and always willing to try something new in my spare time. Big soccer fans, maybe someday you will meet me at the pitch of Botanic Garden/Domain in the weekend~

To enable comments sign up for a Disqus account and enter your Disqus shortname in the Articulate node settings.