You can add a backend class for the block, then add a cache context on language to that block.
First, you need to get the config key for the view block. I believe it is views.view.[BLOCK_ID]
. You can get the block ID in the advanced section of the view.
Next, you add a custom class to the block. Here is how that is done for the system branding block.
/**
* Implements hook_block_alter().
*
* Changes the class for the system branding block to add a cache
* context for language.
*/
function [MODULE]_block_alter(array &$definitions) {
// Set custom callback for system menu block
$definitions['system_branding_block']['class'] = 'Drupal\[MODULE]\Plugin\Block\SystemBrandingBlockOverride';
}
Then you can add a cache context on language to in the class:
namespace Drupal\[MODULE]\Plugin\Block;
use Drupal\system\Plugin\Block\SystemBrandingBlock;
/**
* Adds group caching to the system branding block.
*/
class SystemBrandingBlockOverride extends SystemBrandingBlock {
/**
* {@inheritdoc}
*/
public function getCacheContexts() {
$contexts = parent::getCacheContexts();
$contexts[] = 'languages';
return $contexts;
}
}
Note that you may want to use one one of the following cache contexts instead:
languages:language_interface
languages:language_content