1

The only way to have the taxonomy term name in the title of a taxonomy term Commerce Products view page I've found so far is the example view in the estore theme (I still don't get how tid which should stand for Term ID becomes the title field value):

screenshot of the View > Advanced settings

screenshot of contextual filter: Taxonomy term: Term ID

The problem is that the title shown is not translated on multilingual sites when the term definitely has a proper translation. Is there any way to show that title translated?

For some reason there are no Product: Has taxonomy term ID as there is Content: Has taxonomy term ID in the default taxonomy term view that is displaying the title translated.

AFAIU {{ arguments.tid|t }} is not the way because it will go through a different subsystem.

0

I had to workaround it in code by modifying an example posted by djg_tram:

/**
 * @file
 * Workaround for taxonomy term title not being i18zed.
 */
use Drupal\views\ViewExecutable;
use Drupal\taxonomy\Entity\Term;

/**
 * Implements hook_views_pre_render().
 */
function exposed_filter_workaround_views_pre_render(ViewExecutable $view) {
  $view_id = 'products';
  $view_display = 'page_category';

  if ($view->id() == $view_id && $view->current_display == $view_display) {
    $lang_id = \Drupal::languageManager()->getCurrentLanguage()->getId();

    $term_id = $view->args[0];
    $term = Term::load($term_id);

    $term_translated = $term->getTranslation($lang_id);
    $view->setTitle($term_translated->label());
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.