Label translations are cached

Created on 28 May 2024, 7 months ago
Updated 31 July 2024, 5 months 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

Needs review

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.71.5 2024