0
votes

I have following question

Item level Fallback is enabled in “Sitecore.LanguageFallback.config” and fallback/default language is “en”

Languages configured in site : en, de, el, es, fr, it, ja, pt, zh

Scenario: We try to access the site with Russian(ru) or any other language which we have not configured in sitecore . The site still loads without any error, but no contents are fetched, as the language is not configured the fallback to English language doesn’t working.

Does sitecore loads the page for all the valid languages available irrespective of languages we configure under system/languages. If Yes, then should we explicitly handle in our code to restrict this behavior or fallback to English? Or is there a way we can handle this through configuration.

enter image description here

2

2 Answers

1
votes

This is the expected behaviour unfortunately, Sitecore will load for all languages regardless of whether you have them enabled/configured in the CMS.

You need to handle this yourself in code. On possible option is to use a similar processor to this by John West and override the StripLanguage processor.

public override void Process(PreprocessRequestArgs args)
{
  if (args != null
    && args.Context != null
    && !string.IsNullOrWhiteSpace(args.Context.Request.FilePath))
  {
    string prefix = WebUtil.ExtractLanguageName(
      args.Context.Request.FilePath);

    if ((!string.IsNullOrWhiteSpace(prefix))
      && !this._validLanguages.Contains(prefix.ToLower()))
    {
      return;
    }
  }

  base.Process(args);
}

By simply not stripping out the language code when interpreting request URLs, Sitecore will try resolve the item it will not find a matching ru item under your home and therefore throw as 404 as you would expect it to. (You could also redirect the user to the default language at this stage instead).

The slight down side to this is that the languages are specified in config and any changes would require a deployment. Depending on your exact requirements, you could read these in from an Item specified in the Sitecore tree if you require it to be more dynamic.

0
votes

Your language fallback is not setup correctly. Read the manual at the Sitecore site.

To have a Russian version falling back to English, you need to create a Russian language (it will appear in the Languages list as in your screenshot). On that item, you can fill the Fallback Language field. Set that to English. This defines the fallback language.

In order to have your items use the item fallback (which is what you want if you don't want to create versions in Russian) you must enable that on your items. The easiest way to do so is set it in the standard values of the templates. The checkbox Enable Item Fallback must be checked for the fallback mechanism to work.