Closed (fixed)
Project:
Node Compare
Version:
7.x-1.4
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
16 Sep 2013 at 16:06 UTC
Updated:
23 Sep 2013 at 14:27 UTC
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:
Comments
Comment #1
Dalay commented@calculus, many thanks for your suggestions.
Yes, it is useful, thanks.
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?
Comment #2
calculus commentedI 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.
Comment #3
Dalay commentedTry 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.
Comment #4
calculus commentedAs far as i know entity translation provides translation for field values (content) not field properties like labels, descriptions, list option labels etc (user interface).
Comment #5
Dalay commentedOk, I will add support for i18n_field.
Comment #6
Dalay commented@calculus, your suggestions are implemented in the new release 7.x-1.5. Thanks for your participation.