LibrarySites.Banner

Fallback Series Post 3: Enforcing Language Version Presence, Out-Of-The-Box

As a developer, you may have stumbled upon the issue when first implementing language versions and thought you were doing something wrong.  You added an item in your default language, say 'en'.  Then you added another language to the site, say 'de-de'.  But you have not yet added a version of your homepage in the new language.  You then go to your homepage and decide to see what happens when the context language is the new language: www.mysite.com/?sc_lang=de-de.  And to your surprise, it loads… with blank content.

What's going on?  Well out-of-the-box, Sitecore items do not fall back and Sitecore does not consider missing language versions to mean that the item does not exist.  The item does exist, it's just the language version does not.  So it loads it up, but can't pull any field values, because the language version isn't there and therefore there are no values.

With Alex Shyba's Partial Language Fallback module, you have a choice. 

http://marketplace.sitecore.net/en/Modules/Language_Fallback.aspx

In the Sitecore.SharedSource.PartialLanguageFallback.config file, on a site- by-site basis, you can set an enforceVersionPresence site attribute and then specify the templates that should enforce version presence in the Fallback.EnforceVersionPresenceTemplates setting. 

Envision the scenario as mentioned above: Your homepage item has a version in 'en' but not yet had the 'de-de' added to it.  Assume that the homepage template guid (or one if its base template guids) is added to the EnforceVersionPresenceTemplates setting.  You are viewing the site through the context of the 'de-de' language.  Your site has enableFallback set to true, and the 'de-de' language is set to fall back to 'en'.

If you set enforceVersionPresence to true, your homepage will be treated as not existing, and will load a 404 page.  

If enforceVersionPresence is set to false, then 'en' values of the item will display, even though the 'de-de' version was not added yet to the item (fall back will work without the version presence).  Of course if you did add a 'de-de' version and overrode any of the fields, it would show a combination of 'de-de' and 'en', depending on what has been overridden.

So which is preferable?  Well that really depends on the strategy of your client and their multilingual needs.  Perhaps your client never wants to have a page not exist in the other languages, it should always just fall back unless overridden.  They will add language versions when they need to override something, but otherwise, don't want to worry about it.  In this case, enforceVersionPresence should be set to false.

But on the other side of the coin, it is quite possible your client won't want certain pages to show up in certain languages.  Perhaps there is a section all about America that is not pertinent to those who have chosen to view the site for Germany German.  The client needs a way to specify that.  Some might say to have another site node for Germany.  But what if there are 8 sections full of content on this site, and the America section is just one?  Do you really want to duplicate all of those pages across sites and not reuse the content on both sites?  And if there is that much content, cloning could become a real headache.  In this case, perhaps the client would find it easier to have the language version in the 'en' language only, not create it in the 'de-de' language, and then set enforceVersionPresence to true.  Now, whether the language version exists or not is the way the content author can dictate if the page should load in that language.

One area that requires careful consideration is Media.  A benefit of being able to specify which templates enforce version presence via the Fallback.EnforceVersionPresenceTemplates setting is that you can enforce version presence on some things and not others.  Media may be one location where you don't enforce version presence.  If an image or file is being included on a page that is valid for a language, you might not want pieces of that page missing.  You also may not want to have to add a language version for every media item, just so it could fall back (that could exponentially increase the size of your media library in the index).  Your answer could be to set enableFallback=true, enforceVersionPresence=true, Media.UploadAsVersionableByDefault = true, and then not include your media template guids in EnforceVersionPresenceTemplates.  As stated above, the media items WILL fall back as long as the languages are set to fall back, and then on one-off situations you could add a language version if you need to override the media item for a particular language. 

There is however a small problem with Alex's code if you did not want to enforce version presence and you were planning to have chained fall back (es-us -> en-us -> en).  The ideal scenario in this case is that you don't have to add a language version for each language, but his method ReadFallbackValue in the FallbackLanguageManager would stop at the first language because it checks Versions.Count.  This needs to be changed.

Once I began implementing a site with fall back and enforce language version presence, there was clearly more to consider.  I found that some customizations would be helpful and I discuss them and the update to ReadFallbackValue in my next blog post.

https://github.com/Verndale-Corp/Sitecore-Fallback-FullDemo

 

  • The article is well written and informative. The practical examples are fundamental to understanding scenarios where EnforcingVersionPresence should be set.  There is an error on the 3rd paragraph from the bottom, enforceVersionPresence = true is actually inaccurate.  That section should be:  Your answer could be to set enableFallback=true, enforceVersionPresence=false, Media.UploadAsVersionableByDefault = true