Translation of field labels and taxonomy terms: interface or content?

Events happening in the community are now at Drupal community events on www.drupal.org.
rogerpfaff's picture

This is a problem I described in the entity translation issue queue too: http://drupal.org/node/1342132

Field labels and Taxonomy Terms are seen as interface by drupal and entity translation. That is ok if you create content but brings up errors in some constellation as I described in the issue above.

Imagine you want your users work with the interface set to one language only (their native language) so you set 'interface language detection' to 'user setting'. Your content will be selected by URL and a site wide fallback language must be set to see all content with some titles in content listings.

For content types which use taxonomy references you will have now the problem that (let's consider a french user) the terms and field labels are always french even if the content is english. This only exists for logged in users not for guests. An anonymous user coming in by an URL will see the translated content.

On the one hand I understand the way it works but on the other hand I think that in the view mode the labels and terms should be translated to the content language even if the interface language ist set different.

Comments

interface text

gábor hojtsy's picture

Entity translation does not really deal with interface text. I bet you use i18n module to translate your field labels, since I don't know of any other module that would implement that. So if you also use i18n to translate your taxonomy terms, it would also use a t()-like way to translate them. To make the display language of those configurable, this is really a task for i18n module. Not sure are looking at the right module.

Post is a bit old but thought

guy_schneerson's picture

Post is a bit old but thought I'd share:
One other module that can do this is Display Suite, lets you set the label and that puts it through t().
This is only applicable if you are already using DS.

Clarification

kristen pol's picture

I added some clarification here:

http://drupal.org/node/1342132#comment-5487308

@Gábor Hojtsy - thanks for the reminder that the Entity translation module doesn't to the field label translation... this is confusing to say the least! I wish the Field translation module was called something different like Field settings translation though so it might be a bit less confusing.

Kristen

This is how to translate

ymakux's picture

This is how to translate taxonomy term using t() function

function MYMODULE_taxonomy_term_load($terms) {
  $catalog_vid = 1; // vid of vocabulary
  foreach($terms as $tid => $term) {
    if($term->vid == $catalog_vid) {
       $terms[$tid]->name = t($term->name);
       // or, maybe better way
       // $t = get_t();
      //  $terms[$tid]->name = $t($term->name);
    }
  }
}

Then you can translate term names at admin/config/regional/translate/translate

Another method which allows

ymakux's picture

Another method which allows to bypass cache

function MYMODULE_preprocess_field(&$variables, $hook) {
 
  $t = get_t();
 
  if(!empty($variables['label'])) {
    $variables['label'] = $t($variables['label']); // translate field label
  }
 
  if(!empty($variables['items'])) {
    foreach($variables['items'] as $delta => $item) {
      switch($variables['element']['#field_type']) {
        case 'taxonomy_term_reference' : // taxonomy term
          $variables['items'][$delta]['#title'] = $t(strip_tags($item['#title']));
          break;
        case 'list_text':  // select list
          $variables['items'][$delta]['#markup'] = $t(strip_tags($item['#markup']));
          break;
        //case 'my_field_type' :  //
          //
         //break;
      }
    }
  }
}

Thanks @ymakux for your

maxmendez's picture

Thanks @ymakux for your simple solution, it works fine for my little and simple site.

Internationalization

Group organizers

Group categories

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: