Issue #1157512 by webflo: Fixed Labels are not translated with i18n_field().
authorJose Reyero
Wed, 8 Jun 2011 07:54:09 +0000 (09:54 +0200)
committerJose Reyero
Wed, 8 Jun 2011 07:54:09 +0000 (09:54 +0200)
i18n_field/i18n_field.module

index 1549ec6..20851a2 100644 (file)
@@ -256,6 +256,28 @@ function i18n_field_field_widget_form($form, $form_state, $field, $instance, $la
 }
 
 /**
+ * Implements hook_field_attach_view_alter().
+ */
+function i18n_field_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_read_instance($element['#entity_type'], $element['#field_name'], $element['#bundle']);
+
+      // Translate field title if set
+      if (!empty($instance['label'])) {
+        $element['#title'] = i18n_field_translate_property($instance, 'label');
+      }
+
+      // Translate field description if set
+      if (!empty($instance['description'])) {
+        $element['#description'] = i18n_field_translate_property($instance, 'description');
+      }
+    }
+  }
+}
+
+/**
  * Implements hook_field_create_field().
  */
 function i18n_field_field_create_field($field) {