In the i18n module for Drupal 5 there is no direct way of translating the vocabulary names whilst having associated translated terms. To translate the vocabulary names, I send them to the t() function then I create a translation in site configuration>localisation>manage strings.
Would it be possible to modify Faceted Search to send the vocabulary names to the t() function? Or is there another solution?

Many Thanks,

A Burton

Comments

ABurton’s picture

Upon further inspection, I read in the documentation that Faceted search should work with i18n. In Site Configuration>Multilingual System>Translation, all vocabularies are checked, (so that they are translated by the localisation system), but still the vocabulary names are not translated. (The terms are translated though).

Has anybody got any ideas?

Thanks,

A Burton

david lesieur’s picture

The documentation you have read must have been that of the Drupal 6 branch. The Drupal 6 branch of Faceted Search supports localization of term and vocabulary names (coincidentally, this has been added to the dev version only yesterday!). However, there is not sufficient functionality in the Drupal 5 version of i18n to backport that code to Faceted Search for D5.

t() is not meant to be used with user data, which means it won't be added to Faceted Search for localizing term or vocabulary names.

The right way to solve this would be, I guess, to re-write the i18ntaxonomy module to use the i18nstrings module as in the D6 version. Then the localization code in Faceted Search could be backported to D5. This is not a task I intend to do, but patches are welcome.

ABurton’s picture

Thanks for your swift reply. We are stuck with Drupal 5 for the moment because some of the modules we use have not yet been updated to Drupal 6. I will try and see if I can find a solution by studying the i18ntaxonomy, i18nstrings and faceted search modules. If anyone has any ideas or could help me, it would be most appreciated. I'm a bit surprised that no one else has had the same problem.

Thanks again,

A Burton

david lesieur’s picture

Title: Faceted search and i18n » Faceted search and i18n under Drupal 5
ABurton’s picture

Version: 5.x-1.0-beta4 » 5.x-0.11

I found a solution by intercepting the facted search object and translating the vocabulary name before the block is created.
David, you said:

t() is not meant to be used with user data, which means it won't be added to Faceted Search for localizing term or vocabulary names.

but for me vocabulary names are not user data. Could you please explain? Terms don't need to be localized as they are translated by the i18n module.

Anyway here is the modification I did to the hook_block implementation faceted_search_ui_block in the file faceted_search_ui.module. I have commented the modified lines. Please note, I started this post for version 5.x-1.0-beta4 but the following modif does not work for that version. We decided to stay with the 5.x-0.11 for which this modif works. Sorry, but I don't know how to make a patch. Any comments would be appreciated.

A. Burton

/**
 * Implementation of hook_block().
 */
function faceted_search_ui_block($op = 'list', $delta = 0, $edit = array()) {
  if ($op == 'list') {
    $blocks['current'] = array('info' => t('Faceted search / Current search'));
    $blocks['keyword'] = array('info' => t('Faceted search / Keyword search'));
    $blocks['guided'] = array('info' => t('Faceted search / Guided search'));
    $blocks['related'] = array('info' => t('Faceted search / Related categories'));
    $blocks['sort'] = array('info' => t('Faceted search / Sort options'));
    return $blocks;
  }
  elseif ($op == 'view' && user_access('use faceted search')) {
    global $_faceted_search_ui_current_search;

    faceted_search_ui_add_css();
    # copy faceted search object to avoid manipulating the original...
    $_faceted_search_ui_current_search_copy = drupal_clone($_faceted_search_ui_current_search);

    # translate the vocabulary name...
    foreach($_faceted_search_ui_current_search_copy->_facets as $facet) {
	$facet->_vocabulary->name = t($facet->_vocabulary->name);
    }

    # in the following function calls, use the altered copy to create block...
    switch ($delta) {
      case 'current':
        $block['subject'] = t('Current search'); 
        $block['content'] = faceted_search_ui_show_current_search($_faceted_search_ui_current_search_copy);
        break;

      case 'keyword':
        if ($_faceted_search_ui_current_search->ui_state['stage'] == 'results') {
          $block['subject'] = t('Keyword search'); 
          $block['content'] = faceted_search_ui_show_keyword_search($_faceted_search_ui_current_search_copy);
        }
        break;

      case 'guided':
        if ($_faceted_search_ui_current_search->ui_state['stage'] == 'results') {
          $block['subject'] = t('Guided search');
          $block['content'] = faceted_search_ui_show_guided_search($_faceted_search_ui_current_search_copy);
        }
        break;

      case 'related':
        if (arg(0) == 'node' && is_numeric(arg(1)) && !arg(2) && $node = node_load(arg(1))) {
          if ($content = faceted_search_ui_show_related_categories($node)) {
            $block['subject'] = t('Related categories'); 
            $block['content'] = $content;
          }
        }
        break;

      case 'sort':
        $block['content'] = faceted_search_ui_show_sort_options($_faceted_search_ui_current_search_copy);
        break;
    }
    return $block;
  }
}
ABurton’s picture

Same modification in function faceted_search_ui_stage_facet() which is called when there are too many categories to display and we click on "more...". There are probably other places where the fix has to be made, but for us it is sufficient at least until we can upgrade to version 6.

A. Burton

/**
 * Menu callback to display a facet's categories.
 */
function faceted_search_ui_stage_facet() {
  global $_faceted_search_ui_current_search;

  # copy faceted search object to avoid manipulating the original...
  $_faceted_search_ui_current_search_copy = drupal_clone($_faceted_search_ui_current_search);

  # translate the vocabulary name...
  foreach($_faceted_search_ui_current_search_copy->_facets as $facet) {
    $facet->_vocabulary->name = t($facet->_vocabulary->name);
  }

  faceted_search_ui_add_css();
  faceted_search_ui_add_tooltips();
  
  // Build the search results, which are required to count nodes per category
  $_faceted_search_ui_current_search_copy->execute();

  // Find what facet to show
  list($index, $facet) = $_faceted_search_ui_current_search_copy->get_facet_by_id($_faceted_search_ui_current_search_copy->ui_state['facet-key'], $_faceted_search_ui_current_search_copy->ui_state['facet-id']);
  if (!isset($index) || !isset($facet)) {
    drupal_not_found();
    return;
  }

  faceted_search_ui_set_title($_faceted_search_ui_current_search_copy);
  $categories = faceted_search_ui_build_categories($_faceted_search_ui_current_search_copy, $index); // TODO: paging
  return theme('faceted_search_ui_stage_facet', $_faceted_search_ui_current_search_copy, $index, $facet, $categories);
}
david lesieur’s picture

Terms are user-entered data, even though the users might be site administrators. What I mean with "user-entered data" is data not originating from module source code.

This approach will work, but keep in mind that on some sites using t() that way will greatly "pollute" the locales_source table.

ABurton’s picture

OK, thanks. I think it will be alright because we have only have 15 vocabulary names to be translated with t(). Thanks again for you time,
A. Burton

drupalfan81’s picture

Has anyone found a solution for this in D6. All my translated terms are displaying in Faceted Search, but the vocabulary names themselves are not being translated. My users cannot use the faceted search navigation if they cannot read what the vocabulary terms are. Any solutions to this problem?