Wednesday, 31 May 2017

Language fallback in Sitecore

Language fallback
In a Multilanguage solution, you can use the language fallback functionality to control which items or fields that you want to reuse content from another language, and which items and fields that you want to translate.
You specify a fallback language for the languages in your Sitecore solution and enable language fallback on the relevant items or fields. If a version does not exist in a given language, language fallback activates, and the item or field value is displayed in the fallback language instead.
You can also set up a chain of language fallback. For example, you can specify the language en-NZ to fall back to en-AU and en-AU to fall back to en. If the version in en-AU does not exist for a particular item or field, then the version in en-NZ falls back to the version in en.



Item-level language fallback

Item-level fallback enables you to set up an 'empty' item version in a given language so that it falls back to another language version, including all its fields. In this way, you can launch a new language version of your entire website without creating any items in the new language in the Content database.

Field-level language fallback


Field-level fallback enables you to specify on a single field, which field values that you want to localize and which field values that you want to fall back to another language.

Enable and set up language fallback

To use the language fallback functionality, you enable either item-level or field-level fallback on the relevant sites and on the relevant items, fields, or templates

Enable site-level language fallback

To enable site-level language fallback:
  • Open \Website\App_Config\Include\Sitecore.LanguageFallback.config and set the following attributes to true:
    • enableItemLanguageFallback
    • enableFieldLanguageFallback
You must enable the attributes on the shell and on each of the relevant websites.
<sites>
      <site name="shell">
        <patch:attribute name="enableItemLanguageFallback">true</patch:attribute>
        <patch:attribute name="enableFieldLanguageFallback">true</patch:attribute>
      </site>
      <site name="website">
        <patch:attribute name="enableItemLanguageFallback">true</patch:attribute>
        <patch:attribute name="enableFieldLanguageFallback">true</patch:attribute>
      </site>
</sites>
In multisite environments where you only want to enable language fallback on a subset of the websites, you need to create a specific shell site for each website where you want the language fallback feature enabled.

Specify the fallback language rules


To specify the fallback language for a language definition item:
  1. In the Content Editor, in the content tree, navigate to and click the language definition item that you want to specify the fallback language for. The language definition items are located in sitecore/system/Languages.
2.      In the Data section, in the Fallback Language field, enter the name of the relevant language, for example, en-AU.


Enable item-level fallback


To enable item-level fallback:
  1. In the content tree, navigate to the relevant item.
  2. To enable language fallback on a template, navigate to the relevant template and click the _Standard Values item.

  1. On the Content tab, in the Advanced section, select Enable Item Fallback.


Enable field-level fallback


To enable field-level fallback:
  1. In the content tree, navigate to the relevant template and click the field definition item that you want to enable field-level fallback for.
  1. In the Data section of the item, select:
    • Enable field level fallback – to enable language fallback for all the language versions of the current field. This applies to all the currently available language versions of the field and any new language versions that you create.

    • Enable versioned field level fallback – to enable language fallback for only the current language version of the field.
To allow different fallback settings for the same field in different languages (versioned fallback), in the Sitecore.LanguageFallback.config file, you must set the configuration setting LanguageFieldFallback.AllowVaryFallbackSettingsPerLanguage to true. However, this degrades performance considerably.



References:


What is Sitecore: a developer's view of the CMS

What is Sitecore?

Sitecore is a global software company offering two major products: a powerful CMS; and a fully-adaptive Digital Marketing System (DMS). In this post I’ll be looking at the CMS side of Sitecore, including the functionality and API it offers developers (we’ll look at the DMS in another post).

The Sitecore CMS – an introduction

Sitecore is one of the leading enterprise-level content management systems built on ASP.NET, enabling web content editors and marketers to have full control over all aspects of their website from social integration and blog posts to advanced personalisation, e-commerce and more. Launched in 2001, Sitecore has used the .NET platform from the beginning of the language itself, and has been growing in popularity over the last few years. Currently on its 7th major version, it now runs on .NET 2.0/4.0, and the core has been rewritten from scratch to take advantage of the improvements made in ASP.NET 4.5.

