我使用了一个很好的捆绑包Prezent,但他不想获得回退语言环境。所有配置都已注册,例如在文档中完成所有操作,但它不起作用。也许有人遇到过这个问题?
解决了!而不是:
/**
* 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;
}
在可翻译实体中.php我们从中继承要翻译的实体