Entity Language Fallback
Allows administrators to configure a prioritized list of fallback languages per language, used for entity view and entity upcast operations.
entity_language_fallback
Install
composer require 'drupal/entity_language_fallback:8.x-1.6'
Overview
The Entity Language Fallback module extends Drupal's multilingual capabilities by allowing site administrators to define fallback language chains for each configured language. When content is not available in the requested language, the module automatically falls back to translations in the configured fallback languages, following the priority order set by the administrator.
This is particularly useful for multilingual sites where not all content is translated into every language. Instead of showing a 404 or access denied error, visitors will see the content in the next best available language according to the configured fallback chain.
The module also provides deep integration with Search API, offering specialized datasources and processors that index content with language fallback awareness, ensuring search results are properly populated even when translations are incomplete.
Features
- Configure prioritized fallback language chains per language through the language edit form
- Automatic language fallback for entity view and entity upcast operations
- Integration with Drupal's core language fallback candidates system via hook_language_fallback_candidates_alter
- Access control handling for fallback entities that may have different languages than the current content language
- Search API datasource plugin 'Content Entity (with language fallback)' for indexing entities with fallback translations
- Search API processor plugin 'Fallback language' that adds fallback translations to search index items
- Automatic tracking of entity insert, update, and delete operations for Search API indexes using fallback datasources
- Static caching of fallback chains and entity access results for performance optimization
Use Cases
Regional website with incomplete translations
A multinational company has a website in English, German, French, and Italian. Not all content is translated into every language. By configuring German to fall back to English, French to fall back to English, and Italian to fall back to English, visitors in any language will see content in their language when available, or in English when not. This prevents 404 errors and maintains a consistent user experience.
Language families with shared content
A website supports multiple Spanish variants (Spain, Mexico, Argentina). Content translated to es-ES (Spanish - Spain) can be used as fallback for es-MX and es-AR. Configure es-MX and es-AR to fall back to es-ES first, then to English. This reduces translation workload while providing the most relevant content to each audience.
Search API indexing with language fallback
A multilingual site uses Search API with Solr or Elasticsearch. By adding the 'Content (with language fallback)' datasource to your index instead of the standard 'Content' datasource, search results will include content from fallback languages. A Spanish user searching for content will find English articles that haven't been translated to Spanish yet, indexed with Spanish language metadata for proper faceting and filtering.
Progressive translation workflow
An organization starts with English content and progressively translates to other languages. Using entity language fallback, they can launch in multiple languages immediately, with English content showing where translations don't exist yet. As translations are completed, they automatically replace the fallback content without any configuration changes.
Tips
- Configure fallback languages in a logical hierarchy - for example, all languages falling back to your default site language ensures maximum content availability
- When using Search API, choose between the datasource plugin (entity_language_fallback) for comprehensive fallback indexing or the processor plugin (fallback_language) to enhance existing datasources
- The fallback chain is evaluated in priority order - place the most similar or preferred languages first
- Fallback configuration is per-language, allowing different fallback chains for different languages based on your audience's preferences
- Changes to fallback configuration require cache clearing to take effect for entity views, and re-indexing for Search API
Technical Details
Admin Pages 1
/admin/config/regional/language/edit/{language}
This module adds an 'Entity fallback language' section to the existing language edit form. Administrators can configure which languages should be used as fallbacks when content is not available in the selected language. The fallbacks are checked in priority order.
Hooks 7
hook_language_fallback_candidates_alter
Alters the language fallback candidates for entity_upcast and entity_view operations. This hook integrates with Drupal's core language fallback system to inject the configured fallback languages.
hook_form_language_admin_edit_form_alter
Adds the 'Entity fallback language' configuration section to the language edit form, allowing administrators to set prioritized fallback languages.
hook_entity_access
Handles access checking for fallback entities. Ensures proper access is granted when an entity is displayed using a fallback translation that may have a different language than the current content language.
hook_entity_insert
Tracks new entities for Search API indexes that use the entity_language_fallback datasource. Computes item IDs for all languages in the fallback chain.
hook_entity_update
Updates Search API tracking when entities are modified. Handles inserted, updated, and deleted translations by comparing old and new translation states.
hook_entity_delete
Removes deleted entities from Search API tracking for indexes using the fallback datasource.
hook_search_api_index_items_alter
Sets the correct language on Search API items being indexed, using the language metadata attached by the fallback datasource.
Troubleshooting 3
Verify that: 1) The entity type is translatable, 2) Fallback languages are configured for the requested language at admin/config/regional/language, 3) The entity has a translation in one of the configured fallback languages, 4) Clear all caches after making configuration changes.
Ensure you are using the 'entity_language_fallback:*' datasource (labeled 'Content (with language fallback)') instead of the standard 'entity:*' datasource. Re-index the search index after changing datasources or fallback language configuration.
The module includes access handling for fallback entities. If access issues persist, check that the source translation (the fallback content) has proper access permissions. The module checks access against the actual entity language, not the requested language.
Security Notes 3
- Access control is properly enforced - the module checks access against the fallback entity's actual language, not the requested language
- The module uses static caching with preventLooping flags to avoid infinite recursion in access checks
- Entity tracking for Search API respects the search_api_skip_tracking flag for entities that should not be indexed