9

We have a site that loads a fair deal of data via web api from inside our own project and have stumbled upon some odd behavior regarding dictionaries. It seems that it more or less randomly succeeds in getting the phrase from the dictionary.

One example is a product listing page that fetches "in stock" and "out of stock" dictionaries along with other product information. Loading the page for the first time one product would get the "in stock" key instead of the phrase while the rest gets the correct phrase for the same key, reloading the page and a completely random product gets the key and not the phrase while the rest works.

This is the method we are using: Sitecore.Globalization.Translate.Text("KEY");

We have tried getting the dictionaries from both static and non-static classes.

The SC version we are using is 8.1 (rev. 160302)

Any tips would be greatly appreciated. This occurs in multiple dev environment as well as on a test server.

Thanks

1
  • 1
    Try confirming the key is not duplicated. You can try by opening \website\temp\dictionary.dat in a decent text editor and searching for that key
    – josedbaez
    Oct 24, 2016 at 14:12

3 Answers 3

7

I have this issue on Sitecore 8.1 Initial Release.

To fix it you need to add on publish:end and publish:end:remote event a new handler. This is the class:

 public class DictionaryCacheClearer
 {
   /// <summary>
   /// Clears the whole dictionary domain cache.
  /// </summary>
  /// <param name="sender">The sender.</param>
  /// <param name="args">The <see cref="EventArgs"/> instance containing the event data.</param>
   public void ClearCache(object sender, EventArgs args)
   {
     Translate.ResetCache();
     Log.Info("Dictionary cleared", this);
    }
   } 

On publish:end and publish:end:remote events you will have:

 <event name="publish:end:remote">
     <handler type="Sitecore.Publishing.HtmlCacheClearer, Sitecore.Kernel" method="ClearCache">
       <sites hint="list">
       <site s="1">YourSite</site>
       </sites>
    </handler>
<handler type="YourNameSpace.DictionaryCacheClearer, YourAssembly" method="ClearCache" />
</event>

<event name="publish:end">
   <handler type="Sitecore.Publishing.HtmlCacheClearer, Sitecore.Kernel" method="ClearCache">
     <sites hint="list">
        <site s="1">YourSite</site>
     </sites>
    </handler>
    <handler type="YourNameSpace.DictionaryCacheClearer, YourAssembly" method="ClearCache" />
</event>

Other fix you find it here: https://community.sitecore.net/developers/f/8/t/173

2
  • 1
    We had same issue on Sitecore 7.2 and we have fixed it with same technique Feb 15, 2018 at 19:27
  • If you want to do this in SPE you can do it like this: [Sitecore.Globalization.Translate]::ResetCache($true); May 23, 2019 at 9:56
0

Even I had the same problem very recently. I removed the dictionary.dat in Website/temp/ and republished the dictionary value again. This solved my issue. Thanks to https://cmsxperience.com/2016/10/19/refresh-sitecore-dictionary-entries/

0

This is one of the flaws using OOTB Dictionary functionality in Sitecore. There are a lot other flaws like permissions for this node under /sitecore/system need to be set for content editors and so on.

I would recommend looking into Sitecore Habitat project and inspire by its Dictionary Foundation module:

https://github.com/Sitecore/Habitat/tree/master/src/Foundation/Dictionary

If you are using SXA in your solution or planning to use, I would recommend looking into Sitecore Habitat.Home project and inspire by its Dictionary Foundation module:

https://github.com/Sitecore/Sitecore.HabitatHome.Platform/tree/master/src/Foundation/Dictionary

Then you would have Dictionary entries under /sitecore/content node like this:

enter image description here

and code how you use it could look like this:

enter image description here

1
  • 1
    You can use Dictionary Domains which allows you to specify a per-site dictionary folder (anywhere, outside of /sitecore/system) as well as specify dictionary fallback.
    – jammykam
    Nov 26, 2018 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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