1

I have a drupal English/French website. I have a custom content type called 'ad' with all sort of fields. I have created the file 'node--ad.tpl.php' in my theme directory to customize the display of the 'ad' content. I use pixture reloaded theme and DRUPAL 7. In node--ad.tpl.php fields are displayed with this code: print render($content['field_my_field_name']);

I am trying to translate fields (both labels and values) by using 'field translation' module.

Field translation works when I CREATE or MODIFY a content via admin.

However, when I DISPLAY a content of type 'ad', fields are not translated. This is because drupal calls to 'node--ad.tpl.php' and the translation module is probably not invoked. When deleting 'node--ad.tpl.php', drupal calls the default node.tpl.php with a similar results.

Any help would be appreciated, Thanks in advanced,

Notes :

  1. I correctly activated every dependencies for the module.
  2. User interface translation correctly works.
2

OK, I found out myself how to do this:

  1. Translate field labels and values in "Configuration > Regional and language > Translate > Import". You should import the values as 'User Interface', not as 'Fields'. Do not specify a URL, only msgstr and msgid.

  2. Now, you need to add your t() function in node.tpl.php for the translation to be effective, like so:

    • In the node.tpl.php file, to translate field label write something like this: $content['field_my_field']['#title'] = t($content['field_my_field']['#title']);
    • To translate field's value, use: $content['field_my_field']["#items"][0]['value'] = t($content['field_my_field']["#items"][0]['value']);

You can now render your field:

print render($content['field_my_field']);
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.