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 🙂