-
Notifications
You must be signed in to change notification settings - Fork 380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
slug not translated #276
Comments
anyone have an idea ? |
I have the same problem. Although I didn't change any listeners cause as I see in #232 it should work right away. I have just added the code in YML:
As I understand it should work, but it doesn't. I have 4 translatable fields, all of them are translated except slug. Any idea what should I do? |
You can change to another translation bundle? |
Which one? |
I use the a2lixI18nDoctrine bundle, i find it easier to use, but you'll have to create your own function in order to create a slug, with a @PrePersist annotation it is very simple |
I have searched and tried a while and found a solution for me: Entity: the slug field gets generated from the name field use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\Translatable\Translatable;
/**
* @var string
*
* @Gedmo\Translatable
* @ORM\Column(name="name", type="string", length=150, unique=true)
*/
private $name;
/**
* @Gedmo\Translatable
* @Gedmo\Slug(fields={"name"}, updatable=true)
* @ORM\Column(type="string", unique=true)
*/
private $slug; config.yml: here you have to set parameters:
locale: en
doctrine:
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
gedmo_translatable:
type: annotation
prefix: Gedmo\Translatable\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity"
alias: GedmoTranslatable # (optional) it will default to the name set for the mapping
is_bundle: false
gedmo_translator:
type: annotation
prefix: Gedmo\Translator\Entity
dir: "%kernel.root_dir%/../vendor/gedmo/doctrine-extensions/lib/Gedmo/Translator/Entity"
alias: GedmoTranslator # (optional) it will default to the name set for the mapping
is_bundle: false
stof_doctrine_extensions:
default_locale: '%locale%'
translation_fallback: true
persist_default_translation: true # I think this does the trick
orm:
default:
sluggable: true
translatable: true DefaultController: use use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
/**
* @Route("/entry/{slug}", name="entry_detail")
* @ParamConverter("entry", class="AppBundle:Entry", options={"repository_method" = "findOneByCriteria"})
*/
public function entryDetailAction(Request $request, Entry $entry)
{
return $this->render('frontend/entry.html.twig', [
'entry' => $entry,
]);
} Entity Repository: with the query method to return entity /**
* Find an entry by criteria
* Need this special function, because of translatable
* https://github.com/stof/StofDoctrineExtensionsBundle/issues/232
*
* @param $params
* @return mixed
*/
public function findOneByCriteria(array $params)
{
$query = $this->createQueryBuilder('e');
$i = 0;
foreach ($params as $column => $value) {
if ($i < 1) {
$query->where("e.$column = :$column");
} else {
$query->andWhere("e.$column = :$column");
}
$query->setParameter($column, $value);
$i++;
}
$query = $query->getQuery();
$query->setHint(\Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER, 'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker');
return $query->getOneOrNullResult();
} I hope this example helps someone. |
Still not working today |
I'm a bit confused by this problem. However, I'm now trying to implement it on Symfony 6, without success. The problem seems to be that the SluggableListener doesn't detect any change in the translated field on which the slug depends. Example:
Here, slug won't be translated even if we translate the "name" field because SluggableListener doesn't see it in its changeset fetching (generateSlug function).
For the moment, I'm proposing a not-so-pretty hack:
In a entity using Timestampable, it will translate and update the slug.. |
hi, Has anyone managed to get it working with symfony 6? Thank you |
Hi,
I am using the stofDoctrineExtensionsBundle in order to use the slug and translatable behavior, but i'am encountering issues about the slug translation, i need my slug to be translated for each title of my entity
my title is translated but the slug only use the default locale and is not translated
here is my yamel file service configuration
i put the translatableListener after the sluggableListener
in the documentation i can find this block
but i clearly have no idea where to put this code, the translatable listener isn't already added to the event manager through the doctrine-extensions.yml file ?
I am using a personnalAbstractTranslation
The text was updated successfully, but these errors were encountered: