3 namespace Drupal\locale\EventSubscriber;
5 use Drupal\Core\Cache\CacheTagsInvalidatorInterface;
6 use Drupal\locale\LocaleEvents;
7 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
10 * A subscriber invalidating cache tags when translating a string.
12 class LocaleTranslationCacheTag implements EventSubscriberInterface {
15 * The cache tags invalidator.
17 * @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface
19 protected $cacheTagsInvalidator;
22 * Constructs a LocaleTranslationCacheTag object.
24 * @param \Drupal\Core\Cache\CacheTagsInvalidatorInterface $cache_tags_invalidator
25 * The cache tags invalidator.
27 public function __construct(CacheTagsInvalidatorInterface $cache_tags_invalidator) {
28 $this->cacheTagsInvalidator = $cache_tags_invalidator;
32 * Invalidate cache tags whenever a string is translated.
34 public function saveTranslation() {
35 $this->cacheTagsInvalidator->invalidateTags(['rendered', 'locale']);
41 public static function getSubscribedEvents() {
42 $events[LocaleEvents::SAVE_TRANSLATION][] = ['saveTranslation'];