It would be very useful to pass the title through the translate function when the tree is created. I want to use String Overrides module, or just translate interface, and I can't if I don't modify the module code.

This should be the result:

if(!$element['#leaves_only'] || count($term->children) == 0) {
$name = "edit-" . str_replace('_', '-', $element['#field_name']);
$e = array(
'#type' => ($max_choices == 1) ? 'radio' : 'checkbox',
'#title' => t($term->name), <----------- !!
'#on_value' => $term->tid,
'#off_value' => 0,
'#return_value' => $term->tid,
'#parent_values' => $parent_tids,
'#default_value' => isset($value[$term->tid]) ? $term->tid : NULL,
'#attributes' => isset($element['#attributes']) ? $element['#attributes'] : NULL,
'#ajax' => isset($element['#ajax']) ? $element['#ajax'] : NULL,
);

Thank youuuu!

Comments

svdhout’s picture

I created a quick patch to support localized terms.
It could use improvements, but it gets the job done for

/**
 * This function is like taxonomy_get_children, except it doesn't load the entire term.
 *
 * @param $tid
 *   The ID of the term whose children you want to get.
 * @param $vid
 *   The vocabulary ID.
 *
 * @return
 *   An array of taxonomy terms, each in the form array('tid' => $tid, 'name' => $name)
 */
function _term_reference_tree_get_children($tid, $vid) {
  //Should this use the new DB layer?
  $q = db_query("select d.tid, d.name from {taxonomy_term_data} d, {taxonomy_term_hierarchy} h where d.vid = :vid and d.tid = h.tid and h.parent = :tid order by weight, name, tid", array(':vid' => $vid, ':tid'  => $tid));

  $terms = array();
  
  foreach($q as $term) {
    if (module_exists('i18n_taxonomy')) {
      $realterm = taxonomy_term_load($term->tid);
      $term->name = i18n_taxonomy_term_name($realterm);
    }
    $terms[$term->tid] = (object) $term;
  }

  return $terms;
}
tnightingale’s picture

Just wanted to point out this fix in i18n #1340858: Language in entity_label() ensures that entity_label('taxonomy_term', $term) (http://api.drupal.org/api/drupal/includes--common.inc/function/entity_la...) will return the localized term name.
The end result is identical to this patch but it implements good practice using core api calls and makes the i18n dependency check is unnecessary.

tnightingale’s picture

Category: feature » bug
Status: Active » Needs review
StatusFileSize
new3.01 KB

The patch in #1 wasn't working for us. I have rolled a patch that catches every case of $term->name and replaces it with entity_label('taxonomy_term', $term). As I mentioned in #3, this will result in the correctly localized term name if i18n dev (or the new i18n release when it comes out) is installed.

Marc-Antoine’s picture

I tested it with the latest i18n and tree ref release and it worked, thank you

bartk’s picture

Status: Needs review » Closed (fixed)

Thanks for the patch. I've included it in 1.7.

creando sensaciones’s picture

Version: 7.x-1.6 » 7.x-1.9
Status: Closed (fixed) » Active

I hope I'm doing right by opening this thread again.

I'm using version 1.9 and facing the same problem: Localized terms are not translated, whatever I try. With other widgets they are.
I checked the code and found the function patched in #1 and #3 beeing totally different now.
So I guess with changing the method the problem returned.

My side design is very much depending on this amazing module. So I hope I find a way to fix this.
Thanks anyway.

creando sensaciones’s picture

Status: Active » Closed (fixed)

I found the reason of missing localization in a conflict with the title module: http://drupal.org/node/1865604.

After installing the dev version of the title module everything seems fine.