Last active
August 29, 2015 14:20
-
-
Save DuaelFr/6406ee31bcd2596bffd5 to your computer and use it in GitHub Desktop.
Translate labels and descriptions without i18n_field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Implements hook_field_attach_view_alter(). | |
*/ | |
function MYMODULE_field_attach_view_alter(&$output, $context) { | |
foreach (element_children($output) as $field_name) { | |
$element = &$output[$field_name]; | |
if (!empty($element['#entity_type']) && !empty($element['#field_name']) && !empty($element['#bundle'])) { | |
$instance = field_info_instance($element['#entity_type'], $element['#field_name'], $element['#bundle']); | |
// Translate field title if set | |
if (!empty($instance['label'])) { | |
$element['#title'] = t($element['#title']); | |
} | |
// Translate field description if set | |
if (!empty($instance['description'])) { | |
$element['#description'] = t($element['#description']); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment