1

On my Drupal 8 multilingual project, I have made a custom controller which create a basic page, but I can't figure out which parameter I must use in the routing. Is this _locale?

This is the definition of the route.

custom.route:
path: '{_locale}/portail'
defaults:
  _content: '\Drupal\my_module\Controller\DisplayController::display'
requirements:
_access: 'TRUE

This is the code I am using in the controller class.

public function display(Request $request, $locale) {
    var_dump($locale);die;
}
4

The language is detected and the prefix removed before routing. So you have a static route without parameter and in the controller you can get the prefix from the language manager:

  $langcode = $this->languageManager()->getCurrentLanguage()->getId();
  • 2
    Yes, this answers to both How do I define a route in a multi-lingual site? and How do I get the language set for a page returned from my controller? – kiamlaluno Dec 26 '17 at 10:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.