Label translations are cached

Created on 28 May 2024, about 1 month ago
Updated 27 June 2024, about 23 hours ago

Problem/Motivation

On my multilingual site, I have translated facet labels into different languages. However, the labels shown in the frontend are in the interface language of the last cache flush. The issue appears to be that in the 'FacetBlockDeriver', the 'admin_label' is cached for all languages and it is set with the facet label in the current language:

'admin_label' => $facet->getName(),

Steps to reproduce

  1. Set up a multilingual site with facets in facets_block.
  2. Translate the facet labels.
  3. Enable 'Show Facet titles' in the FacetsBlock configuration.

Proposed resolution

I was able to fix the issue by using 'hook_facets_block_facets_alter':

function hook_facets_block_facets_alter(&$facets) {
foreach ($facets as &$facet_block) {
    $facet = \Drupal::entityTypeManager()->getStorage('facets_facet')->load($facet_block['#block_plugin']->getDerivativeId());
    if ($facet) {
      $facet_block['title'] = $facet->getName();
    }
  }
}

Additionally, I provided a patch to fix the issue.

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany Ayrmax

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.69.0 2024