Kamran
Kamran

Reputation: 4100

Sitecore best possible way to get Item in English if its not present in the given language

In my website every item exist in English version. Now if a user with Content Language ='Danish' wants to access an item which does not exist in 'Danish' language. The users actually see nothing, what I want to do is that if the item does not exist in desired language then get the English version of it.

I am doing this to achieve my goal:

string itemId = "{05B1C498-39D1-40D6-B454-2A3277A6DDF9}";
Item versionItem = Sitecore.Context.Database.GetItem(itemId);
if (versionItem.Versions.Count > 0)
    lblOutput.Text = "Item does not exist in desired language";
else
{
    versionItem = contextDatabase.GetItem(itemId, Sitecore.Data.Managers.LanguageManager.GetLanguage("en"));
    lblOutput.Text = "Here is the item in default English language";
}

Is it the right way to achieve what I want? because my concern is that then I have to use this code to access every item. Is there any global settings or some thing like this so that I can get the item in 'English' language if it is not exist in desired language.

Upvotes: 2

Views: 1422

Answers (2)

Vlad Iobagiu
Vlad Iobagiu

Reputation: 4118

You can use Fallback language module for your case.

https://marketplace.sitecore.net/en/modules/language_fallback.aspx

http://www.sitecore.net/Learn/Blogs/Technical-Blogs/Elizabeth-Spranzani/Posts/2014/10/Fallback-followup.aspx

http://www.sitecore.net/Learn/Blogs/Technical-Blogs/Elizabeth-Spranzani/Posts/2014/03/Fallback-Series-Post-2.aspx

From the second blog post looks like is working on Sitecore 7.2.

With Sitecore 7 being the norm now, and the impending Sitecore 8 on the horizon, I figured it was about time to run some tests and make sure all of this still worked on the latest publicly released version: Sitecore 7.2 Update 2 (revision 140526).

Upvotes: 3

Marek Musielak
Marek Musielak

Reputation: 27132

You should check something called Language Fallback in Sitecore.

There are plenty of blog post about it, e.g.:

http://jonathandeveloper.com/2014/07/sitecore-7-language-fallback-revisited-and-glass/

There is also a Language Fallback Sitecore module on marketplace (but only working with Sitecore 6 from what is described).

Upvotes: 0

Related Questions