Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7933943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:29:06+00:00 2026-06-03T21:29:06+00:00

I am trying to display a list of categories with Translatable behavior. My default

  • 0

I am trying to display a list of categories with Translatable behavior.
My default locale is ‘fr’.

In my ‘ext_translations’ table, I have all records needed for locale ‘en’.

My controller :

    ....
    $this->get('session')->setLocale('en');
    $categories = $this->getDoctrine()->getRepository('MyBundle:Category')->findAll();
    ....

The problem is that when I display all retrieved categories, I get the ‘fr’ translations instead of the ‘en’.

I tried to display the $locale variable from my Category entity, and it is empty.

The only solution I have is to add this in my controller :

    ....
    $em = $this->getDoctrine()->getEntityManager();
    foreach($categories as $cat){
        $cat->setTranslatableLocale($this->get('session')->getLocale());
        $em->refresh($cat);
    }
    ....

But of course, it is not a good solution.

Any help ?
Why is the $locale variable of my entity empty ?

Thanks for your help,

Regards,

Aurel

EDIT

My Entity :

<?php

namespace Acme\MyBundle\Entity;

use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Translatable\Translatable;

/**
 * Acme\MyBundle\Entity\Category
 *
 * @ORM\Table(name="category")
 * @ORM\Entity(repositoryClass="Acme\MyBundle\Repository\CategoryRepository")
 */
class Category implements Translatable
{

    /**
     * @var smallint $id
     *
     * @ORM\Column(name="id", type="smallint", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var string $title
     *
     * @Gedmo\Translatable
     * @ORM\Column(name="title", type="string", length=255, nullable=false)
     */
    private $title;

    /**
     * @Gedmo\Locale
     * Used locale to override Translation listener`s locale
     * this is not a mapped field of entity metadata, just a simple property
     */
    private $locale;

    public function setTranslatableLocale($locale)
    {
        $this->locale = $locale;
    }

    public function getLocale(){
        return $this->locale;
    }

    /* ... all getters and setters ... */

    /**
     * Set title
     *
     * @param string $title
     */
    public function setTitle($title)
    {
        $this->title = $title;
    }

    /**
     * Get title
     *
     * @return string 
     */
    public function getTitle()
    {
        return $this->title;
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T21:29:07+00:00Added an answer on June 3, 2026 at 9:29 pm

    I found a solution, but it means that the StofDoctrineExtensionsBundle is not working properly.

    I had to edit my config.yml file to add the LocaleListener explicitly :

    my_translatable_locale_listener:
        class: Stof\DoctrineExtensionsBundle\EventListener\LocaleListener
        arguments: [@stof_doctrine_extensions.listener.translatable]
        tags:
            - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest }
    

    If somebody has a better solution…

    Aurel

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to display a list of items with their name and all categories
I'm trying to display a list of all events for a particular venue depending
I am just trying to display a list from an array that I have
Im trying to display two list: one for categories and brand but only the
I'm trying to display a list of all the Input Methods that are currently
I am trying to display a list of ALL users on a page. It
Basically what i am trying to do is display a list of categories. And
Trying to display a list filtered by the ‘term’ in autocomplete I have a
I am trying to display a list of cookbooks which have been tagged with
I'm trying to diplay list of data (categories) with jstl tag in a jsp

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.