1 locale.module | locale_field_language_fallback(&$display_language, $entity, $langcode) |
Applies language fallback rules to the fields attached to the given entity.
Core language fallback rules check if fields have a field translation for the requested language code. If so the requested language is returned, otherwise all the fallback candidates are inspected to see if there is a field translation available in another language. By default this is called by locale_field_language_alter(), but this behavior can be disabled by setting the 'locale_field_language_fallback' variable to FALSE.
Parameters
$display_language: A reference to an array of language codes keyed by field name.
$entity: The entity to be displayed.
$langcode: The language code $entity has to be displayed in.
File
- core/
modules/ locale/ locale.module, line 297 - Add language handling functionality and enables the translation of the user interface to languages other than English.
Code
function locale_field_language_fallback(&$display_language, $entity, $langcode) {
// Lazily init fallback candidates to avoid unnecessary calls.
$fallback_candidates = NULL;
$field_languages = array();
foreach ($display_language as $field_name => $field_language) {
// If the requested language is defined for the current field use it,
// otherwise search for a fallback value among the fallback candidates.
if (isset($entity->{$field_name}[$langcode])) {
$display_language[$field_name] = $langcode;
}
elseif (!empty($entity->{$field_name})) {
if (!isset($fallback_candidates)) {
require_once BACKDROP_ROOT . '/core/includes/language.inc';
$fallback_candidates = language_fallback_get_candidates();
}
foreach ($fallback_candidates as $fallback_language) {
if (isset($entity->{$field_name}[$fallback_language])) {
$display_language[$field_name] = $fallback_language;
break;
}
}
}
}
}