2

We have a multilingual website and using language fallback(Item Level). I am finding hard to get the fallback language of an item.

We have fr-FR which is falling back to en-FR. But when I get the item in fr-FR and check for

LangugaeFallbackEnabled field is false

I could not find any other fields specifying this information.

I have double checked in Sitecore it's falling back to en-FR.

What's the best way to check for the fallback language of an item?

Sitecore Version - 8.1 update 3

2
  • With language fallback, accessing the item in the language that is falling back should give the item in the fallback language without any extra checks. Is that not working or are you trying to check if the item is falling back vs not for a specific reason?
    – Teeknow
    Commented Aug 29, 2017 at 15:33
  • Its giving me the item in falling back language. I am trying to check if item is falling back because I need to execute some logic if it is. Commented Aug 29, 2017 at 15:41

1 Answer 1

3

To check if an item you are accessing is a fallback use the IsFallback property: Sitecore.Data.Items.Item.IsFallback. To get the actual language being used you could use the method Sitecore.Data.Items.Item.GetFallbackItem() and check the language on that.

It's possible that you could do this more efficiently while looking at that method by using the language fallback manager: Sitecore.Data.Managers.LanguageFallbackManager.GetFallbackLanguage(Language language, Database database, ID relatedItemId).

12
  • Is there a way to find which language it is falling back to? Commented Aug 29, 2017 at 15:46
  • You can try using this method: Sitecore.Data.Items.Item.GetFallbackItem(). Then you would check the Language property of what that returns. I have updated my answer to include that.
    – Teeknow
    Commented Aug 29, 2017 at 15:57
  • Actually, that did not help, isFallback property is false and GetFallBackItem is null? Commented Aug 29, 2017 at 16:05
  • 1
    @DheerajPalagiri can you verify that accessing the item while your context language is set to the language that does not have a version has its fields filled with the content of the language it falls back to? Another thing I would like you to try running is the following: Sitecore.Data.Managers.LanguageFallbackManager.GetFallbackLanguage(Language language, Database database). This should return your fallback language. If it does not then I believe there is an issue with how that is configured (/sitecore/system/Languages).
    – Teeknow
    Commented Aug 29, 2017 at 16:11
  • 1
    Alright sounds good. If the linked question doesn't help out feel free to post a new question focused on your issue.
    – Teeknow
    Commented Aug 29, 2017 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.