DictionaryDomain null (in backend) in your SXA JSS site


Hello dear sitecorians, I hope you are well and enjoying the wonderful world of Sitecore πŸ™‚
Sitecore recently secured a stunning US$1.2B investment. This is great news, does this mean Sitecore will finally move to .Net 5(or 6)? Let’s hope so πŸ˜‰

Today’s post will be about the lovely and successful combination of SXA and JSS. If you are doing JSS development, I strongly recommend you switch to SXA JSS.

One of the great things when using SXA together with JSS, is that the site config is no more. Instead, it’s all in Sitecore. No more annoying site config that needs to be patched and all that…

However, I recently noticed something strange when working with dictionaries(translated phrases). The dictionary works great on the frontend side, the url

  
https://yoursite.com/sitecore/api/jss/dictionary/yoursite/yourLanguage?sc_apikey=theAppKey

returns the proper JSON(containing all the translated dictionary phrases).

But on the backend side(working with a custom layout resolver), when trying to do a “standard translation”:

  
Sitecore.Globalization.Translate.Text("phraseKey") 

I could not get the translation to work, it just returned the phrase key. I tried them all…

  
Sitecore.Globalization.Translate.TextByDomain()
Sitecore.Globalization.Translate.TextByLanguage()  

They all returned the phrase key.

It got me thinking, is the DictionaryDomain null? So I fired up the debugger and had a look at the Sitecore.Context.Site object:

And guess what, the DictionaryDomain is null. This was a very confusing moment, the dictionary phrases work great on the frontend side but not on the backend side πŸ€”

So what to do? Well if it was a classic sitecore website, I would probably have a look at the site config. To check that the dictionaryDomain is set:

  
<site name="basic-company"
            inherits="website"
            dictionaryDomain="{B741B17B-67B2-4DD8-A216-D092813871F0}"
            hostName="cd.basic-company-aspnetcore.localhost"
            rootPath="/sitecore/content/Basic Company"
            patch:before="site[@name='website']" /> 

So how do we do this on an “SXA JSS” site? Well, it was quite easy πŸ™‚ If you locate the site settings node (the one that replaces the site config). Now, scroll down to the “Other Properties” fields:

Here we can add the “missing” dictionaryDomain field and the “Guid” value from the Dictionary in the tenant site.

And now the translation works on the backend side!

That’s all for now folks πŸ™‚


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.