Language fallback

The language fallback mechanism is responsible for providing a content for a localized attributes if no value is provided for the current localization settings.

The Problem

What language shall the user see if the language in the current language is missing.

Default language vs. Current language

Each site/store has its defaultLanguage. The defaultLanguage is used as a fallback language when the user tries to open the website and their browser language preferences are not supported.

However, from that point on the user may choose whatever language they like. So, initially the currentLanguage is either the defaultLanguage (if the current browser language is not supported by the site) or one of the supported languages (if the current browser language is supported by the site). Later on the currentLanguage and the defaultLanguage can be different.

Supported levels of language fallback

  • 1st level - fallback to the country non specific locale.

Sample scenario: The site’s content is translated in English (EN only). The user opens the website with EN_US or EN_GB as a default language. The site fallbacks to the EN version and displays the EN content.

  • 2nd level - fallback to the default language if the content for the current language is not present.

Sample scenario: The site’s content is translated in English only. The user opens the website with bg_BG as a default language. Since English is the default site language, it will be used as a fallback. The content will be displayed in English.

The algorithm applied in the example:
- the user tries to find "bg_BG" content;
- fallback and try to get just "bg" content;
- fallback to get the default language content, let’s say "en_US";
- fallback third time to get the default language content without the country (meaning "en" in the sample scenario);
- an empty string is returned in case no content is found in current + fallback or default + fallback languages.