function bynder_get_applicable_label_translation in Bynder 8.3
Same name and namespace in other branches
- 8 bynder.module \bynder_get_applicable_label_translation()
- 8.2 bynder.module \bynder_get_applicable_label_translation()
- 4.0.x bynder.module \bynder_get_applicable_label_translation()
Returns most appropriate label for option.
Parameters
array $option: The property array from Bynder.
Return value
string Returns translated label for the current language if available or the default label.
1 call to bynder_get_applicable_label_translation()
- BynderConfigurationForm::buildForm in src/
Form/ BynderConfigurationForm.php - Form constructor.
File
- ./
bynder.module, line 154 - Provides bynder integration.
Code
function bynder_get_applicable_label_translation(array $option) {
$current_language_id = \Drupal::languageManager()
->getCurrentLanguage()
->getId();
$available_label_translations = [];
if (isset($option['labels'])) {
foreach ($option['labels'] as $langcode => $label) {
// Drupal doesn't differentiate by default en_US and en_GB. Here if we
// first get en_US and then en_GB we return the value from en_GB for the
// English language. If we get the reverse order the reverse is true.
$available_label_translations[substr($langcode, 0, 2)] = $label;
}
}
if (array_key_exists($current_language_id, $available_label_translations)) {
return $available_label_translations[$current_language_id];
}
return $option['label'];
}