/** * Set translation * * @param string $entityType Type of entity * @param string $entityId Id of entity * @param string $entityField Field of entity * @param string $translationValue Translated value * @param string $locale Locale * * @return $this Self object */ public function setTranslation($entityType, $entityId, $entityField, $translationValue, $locale) { $translation = $this->entityTranslationRepository->findOneBy(['entityType' => $entityType, 'entityId' => $entityId, 'entityField' => $entityField, 'locale' => $locale]); if (!$translation instanceof EntityTranslationInterface) { $translation = $this->entityTranslationFactory->create()->setEntityType($entityType)->setEntityId($entityId)->setEntityField($entityField)->setLocale($locale); $this->entityTranslationObjectManager->persist($translation); } $translation->setTranslation($translationValue); $this->translationsToBeFlushed[] = $translation; return $this; }
/** * Warm-up translations * * @return $this Self object */ public function warmUp() { $translations = $this->entityTranslationRepository->findAll(); /** * @var EntityTranslationInterface $translation */ foreach ($translations as $translation) { $cacheKey = $this->buildKey($translation->getEntityType(), $translation->getEntityId(), $translation->getEntityField(), $translation->getLocale()); $this->cache->save($cacheKey, $translation->getTranslation()); } return $this; }