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

[Translatable] Detached required method. Interface design. #2862

Open
fabpico opened this issue Aug 30, 2024 · 2 comments
Open

[Translatable] Detached required method. Interface design. #2862

fabpico opened this issue Aug 30, 2024 · 2 comments

Comments

@fabpico
Copy link

fabpico commented Aug 30, 2024

I was following the example and wondered why my IDE did not have any reference of the method setTranslatableLocale, I expected it to be declared in Gedmo\Translatable\Translatable. Indeed, the interface is empty and says // use now annotations instead of predefined methods, this interface is not necessary.

I find the interface and method definition necessary, because I don't want to have methods in my code which are required for a 3rd-party package, but have no contact the that package.

I find, the Idea to have the translatable feature is to have at minimum 2 languages, to translate from one to another language. Because of that, I find it unnecessary to fall back to a default locale when not using setTranslatableLocale (example), because we normally want to translate something, so we need the method anyway.

My suggestion is to add setTranslatableLocale to Gedmo\Translatable\Translatable.

@mbabker
Copy link
Contributor

mbabker commented Aug 30, 2024

Each of the extensions has marker interfaces to identify objects in your application that use a feature, but it's not a requirement for your application to use any of those interfaces. Aside from some union object|MarkerInterfaces types in doc blocks, those marker interfaces are unused. Most of how this library works actually comes from the extended mapping metadata (be it annotations, attributes, or XML) and using that to handle things at runtime (looking at that example, the Article::setTranslatableLocale() method is really there for your application's use, but the library is going to use whatever field you've got the #[Gedmo\Locale] attribute set to when it needs to grab that value).

You're welcome to design interfaces for your own application's use that suit your needs, but changing those marker interfaces to have a required implementation would be a major design change in how this library is used.

@fabpico
Copy link
Author

fabpico commented Sep 2, 2024

@mbabker Indeed I already noticed that it works without implementing Gedmo\Translatable\Translatable to the entity, by only using attributes. But the example in the main branch is implementing the interface.

In that case may I suggest to let cleanup the example to leave out implements Translatable? This would have saved me experimentation and testing time.
(Of course maybe most people don't bother having extra boilerplate code which is not needed, but for those who want clean code, it would be nice.)

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

2 participants