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

Allow translations in resource bundle #2405

Merged
merged 1 commit into from
Jan 29, 2015
Merged

Allow translations in resource bundle #2405

merged 1 commit into from
Jan 29, 2015

Conversation

gonzalovilaseca
Copy link
Contributor

With this small refactorization it's possible to create a translatable resource entity, eg:

sylius_resource:
        size:
            driver: doctrine/orm
            classes:
                model: MyBundle\ProductBundle\Entity\Size
                repository: Sylius\Bundle\ResourceBundle\Doctrine\ORM\TranslatableEntityRepository
                translatable:
                    targetEntity: MyBundle\ProductBundle\Entity\SizeTranslation
                    translatable_fields:
                        - presentation
        size_translation:
            driver: doctrine/orm
            classes:
                model: MyBundle\ProductBundle\Entity\SizeTranslation

It would be great to have the translatable repo mapped by default, but that will be in another PR.

pjedrzejewski pushed a commit that referenced this pull request Jan 29, 2015
…ource-bundle

Allow translations in resource bundle
@pjedrzejewski pjedrzejewski merged commit 4ef441d into Sylius:master Jan 29, 2015
@pjedrzejewski
Copy link
Member

Thanks Gonzalo! 👍

@@ -16,14 +16,15 @@
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Sylius\Bundle\TranslationBundle\DependencyInjection\AbstractTranslationExtension;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong IMO as it adds (missing anyway) dependency for ResourceBundle on the TranslationBundle...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stloyd What do you mean? I don't see why this is adding a dependency of ResourceBundle on TranslationBundle.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using class from another bundle is the additional dependency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I thought you meant that the dependency was the other way round.
If we allow translations in the resource bundle it's normal to have a dependency on that bundle.

@pjedrzejewski
Copy link
Member

I am thinking if we really need Transltion and TranslationBundle, maybe add translations support to Sylius resource directly. What do you think guys? @stloyd @gonzalovilaseca @Sylius/core-team

@gonzalovilaseca
Copy link
Contributor Author

@pjedrzejewski At some point I thought that too. Let's see what others say. The integration would be quite easy.

@pjedrzejewski
Copy link
Member

Yes, also, would be cool if we can move the translation resource creation to the translatable node directly. So instead of:

sylius_resource:
    resources:
        app.book:
            driver: doctrine/orm
            classes:
                model: App\Entity\Book
                translatable:
                    model: App\Entity\BookTranslation
        app.book_translation:
            driver: doctrine/orm
            classes:
                model: App\Entity\BookTranslation

We can have:

sylius_resource:
    resources:
        app.book:
            driver: doctrine/orm
            classes:
                model: App\Entity\Book
                translatation:
                    model: App\Entity\BookTranslation
                    repository: # And other configurations.

I think that should be quite simple to do. Basically: translation node under classes registers another resources with name X_translation. :)

Same for bundle configs of course.

@gonzalovilaseca
Copy link
Contributor Author

@pjedrzejewski In fact, while refactoring the bundle I started to do it that way, but then I realised that any configuration that might be added in the future to the classes array node should be added to the new translation node too. I saw a bit of code duplication there that's why I went back and left it as it is now.
I also considered this approach too:

sylius_resource:
    resources:
        app.book:
            driver: doctrine/orm
            classes:
                model: App\Entity\Book
                translatation: app.book_translation

        app.book_translation:
            driver: doctrine/orm
            classes:
                    model: App\Entity\BookTranslation
                    repository: # And other configurations.

But with this approach I had issues in the case where app.book_translation was defined in another bundle whose configuration might not have been loaded yet, but I can have a look again, I'm sure there are workarounds.

First option is easier, but as I said, configuration nodes will need to be duplicated.

@pjedrzejewski
Copy link
Member

I'd say I am fine with the little duplication here, we can look at it later, when we perhaps add something more than translation. log could work in a similar way, right now we have a bit hacky handling of entity history. :)

pamil pushed a commit to pamil/Sylius that referenced this pull request May 7, 2019
…or-resource-bundle

Allow translations in resource bundle
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

Successfully merging this pull request may close these issues.

6 participants