-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
[Trans] Auto trans on devs content should not be a thing #153
Comments
I find it disturbing to use the translator in the backend, even though this is a frontend centric piece of the backend. For myself I don't see an issue when Symfony warns about missing translations. But I don't know, if there are any official best practice for such cases in bundles. |
This is not a missing translation error.
How? $builder
->add('nom', TextType::class, [
'label' => $this->getTranslator()->trans('label.name'),
])
->add('statut', EnumType::class, [
'label' => $this->getTranslator()->trans('label.status'),
'class' => DocumentStatutEnum::class,
'choice_label' => fn(DocumentStatutEnum $statut) => $statut->trans($this->getTranslator()),
])
; enum DocumentStatutEnum: string implements TranslatableInterface
{
case Nouveau = 'nouveau';
case Brouillon = 'brouillon';
case EnCours = 'en_cours';
case Valide = 'valide';
case Refuse = 'refuse';
public function trans(TranslatorInterface $translator, string $locale = null): string
{
return match ($this) {
self::Nouveau => $translator->trans('label.new', locale: $locale),
self::Brouillon => $translator->trans('label.draft', locale: $locale),
self::EnCours => $translator->trans('label.in_progress', locale: $locale),
self::Valide => $translator->trans('label.valid', locale: $locale),
self::Refuse => $translator->trans('label.refused', locale: $locale),
};
}
}
There's no best practice about that. But I know it is not a good practice to try to translate dynamically a variable, even in twig than PHP back-end.
As I said before, it's a big nono for me. $changePassword = new MenuItemModel(
'change_password',
'action.edit_profile', // <----- That will not be detected
'user_edit',
['user_uuid' => $user->getUuid()]
);
I'd rather have something not happen because I'm not using it properly.
Than something that is being done by someone/something else and I can't do anything about it.
|
There is a lot of data that cannot be translated, e.g. Cities, Numbers ... but that is not the point, right? I see what you are saying. It works very well for me since years, but that doesn't mean it is the correct way. Just changing it will cause massive BC breaks (at least in my projects), so please propose a way forward that is BC safe. My project uses plugins from third party developers and I am not able to simply rip that feature out. |
TRUE! Some data can be translated and some can't.
Also true, unfortunately 😞 |
You know the AdminLTE Bundle, right?! It has the same logic and it was used and installed (and still is) a couple of times every day: https://packagist.org/packages/kevinpapst/adminlte-bundle/stats
... I don't like these "there is only one correct way to do it and it's mine" expressions 😁 I am a fan of having all translation calls in the frontend, but then I never used that translation command as well 🤷 so that's probably why I never really thought about it twice. But I do accept your arguments and that's why we should concentrate on finding a way forward: What about add a new flag (isTranslated = false) to the MenuItem class and check that in the template when displaying the label? If That could work? At some point in the future we need to remove that extra flag |
I am not here to impose my wishes / my needs. In my company, we have some tests to make sure there's no missing translation. ATE, we strictly do not use variable with
Sounds good to me 👍 |
Sounds like a good approach! I'll play with that as well and see how I like it. And don't hesitate to change the Menu Interface if necessary (like I recently did). This is also a BC break, but a "minor" one that is identifiable and fixable in 5 minutes. And I do not expect that many users implement their own MenuItemModel. |
i'am also working with a UserDetailsSubscriber and for example also spotted that there |
@akkushopJK Pass a translated param to the From this: $changePassword = new MenuItemModel(
'change_password',
'action.edit_profile', // <----- That will not be detected
'user_edit',
['user_uuid' => $user->getUuid()]
); To this: $changePassword = new MenuItemModel(
'change_password',
$this->translator->trans('action.edit_profile'), // <----- HERE
'user_edit',
['user_uuid' => $user->getUuid()]
); You will get a warning from Symfony that you are translating something that has already been translated. |
I am fine with adapting the logic, but someone needs to do this change and we should do it in a new branch for the 1.0 bump. |
I'm currently experiencing some translation errors when using the menu and navbar.
What I got
From a subscriber, I implement some items to the menu.
These items have labels that are already translated inside the subscriber.
What TablerBundle does
When TablerBundle print the twig result of the menu item, it tries to trans a content that is already translated.
Like
{{ 'Modifier mon profil'|trans }}
.What is the problem?
Because of this, Symfony tells me that I have missing/wrong translations.
What is the solution?
trans domain
to any trans function/filter that the bundle uses❌ I don't think this is a good idea:
bin/console translation:extract
(huge nono for me)Only word/phrase that we define in the bundle.
✔️ Rude, but I'll take it!
The text was updated successfully, but these errors were encountered: