In the last couple of years, there were quite a lot of posts on the problem of label translation for the list of allowed CCK field values (see e.g. http://drupal.org/node/182884 or http://drupal.org/node/248573);
with newer versions of Drupal, CCK, and i18n released since then, this problem still does not seem to be fully resolved.

For example, I create a text CCK field for countries that should be selected from the "Value|Label" list:

AL|Albania
AM|Armenia

and so on.
Then, I'm trying to translate country names into another language.
I go to admin/build/translate/search and search for 'Albania' string - but I cannot find it.
I do "Refresh strings", I run cron, I dance with a tambourine - but I still cannot find it.
Okay, let's try to use an old trick of assigning label strings via a php code:

return array(
'AL' => t('Albania'),
'AM' => t('Armenia')
);

This seems to work better, and in most cases I am able to find the strings to translate.
Sometimes, however, it does not work either. It may help if you edit and save a node that refers to this CCK field - then, you are usually able to find a string that was not found before. (This also works better for php code than for the regular way of defining value labels).

To cut a long story short, translation of value labels often seems to require some creative efforts instead of being a routine procedure.
Does anybody know - is this a locale issue, or i18n issue, or cck issue?

Comments

jose reyero’s picture

Title: Translation of labels for CCK field values - still problematic... » Translation of labels and values for CCK fields
Component: User interface » Compatibility
Category: support » feature

This behavior you describe is consistent with Drupal 6 not translating user defined strings.

So this may be a feature request for i18n, cck, or both. For now, it's in the 'to-do' list.

SaxxIng’s picture

I'm interested too to this feature... essentially it is a behavior like the selected fields in core profile (that are correctly translatable with the i18nprofile). To Implement this type of feature, at the moment, the major problem/limit is in 18n or in cck?
Regards,
Saxx

.jon’s picture

This missing feature essentially means that you cannot supply a fully translated site, if you use custom CCK fields.

Or is there a way around this? (Displaying translated custom CCK field labels according to the node language)

amccann’s picture

I will be a sponsor of a fix for this if someone is interested in working on it.

Cactii1’s picture

I've tried with the code but it doesn't seem to work for me.

Going to be playing with this for awhile it seems.

EDIT

Forget it - this is not possible.
Going to have to go with a database for each language.
Careful uninstalling anything that has to do with Multi-Language stuff. Totally broke my site and left my database a complete mess.

jakosa’s picture

Ooops. Not good. Hope this will be fixed nicely soon.

Vote_Sizing_Steve’s picture

subscribing

iernst’s picture

i would like to be a sponsor too, if this will be fixed.

yesct’s picture

subscribing.

peterpoe’s picture

My workaround (just for labels) is to change the t() functions in content-field.tpl.php from this:

t($label)

to this:

t($label, array(), $node->language)

Now the labels have the same language of the node.

alonpeer’s picture

Subscribe

ErwanF’s picture

Subscribing. I can hardly believe this.

jose reyero’s picture

Status: Active » Postponed (maintainer needs more info)

I think they finally added t() to titles and descriptions in CCK, so this may not be an issue anymore.

Daniel Norton’s picture

subscribe

sandino’s picture

subscribe

merilainen’s picture

subscribing

headkit’s picture

textfields should be translatable like body-text i think.
subscribing and hoping...

neochief’s picture

Status: Postponed (maintainer needs more info) » Closed (duplicate)

Marking this as duplicate of #531662: Internationalization support, as there posted complete solution.

cangeceiro’s picture

This works if you get the translation table module, then go to "Site Building" > "Translate Interface" > "Search" and search for the label of your cck fields, translate here and the fields display properly.

vronkdaut’s picture

I am not able to translate my cck-field labels.
I tried to import the translations and also to translate individual label in the translate interface.
But they still show up in the original.
Anyone any idea where I could look for remedy?
This should be working, right?
I mean, there is t($label) in content-field.tpl.php.
Does it need more?

EDIT: sorry, mea culpa. haven't updated cck-module. with 2.6 version it works fine.
thanks
Matej

Village Internet’s picture

In Views, use a custom field label and this can be translated

webel’s picture

I have Content 6.x-2.6, and I still can't get the translated field labels to show up on loading translated pages.
I have translations entered for the field labels in the translate interface (found using search as described above).

Is there anything else one had to do ?
What else can I check ?

webel’s picture

@peterpoe who wrote:

My workaround (just for labels) is to change the t() functions in content-field.tpl.php from this:

t($label)

to this:

t($label, array(), $node->language)

Now the labels have the same language of the node.

I did this and got no change, vs Content 6.x-2.6.

druvision’s picture

#21 saved my day! Works for me beautifully. "In Views, use a custom field label and this can be translated".

cholden’s picture

#21 / #24 - How do you translate a custom field label?

arnulfo’s picture

Hi, try (see #19):

Refresh strings:

... admin/build/translate/refresh

snd search string:

... admin/build/translate/search

tomsm’s picture

How can I translate prefix and suffix?

fleshgrinder’s picture

To translate the allowed values of a CCK field you have to use the PHP code form and do the following:

global $language;

return array(
  t('black', array(), $language->language),
  t('white', array(), $language->language),
);

In the object $language is always the currently displayed language stored, so even if the field is displayed in another context it will be translated correctly.

momper’s picture

subscribe

pendashteh’s picture

my solution for translating values:

find the file views-view-field.tpl.php, copy it in your theme directory.
then change:

print $output;

to:

print t($output);
gabrielu’s picture

I still didn't found how to translate prefix and suffix texts to CCK fields. Any hints? Is there a .tpl for displaying the field edit / view wrapper, where I could do the same trick as with views-view-field.tpl.php?

Although I would love a more specific approach, more like:
replace

<span class="field-suffix"><?php echo $suffix; ?></span>

with:

<span class="field-suffix"><?php echo t($suffix); ?></span>

rather than translating the whole $output variable.

Thanks,
Gabriel

Drake’s picture

subscribe

gabrielu’s picture

Hello,
I finally ended up in theming the textfield element.
Placed in my template.php file

<?php
/*
 * theme_textfield($elemnt)
 */

function THEMENAME_textfield($element) {
  $size = empty($element['#size']) ? '' : ' size="' . $element['#size'] . '"';
  $maxlength = empty($element['#maxlength']) ? '' : ' maxlength="' . $element['#maxlength'] . '"';
  $class = array('form-text');
  $extra = '';
  $output = '';

  if ($element['#autocomplete_path'] && menu_valid_path(array('link_path' => $element['#autocomplete_path']))) {
    drupal_add_js('misc/autocomplete.js');
    $class[] = 'form-autocomplete';
    $extra =  '<input class="autocomplete" type="hidden" id="' . $element['#id'] . '-autocomplete" value="' . check_url(url($element['#autocomplete_path'], array('absolute' => TRUE))) . '" disabled="disabled" />';
  }
  _form_set_class($element, $class);

  if (isset($element['#field_prefix'])) {
    $output .= '<span class="field-prefix">' . t($element['#field_prefix']) . '</span> ';
  }

  $output .= '<input type="text"' . $maxlength . ' name="' . $element['#name'] . '" id="' . $element['#id'] . '"' . $size . ' value="' . check_plain($element['#value']) . '"' . drupal_attributes($element['#attributes']) . ' />';

  if (isset($element['#field_suffix'])) {
    $output .= ' <span class="field-suffix">' . t($element['#field_suffix']) . '</span>';
  }

  return theme('form_element', $element, $output) . $extra;
}
?>
KhaledBlah’s picture

@takpar (#30) Thanks, I was looking for that!