我使用了一个很好的捆绑Prezent,但他不想获得后备区域设置。所有配置都已注册,所有内容都在文档中example完成,但它不起作用。也许有人遇到过这个问题?
答案 0 :(得分: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中,我们从中继承要翻译的实体