0
votes

In my multilanguage Drupal 6 website I need to make my CCK field default values translatable, i.e.

  • Hello - in the English version
  • Bonjour - in the French one

I cannot find this text with Translation Table, neither are these values in variable table so that I can use multilingual variables.

Do You know how to have different default values in different languages?

2

2 Answers

1
votes

This method is a bit of a hack. Im not sure I would deploy this without really considering the consequences. For a simple usecase it MIGHT be ok.

Create a custom module, lets say def_translate. To def_translate.module, add a function

function def_translate_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  if($node->type == "sometype" 
        && $op == "load" 
        && $node->field_some_cck_field_type[0]['value'] == "your default value") 
   {     
      $node->field_some_cck_field_type[0]['value'] = 
              t($node->field_some_cck_field_type[0]['value']); 
  }
}

Ok - so what is this doing?

When a node is loaded, hook_nodeapi gets called, with $op set to "load". This gives us an opportunity to do manipulate the node before it is rendered. Before we do anything we check

  1. Is this the right type of node?
  2. Is our op = "load"?
  3. Is the value our default value?

What we then do is pass the existing default value through the t() function. This will make the default string available to i18n translation table, and you can then use the normal way of translating strings.

*DISCLAIMER* I have not tested this myself in production. Im not entirely sure what the effects will be. You probably want to think this through before implementing it, and you probably want to put some features in to look up the default values from the DB incase they are changed in the CCK UI.

Hope this helps - or possibly shakes a hint of a solution to your problem!

1
votes

When you define the CCK field, you can enter a PHP code snippet to override the default value of the field.

Enter the following there :

return array(0 => array('value' => t('Hello')));

Now access a node add page with this CCK field from a non-English version so that it gets added to translatable strings.

Now you're able to translate it using the "Translate interface" menu (it might take a visit to the "create" page of your cck type first though). It doesn't require any extra modules in fact, just basic D6 (and it probably works in D5 and D7 as well).