When I use this token [facetapi_active:facet-label] in the Current Search block, I notice that it is not translatable through the Interface localization. Also I cannot rename default labels such as 'Field: Store » Title'?

This is what I need:

- rename facet label 'Field: Store » Title' to 'Store'
- consequently allow localization of 'Store' to 'Laden' in German

Comments

Anonymous’s picture

Category: task » support
Status: Active » Fixed

It can be done like this (in a custom module):

/**
 * Implements hook_facetapi_facet_info().
 *
 * Needed to rename and translate Facet Label tokens
 */
function custom_facetapi_facet_info(array $searcher_info) {
  $facets = array();

  // Facets are usually associated with the type of content stored in the index.
  if (isset($searcher_info['types']['my_type'])) {
    $facets['brand']['label'] = t('Brand');
    $facets['categories']['label'] = t('Category');
    $facets['discount']['label'] = t('Discount');
    $facets['price_final']['label'] = t('Price');
    $facets['store:title']['label'] = t('Store');
    // etc...
  }

  return $facets;
}

I'm perfectly fine with this solution. (Flush cache to refresh tokens)

cpliakas’s picture

Thanks for posting!

Looking at your problem and solution, it could be a cool feature in a contrib module or in Facetapi Bonus to have a UI to modify some of the facet information as opposed to having to do it via code. Either way, great work and thanks for both the use case and solution.

Chris

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

better explanation

savel’s picture

Issue summary: View changes

Can't get to work #1 with latest version.

Instead I used custom_facetapi_facet_info_alter() and reduced the code to

function custom_facetapi_facet_info_alter(array &$facet_info, array $searcher_info){
  $facet_info['field_product:commerce_price:amount_decimal']['label'] = t('Price');
}