1
votes

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.

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.

1

1 Answers

1
votes

OK I found out myself how to do this. I give the solution here. It may help for others :

First, translate field labels and values in Configuration > Regional and language > Translate > Import. Do not import values as Fields but as User Interface. Do not specify an URL (only msgstr and msgid).

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

In the node.tpl.php file, if you want to translate field label, write this : $content['field_my_field']['#title'] = t($content['field_my_field']['#title']);

Then to translate field value do this : $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']);