Hello and thank you for the module.

I wanted a certain functionality so i override node_compare.pages.inc

1. Translate field labels with i18n_field module.
2. Hide fields if every node's value is empty. F.e. let us assume that there is an list_text field and the compared nodes have no values. Now module generates a row table full of N/A. We could just hide it.

I replaced lines 146-152 with:

$row = array(array('data' => i18n_field_translate_property($instance, 'label'), 'class' => 'compare-field-label'));
$field_has_content = FALSE; 

foreach (array_keys($header) as $nid) {
  $field = field_view_field('node', $nodes[$nid], $field_name, $display);
  if ($field) {
    $row[] = render($field);
	$field_has_content = TRUE;
  } else {
    $row[] = t('N/A');
  }
}

if ($field_has_content) {
  $rows[$display['weight']] = array('data' => $row, 'class' => array('compare-field-row', $field_name));
}

We should check if i18n_field module exists, in order to use i18n_field_translate_property function.

F.e.

if (module_exists('i18n_field')) {
  $row = array(array('data' => i18n_field_translate_property($instance, 'label'), 'class' => 'compare-field-label'));
} else {
  $row = array(array('data' => $instance['label'], 'class' => 'compare-field-label'));
}

Also field hiding functionality could be controlled with a boolean variable in form.

Other suggestions are controlling:

  • N/A text
  • "Properties:" label (line 154)
  • Display of field labels (due html table, label could replaced by nbsp character)

Comments

Dalay’s picture

@calculus, many thanks for your suggestions.

$field_has_content = FALSE;

foreach (array_keys($header) as $nid) {
  $field = field_view_field('node', $nodes[$nid], $field_name, $display);
  if ($field) {
    $row[] = render($field);
    $field_has_content = TRUE;
...

Yes, it is useful, thanks.

if (module_exists('i18n_field')) {
  $row = array(array('data' => i18n_field_translate_property($instance, 'label'), 'class' => 'compare-field-label'));
} else {
  $row = array(array('data' => $instance['label'], 'class' => 'compare-field-label'));
}

I'm not familiar with the i18n_field, but looking at the code, I see no point in doing it just for the label. But what about the values ​​of the fields?

calculus’s picture

I am not familiar with another way (except for i18n_field) to translate labels or other field properties (options in select inputs, descriptions etc).

I am not an expert either but with basic debugging, field_info_instance function (you are using it for field labels among other things) returns only default language label.

On the other hand, field_view_field function (you are using it inside foreach loop to extract values) returns translated values and labels.

In my test installation, i have translated values with i18n_field and entity translation. field_view_field function returns correct translated values no matter what.

Dalay’s picture

Try the Entity translation. It also provides a user interface to actually use field translation, there isn't much you can do with translatable fields without that module anyway.

calculus’s picture

As far as i know entity translation provides translation for field values (content) not field properties like labels, descriptions, list option labels etc (user interface).

Dalay’s picture

Ok, I will add support for i18n_field.

Dalay’s picture

Status: Active » Closed (fixed)

@calculus, your suggestions are implemented in the new release 7.x-1.5. Thanks for your participation.