0
votes

I have such a link:

<?=$this->Html->link(__('Kontakt'), array('controller' => 'contacts', 'action' => 'show', 'language' => $this->Session->read('Config.language')));?>

My route looks like this:

Router::connect('/kontakt', array('controller' => 'contacts', 'action' => 'show', 'language' => 'deu'));

This way I get such a link in browser:

domain.com/kontakt (german is my base language)

Now I want the other languages as well, therefore I transport the language flag with the url in order to get this:

domain.com/eng/contact (all languages except german need this language shortcut)

I have this route

Router::connect('/:language/kontakt', array('controller' => 'contacts', 'action' => 'show'),

array( 'language' => 'eng|spa|fre|rus' ));

This creates my nicely urls like:

/spa/kontakt or /eng/kontakt or /fre/kontakt

I wonder now, how I can set the the translated words into the routes, without having a single line for each translation? Is there a way to make it somehow dynamic?

Thanks!

1

1 Answers

1
votes

Use the translation methods, just like in any other place:

Router::connect('/' . __d('routes', 'kontakt'), array('controller' => 'contacts', 'action' => 'show', 'language' => 'deu'));

The issue with that is that you don't set the language dynamically which will cause that the translation works but what ever "kontakt" will become is going to be routed to /deu/.

You must set the language dynamically to the route, not static as you do or you'll still have to add each language manually to the routes. If you prefer to do that I would check conditionally what language is active and load a separate route file depending on the language.