Last Updated: February 25, 2016
·
2.078K
· my3recipes

CakePHP multilingual route

If you're working on multilingual CakePHP app, you will need to create multilingual routes. Most common case is to have these urls:

www.example.com/en/demo
www.example.com/de/demo

So, our app will have first param (en, de & etc) for selecting language. Open /app/Config/routes.php and add:

Router::connect('/:i10n/:controller', array('action' => 'index'), array('i10n' => '[a-z]{2}'));
Router::connect('/:i10n/:controller/:action/*', array(), array('i10n' => '[a-z]{2}'));

Reg expression array('i10n' => '[a-z]{2}') defines that language code should be any two lowercase letters.
It's a very basic example, but will show you have route works.

1 Response
Add your response

You might even define only some languages to match:
Router::connect('/:i10n/:controller/:action/*', array(), array('i10n' => 'en|de|it|es'));
In this way you could use another 2char string to match another rule (ex: /up/files)

over 1 year ago ·