Skip to content
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

The first translation on the child item will be translated to the fallback language #766

Open
Sentence opened this issue Jun 7, 2024 · 5 comments

Comments

@Sentence
Copy link

Sentence commented Jun 7, 2024

When listing an entity's childs, the first translation on the child item will be translated to the fallback language, the 2nd and 3rd in the list is using the current locale correctly.

Eg. the first one will be the fallback language, the rest will be the current locale:
{% for item in list %} {{ item.country.name }}<br/> {% endfor %}

If forcing the translation to the currenct locale with .translate(app.request.locale) it works

I'm using this bundle for 4-5 years now but got this issue twice only in many projects.

Any tips or suggestions?

@SVillette
Copy link

Same issue here, after some investigations, it seems to be linked to doctrine.orm.enable_lazy_ghost_objects: true.

@Sentence
Copy link
Author

Yep, if i set it to false, it works, thanks a lot for the tip!

@SVillette
Copy link

Still an issue as setting this parameter to false is deprecated

@Sentence
Copy link
Author

Sadly yes, but i'm using it currently in a Symfony 6.4.8 project (i'm trying to avoid 7 'til i can, since older/smaller bundles can conflict like this issue)

bobvandevijver added a commit to bobvandevijver/DoctrineBehaviors that referenced this issue Jun 11, 2024
@bobvandevijver
Copy link
Contributor

We hit this as well, but as we use our own translatable trait, it was easily fixable without submitting it here. The only thing you need is to override the getCurrentLocale and getDefaultLocale methods, and add the following:

    if ($this instanceof Proxy && !$this->__isInitialized()) {
        $this->__load();
    }

The issue is that non-mapped properties ($currentLocale and $defaultLocale) are marked as excluded by the lazy ghost as they are not mapped. Hitting these properties therefor no longer triggers database hydration, which causes the load event handler to not be run for the translatable if it wasn't fully loaded. Calling the load manually will trigger hydration and the load event listener, initialising these properties correctly.

I have created a PR as well: #767

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants