shopware – How to localize routes of a custom controller in shopware6 – Code Utility


I’m following the guides of creating an custom controller.

It works fine so far, but how do I localize a path to the controller?
I peeked into the symfony documentation about routing and found the solution by Annotation
But this doesn’t work. No mater how I formated my language string.

     * @Route({
     *     "en-GB": "/joe",
     *     "de-DE": "/peter",
     *     "en-GB": "/joe",
     *     "de-DE": "/peter",
     *     "en": "/joe",
     *     "de": "/peter"
     * }, name="frontend.example.example", methods={"GET"})


I believe this is not recommended in the way you are trying it.

Shopware can be configured in all kind of languages by the store owner. So it would not make sense to just hard code German and English language by in the code.

Instead, I suggest to write a custom router which picks up the route name from a plugin configuration, which then should allow to set the route name per language with a translatable entity. This is similar how products work: The store owner can configure a product in German as “Kissen” and English and “Pillow” and so the localized routes will work.