Troubleshooting Issues with Sitecore Dictionary in Multi Lingual Solutions

Sitecore dictionary is often used to support content which is not part of your main page content or its related content, for example labels for forms, content managed validation messages , button texts etc… Sitecore Dictionary is supported out of the box through the Sitecore.Globalization namespace.

The Sitecore Dictionary does have support for a context specific (multi-site, multi-tenant or multi lingual implementations) through the use of dictionary domains.

If you would like to know more about on this topic, the sitecore community have written a lot of informational posts, see below for reference

This blog post solely focuses on a issue with sitecore dictionary while using on multi-site and multi-lingual solutions on sitecore 8.1 Update 3

Issue

There were a variety of sporadic issues with sitecore dictionary especially when language fallback is turned on in my implementation, I have listed some of them below

  • Dictionary items showing Key value instead of Phrase text
  • Dictionary cache not getting updated in remote instances such as CD servers
  • Dictionary entry shows incorrect value by Translate.Text(“Keyword”) with Fallback language item turned on/a>

Solution

The issue was finally narrowed down to the dictionary cache not getting updated, now I could have easily used the “Translate.ResetCache” method on publish end event, but that would be an overkill because I have about 30K dictionary items in my implementation

I finally decided to update my dictionary cache on publish end and publish end remote events and voila that fixed all of my dictionary issues

Implementation Fix : Patch

[code lang=”xml”]
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:set="http://www.sitecore.net/xmlconfig/set/">
<sitecore>
<events>
<event name="publish:end">
<handler type="HI.Dictionary.DictionaryCacheUpdater, HI.Dictionary" method="UpdateDictionaryCache"/>
</event>

<event name="publish:end:remote">
<handler type="HI.Dictionary.DictionaryCacheUpdater, HI.Dictionary" method="UpdateDictionaryCache"/>
</event>
</events>
</sitecore>
</configuration>
[/code]

Implementation Fix : Method

[code lang=”csharp”]
namespace HI.Dictionary
{
public class DictionaryCacheUpdater : ItemEventHandler
{
public DictionaryCacheUpdater()
{
}

public void UpdateDictionaryCache(object sender, EventArgs args)
{
foreach (string publishingTarget in (args as PublishEndRemoteEventArgs).get_PublishingTargets())
{
Item item = Context.get_Database().GetItem(ID.Parse(publishingTarget));
if (item.get_TemplateID() != TemplateIDs.DictionaryEntry)
{
continue;
}
base.UpdateCacheEntries(item.get_Item(FieldIDs.DictionaryKey), item.get_Item(FieldIDs.DictionaryKey), item);
}
Log.Info("Updated Dictionary Cache.", this);
}
}
}
[/code]

There were couple of other references which helped me in my research, they may be a good read

please let me know if you have any questions on the implementation