Skip to content

Instantly share code, notes, and snippets.

@DuaelFr
Last active August 29, 2015 14:20
Show Gist options
  • Save DuaelFr/6406ee31bcd2596bffd5 to your computer and use it in GitHub Desktop.
Save DuaelFr/6406ee31bcd2596bffd5 to your computer and use it in GitHub Desktop.
Translate labels and descriptions without i18n_field
<?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