2
votes

I work Only with symfony routing components in personal project(without full symfony framwork). my method is: add route in routes.yaml file like this:

index:
    path:     /test
    methods: GET
    controller: 'App\Catalog\Controller\Home\IndexController::index'

register:
    path:     /test/account/register
    methods: GET
    controller: 'App\Catalog\Controller\Account\RegisterController::index'

my routing work fine But I need to add automatic locale prefix in uri/routing for multi language system like this:

mydomain/test    //for default language ie: en
mydomain/test/fr
mydomain/test/de
mydomain/test/account/register      //for default language ie:en
mydomain/test/fr/account/register
mydomain/test/de/account/register

How do add locale prefix in routes.yaml file and remove default locale prefix language ?!

1

1 Answers

2
votes

If your Application is up-to-date you can use Internationalized routing introduced in 4.1 like this

# config/routes/annotations.yaml
controllers:
    resource: '../../src/Controller/'
    type: annotation
    prefix:
        en: '' # don't prefix URLs for English, the default locale
        fr: '/fr'
        de: '/de'

Otherwise, you can reference another routing.yml file with prefix option like this

# config/routing.yml

french_route:
    resource: "french_routing.yml"
    prefix:   /fr

deutch_route:
    resource: "deutch_routing.yml"
    prefix:   /de

You can separate languages with files, and each one will come automatically with his own prefix