Language Fall Back Module

Last year we implemented the language fallback module for a client to enable them to view the website in Canadian French and English. Language fallback module displays the default language version of an item in absence of the french version if the Sitecore context is changed to French.

Language Fall Back Module:-

Install the following packages  from the reference links given below.

  1. Sitecore_6_5_PartialLanguageFallback_ItemProvider-2012_02_02.zip (items and files)
  2. LanguageFallbackCompleteSitecore6_5-2012_02_02.zip(items only)

Files and Configuration:-

Acquire the shared source solutions and build them with the Sitecore libraries specific for your version (your Sitecore.Kernal.dll and any other Sitecore libraries needed)

See the “Shared Source” links below at the end

In the package you will see the following files:-

bin/Sitecore.SharedSource.PartialLanguageFallback.dll

bin/Sitecore.LanguageFallbackItemProvider.dll

Sitecore.SharedSource.PartialLanguageFallback.config

Sitecore.LanguageFallbackItemProvider.config

In Site definitions, add enableFallback

<site name=”website” virtualFolder=”/” physicalFolder=”/” rootPath=”/sitecore/content” startItem=”/Incapital” database=”web” domain=”extranet” allowDebug=”true” cacheHtml=”true” htmlCacheSize=”10MB” registryCacheSize=”0″ viewStateCacheSize=”0″ xslCacheSize=”5MB” filteredItemsCacheSize=”2MB” enablePreview=”true” enableWebEdit=”true” enableDebugger=”true” disableClientData=”false” loginPage=”/LoginRedirect.aspx” enableFallBack=”true“/>

In Web.config change the Sitecore variable “languageEmbedding” to “always” for embedding language in the URL.

Sitecore changes:-

Add the languages (country-Language) to Sitecore (/sitecore/system/languages)

You may need to temporarily modify your configuration to allow an Item name with a dash

<setting name=”InvalidItemNameChars”>

<patch:attribute name=”value”>\/:?&quot;&lt;&gt;|[]-</patch:attribute>

</setting>

Update the two fallback fields on languages

Post1

There are two fallback fields (one for each library)

Data/Fallback {C2E0719F-5806-4E5A-AAFD-7DED272A5601}

FallbackLanguage {892975AC-496F-4AC9-8826-087095C68E1D}

Enable Fallback on Data Templates:

For the fallback module to work you need to enable the fall back on each data template where you want the language fallback to work. When the fall back module is enabled Sitecore will fallback to default language when different language versions for items are not present. Publish the data templates.

Post 2

Code:-

How user would switch languages may be a coding/configuration effort:-

One example is having a language switcher control in the site navigation (like choosing a country)

Also we have written a clientlanguageresolver.cs to intercept the http request to check for cookies, browser settings,etc and the following web.config changes are made to include this :-

code 1

Code 2

Code 3

<httpRequestBegin>

<!– Language resolver from webclient–>

<processor type=”InCapitalCanada.httpModules.ClientLanguageResolver,InCapitalCanada” />

<!– Language resolver from webclient–>

</httpRequestBegin>

Shared Source/Reference Links:-

http://mediacontent.sitecore.net/Support/LanguageFallbackSolution/

http://trac.sitecore.net/LanguageFallback/

http://svn.sitecore.net/LanguageFallback/

http://sitecoreblog.alexshyba.com/2011/08/partial-language-fallback-module-update.html

Language Fallback Sitecore Items:-

All of these data items are now packaged in LanguageFallbackCompleteSitecore6_5-2012_02_02.zip

post 3

Website/App_Config will have:-

post 4

Website/Bin will have:-

post 5

With the above settings and coding language fallback module would work without any errors. I also have a custom dll from Sitecore support for searching French Text from RTE.

Advertisements

Single Sign On for Sitecore CMS websites using Virtual Users.

Many times we have a central repository like an external database, Salesforce CRM, Microsoft Dynamics CRM, etc and we need to authenticate users against those external systems before allowing them to access secured data like media items, pdf’s, etc hosted on Sitecore website, this can be achieved by creating virtual users in Sitecore.

For this to happen the user needs to be an extranet user in Sitecore, to avoid adding thousands of such users as extranet users in Sitecore a better approach is to create a virtual user. Once the virtual user is created you can authenticate the user against any external system using there API’s, after the user is authenticated using external system we can create a Sitecore virtual user using Sitecore Security API’s. We can also make the virtual users members of different Sitecore roles and control there access using access rights.

Code snippet for creating virtual users is as follows:-

Sitecore.Security.Accounts.User user =  Sitecore.Security.Authentication.AuthenticationManager.BuildVirtualUser(@”domain\user”,true);

The above code snippet most preferably should be used in the login method of your login form after authenticating the user against external system.

Code snippet for Logging in virtual users:-

Note: By default Sitecore does not honor the expiration timeout value when using AuthenticationManager.Login(string userName). To enforce this and avoid having untold numbers of Virtual Users being orphaned in Sitecore you need to implement the fix detailed here: http://webcmd.wordpress.com/2012/03/07/sitecore-setting-timeout-on-a-virtual-user/

Code snippet for logging out and deleting the virtual users:-

Sitecore.Security.Authentication.AuthenticationManager.Logout();

VirtualUser.User.Delete();

 

The above code snippet should be a part logout method depending on your logic.

References:-

  1. http://sdn.sitecore.net/upload/sitecore6/62/security_api_cookbook_sc60-62-a4.pdf
  2. http://www.sitecore.net/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2011/08/Authentication-Options-with-the-Sitecore-ASPNET-CMS.aspx
  3. http://webcmd.wordpress.com/2012/03/07/sitecore-setting-timeout-on-a-virtual-user/