The Sitecore CMS is at the heart of all Sitecore-powered websites. Having taken advantage of the flexibility, scalability and security of the .NET framework it’s an enterprise favourite, used by leading global organisations such as Experian, Toshiba, Canon and NestlĂ©. The CMS incorporates a powerful desktop interface that is controlled by a fully-customisable role-based system. This desktop is very similar in look and feel to a Windows desktop, which makes it easy for users new to Sitecore to pick up and learn the system. Like Windows, there are also multiple applications aimed at specific tasks such as editing content, managing users, monitoring campaigns, setting up workflows, etc.

The Sitecore CMS

Databases

From a developer perspective Sitecore is a dream to work with, containing 1,300 classes and 5,000 methods that form a rich, extensive developer framework.

The CMS itself is made up of three databases and a web application:


Core database

The core database is used by Sitecore to manage membership (as it builds on ASP.NET membership, this allows standard .NET membership controls to just work), handle system settings and hold the entire configuration for all applications in the CMS. This database can be accessed through the CMS, and you are able to configure any of the settings, override standard functionality, build your own applications, and add buttons and functionality to the ribbon in the editors.


Master database

The master database is where all the content editor work is done. Whenever a new piece of content is created, edited or deleted it is stored here, including those in preview mode. The master database can have workflow enabled and customised, so sections of the site can be locked down to certain roles, or made to go through an approver or translator before they go live.


Web database

The web database is where the live content for the web application is located. It differs from the master database in that it doesn’t contain anything in preview mode and only stores the latest live  version of each item. When a content editor publishes some content it is then copied from the master database to the web database.

In a production environment only the web and core database are then hosted in the SQL server instance on the live environment. This means that the CMS is unavailable from the public website, making the application more secure. On a schedule these databases are replicated using SQL replication from the authoring environment out to the live environment.

Item folders

All the content contained in a Sitecore web application is stored in the content tree, with the Content and Media Library items intended for content editors’ use and the Layouts, System and Templates folders aimed at developers and system administrators (accordingly, all folders are locked down based on the user’s role). Sitecore considers everything within the content tree an item that can be queried using the API; so all pages are items, as are images, PDFs and so on, meaning they can be easily found using this method.

Sitecore CMS Content Tree
Sitecore’s content tree


Content

The Content item folder is where the pages and data for the website are stored, and the structure of these items represents the structure of the website.


Media

The Media Library is where all the physical multimedia files can be stored, either on the file system or as a blob in the database.


Layout

The Layout item folder is where all the ASPX ‘layouts’ for the web application are declared, referencing the location of the file in the web application root. It also contains ‘sublayouts’; ASCX files that represent the widgets etc. used to create a page. Layouts are combined with multiple sublayouts to build pages, which means widgets can be reused and content editors can swap out one widget for another without developer intervention.


System

The System item folder is where standard settings for the content editor and the web application are held. For example, if you wanted to add another language to the web application this is where you would do it.


Templates

The Templates item folder is a where all the template items are stored for the site. Template items are used to describe objects in Sitecore, and specify what fields that object will contain, the content of any standard values (i.e the default value for a field when an item is created, such as the title field always containing the name of the object), and any layouts that are attached to the item (for example, a news article item containing a news layout, along with standard page templates).
  

Sitecore API

The Sitecore API is very powerful; you are able to query Sitecore items using a number of different technologies, from standard .NET web forms to using XSLT and MVC. Sitecore items can also be queried using a number of methods; they have their own query languages Sitecore Query and Sitecore Fast Query which are very similar to XPath, and you are also able to use Linq to query Sitecore items and use ‘where’ clauses to filter down further.

Sitecore also takes advantage of Lucence to crawl and index content on the website. This can be further enhanced with a powerful open source package called Advanced Database Crawler which extends Lucence functionality to index GUIDs, giving developers some great search capabilities such as searching within certain folders, by template types, when a certain field contains a certain value and more. This is great for developers as it adds flexibility while retaining the speed and performance associated with indexing and searching content via Lucence.