Ejemplo n.º 1
0
 /**
  * @param $key
  * @param $locale
  * @param string $default
  * @param string $defaultLocale
  * @return Entity\Translation|mixed|object
  */
 private function getTranslationEntity($key, $locale, $default = '', $defaultLocale = 'en_US')
 {
     $translationString = empty($default) ? $key : $default;
     $translation = $this->db->getRepository('\\Fraym\\Translation\\Entity\\Translation')->findOneByKey($key);
     if (null === $translation) {
         return $this->createTranslation($key, $translationString, $locale, $defaultLocale);
     }
     $repository = $this->db->getRepository('Gedmo\\Translatable\\Entity\\Translation');
     $translations = $repository->findTranslations($translation);
     if (isset($translations[$locale])) {
         return (object) $translations[$locale];
     } elseif ($this->locale->getLocale()->locale == $locale) {
         $translation->locale = $locale;
         $this->db->refresh($translation);
         $this->db->clear();
         return $translation;
     } else {
         return $this->updateTranslationLocales($translation, $translationString, $locale, $defaultLocale);
     }
     return (object) $translations[$locale];
 }