Let's Share

My personal place to share knowledge about Sitecore, Powershell, Amazon Web Services and .NET

Let's build dictionary toolbox for Sitecore

posted by Robert Senktas   | 08-04-2017


dictionary toolbox

Historical background

Long time ago in the stone age era, I mean a version 6.5 there was just a single dictionary under system node. It was a solution only for braveheart developers. Till this time Sitecore introduce a lot of improvements in dictionary area.
The first big improvement was a Dictionary Domains In a few simple words dictionary domains allow you to have a separated dictionary for each web site.
For the next big improvement we have to wait to version 8.1 release.In version 8.1 Sitecore introduce a fallback language functionality.. Fallback langugage functionality is not only dedicated for dictionaries but for all Sitecore items.


Dictionary Toolbox

dictionary toolbox Now is time for the Dictionary Toolbox age.The Dictionary Toolbox is an answer for customer needs. With this tool customers can easy move translated items to the other environement or export items for a translation. For development I will use very sharp tool - Sitecore Powershell Extension. The main Dictionary Toolbox functionalities will be:

  • Export dictionary items from any dictionary domain to csv file
  • Import doctionary items from csv file
  • Display all items with empty phrase, or without language version, Clear dictionary cache, this can be usefull during development, when master database is used

Screen showns simple interface. User can choose dictionary domain item and next language to export dictionary items. SPE team did a good job and I was able to achieved this effect in a very simple way. For display items based on the dictionary domain template I used tree list control. To show all languages Droplist is used. The another good thing is that this controls shown only items accessible for the logged user.



Here is powershell scrip to generate UI and fill controls with the necessary data. You just have to add code for parameters checking and exit if user do not chooose dictionary and language.

$dialog = Read-Variable -Parameters `
    @{ Name = "dictionaryDomain"; Title = "dictionary"; Source="DataSource=/sitecore/content&DatabaseName=master&IncludeTemplatesForDisplay=Dictionary domain" ; Editor="treelist"}, `
    @{ Name = "language"; Title = "Language"; Source="DataSource=/sitecore/system/languages" ; Editor="droplist"}, `
    @{ Name = "emptyOption"; Value=$true; Title = "Export empty items" ; Editor="bool"} `
    -Description "This script will export Dictionary data into file." `
    -Width 400 -Height 200 `
    -Title "Dictionary Toolbox" `
    -OkButtonName "Export" `
    -CancelButtonName "Cancel"

When a user makes a choice powershell need to get all dictionary items in proper language.

$dictionaryEntries = Get-ChildItem -Recurse -ID $dictionaryDomain.ID  -Language $language.Name
 | Where-Object { $_.TemplateName -eq "Dictionary entry" } 
  | ForEach-Object { return AddPathMember($_) }

Next all dictionary items will be exported to CSV file. Not all properties will be exported only item ID, item name, key, phrase and item path.

$csv = $dictionaryEntries | Select-Object -Property Name,Key,Phrase,ID, Path | ConvertTo-Csv -NoTypeInformation |  Out-String
    
$fileName = CreateFileName($language)

Out-Download -Name $fileName -InputObject $csv | Out-Null

A full script is available on Git

Sitecore Powershell Dictionary Toolbox

This is a personal blog. All opinions here are my own opinions and do not represent my employer’s view in anyway.

Sitecore Automation Module