Multilingual pattern in route

How can we match the localized URL of 1 single page (in different languages) in 1 route as pattern?
E.g. I would like to act on the page “/en/detailpage”, “/nl/detailpagina”, “/de/detailseite” & “/fr/page-de-detail”. How do I get this into the “pattern” part of the route?

c::set('routes', array(
  array(
    'pattern' => '??????????????????????',
    'action'  => function() {
      // do something here when the URL matches the pattern above
      // and the specified request method
    },
    'method' => 'GET|POST|DELETE'
  )
));

I would like to avoid having a different route for each language with the same “action” into it…

Thanks!

You should be able to do:

c::set('routes', array(
  array(
    'pattern' => [
      '(:any)/detailpage',
      '(:any)/detailpagina',
      '(:any)/detailseite',
      '(:any)/page-de-detail'
    ],
    'action'  => function($language) {
      // do something here when the URL matches the pattern above
      // and the specified request method
    },
    'method' => 'GET|POST|DELETE'
  )
));

or

c::set('routes', array(
  array(
    'pattern' => '(:any)/(detailpage|detailpagina|detailseite|page-de-detail)',
    'action'  => function($language, $id) {
      // do something here when the URL matches the pattern above
      // and the specified request method
    },
    'method' => 'GET|POST|DELETE'
  )
));
2 Likes

This is gold (and belongs in the docs).

Thanks for the fast reply, @bastianallgeier

I’ve created an issue and will add this to the docs asap.

1 Like