2014-12-09 70 views

回答

0

解决! 相反的:

/** 
* Translation helper method 
*/ 
public function translate($locale = null) 
{ 
    if (null === $locale) { 
     $locale = $this->currentLocale; 
    } 

    if (!$locale) { 
     throw new \RuntimeException('No locale has been set and currentLocale is empty'); 
    } 

    if ($this->currentTranslation && $this->currentTranslation->getLocale() === $locale) { 
     return $this->currentTranslation; 
    } 

    if (!$translation = $this->translations->get($locale)) { 
     $className = $this->getTranslationEntityClass(); 
     $translation = new $className; 
     $translation->setLocale($locale); 
     $this->addTranslation($translation); 
    } 

    $this->currentTranslation = $translation; 
    return $translation; 
} 

的用途必须退区域:

/** 
* Translation helper method that uses a fallback locale 
*/ 
public function translate($locale = null) 
{ 
    if (null === $locale) { 
     $locale = $this->currentLocale; 
    } 

    if (!$locale) { 
     throw new \RuntimeException('No locale has been set and currentLocale is empty'); 
    } 

    if ($this->currentTranslation && $this->currentTranslation->getLocale() === $locale) { 
     return $this->currentTranslation; 
    } 

    if (!$translation = $this->translations->get($locale)) { 
     if (!$translation = $this->translations->get($this->fallbackLocale)) { 
      throw new \RuntimeException('No translation in current or fallback locale'); 
     } 
    } 

    $this->currentTranslation = $translation; 

    return $translation; 
} 
在TranslatableEntity.php

从中继承实体被翻译