2

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 ?!

Stephan Vierkant
  • 9,674
  • 8
  • 61
  • 97
NewCod3r
  • 1,168
  • 1
  • 12
  • 28

1 Answers1

3

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

Dylan Delobel
  • 786
  • 10
  • 26
  • @I work Only with routing components in personal project(without full symfony framwork). your methods work with Symfony structure and full framework(ie annotations / config / ...) – NewCod3r Jun 12 '19 at 08:57