PrezentDoctrineTranshableBundle без резервной локали

0

Я использую хороший пакет Prezent, но он не хочет возвращаться в локау. Все конфиги зарегистрированы, все делается, например, в документации, но это не работает. Может быть, кто-то столкнулся с этой проблемой?

Теги:
multilanguage

1 ответ

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, из которого мы наследуем объект, который нужно перевести

Ещё вопросы

Сообщество Overcoder
Наверх
Меню