Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

Adding custom routes for each language #18

Closed
formulaclick opened this issue Sep 19, 2012 · 8 comments
Closed

Adding custom routes for each language #18

formulaclick opened this issue Sep 19, 2012 · 8 comments

Comments

@formulaclick
Copy link

I want to add some custom routes for each language. Example:

App::uses('I18nRoute', 'Lang.Routing/Route');
Router::defaultRouteClass('I18nRoute');

Router::connect('/english-page', array('lang'=>'eng', 'controller' => 'pages', 'action' => 'display', 'my_page'));
Router::connect('/spanish-page', array('lang'=>'spa', 'controller' => 'pages', 'action' => 'display', 'my_page'));

But it doesn't work. Is it a bug? Or how should I do to get this working?

@formulaclick
Copy link
Author

Nobody knows how to get this? :-(

@burzum
Copy link
Contributor

burzum commented Oct 15, 2012

What exactly is not working? What is expected? Can you provide a unit test?

@formulaclick
Copy link
Author

I'll give a clearer example:

I want http://www.example.com/posts to be parsed as array('lang'=>'eng', 'controller' => 'posts', 'action' => 'index')
and http://www.example.com/noticias to be parsed as array('lang'=>'spa', 'controller' => 'posts', 'action' => 'index')

I have the following code but it doesn't work:

App::uses('I18nRoute', 'Lang.Routing/Route');
Router::defaultRouteClass('I18nRoute');

Router::connect('/posts', array('lang'=>'eng', 'controller' => 'posts', 'action' => 'index'));
Router::connect('/noticias', array('lang'=>'spa', 'controller' => 'posts', 'action' => 'index'));

Any idea?

@burzum
Copy link
Contributor

burzum commented Oct 17, 2012

This App::uses('I18nRoute', 'Lang.Routing/Route'); should be App::uses('I18nRoute', 'I18n.Routing/Route');

@formulaclick
Copy link
Author

Sorry, in my example I located the file in a different Plugin name, but the problem is the same. Actually the plugin work fine, if I have "Router::connect('/posts', array('controller' => 'posts', 'action' => 'index'));" and I load http://www.example.com/spa/posts in my browser it works fine. The only thing I'like to implement is instead of http://www.example.com/spa/posts to be able to convert it in http://www.example.com/noticias with routing rules:

I want http://www.example.com/posts to be parsed as array('lang'=>'eng', 'controller' => 'posts', 'action' => 'index')
and http://www.example.com/noticias to be parsed as array('lang'=>'spa', 'controller' => 'posts', 'action' => 'index')

Is this the correct way??

Thank you

@lorenzo
Copy link
Contributor

lorenzo commented Oct 17, 2012

No, this plugin is for automatically setting the language for page contents, not for translating the url

@burzum
Copy link
Contributor

burzum commented Oct 17, 2012

@igurpi You do not even have to use the I18n route class for that, using the default route class for this works fine, I've just tried it in a unit test and it worked.

@lorenzo thanks I've added this sentence to the readme.md :) 0d66524

@burzum burzum closed this as completed Oct 17, 2012
@formulaclick
Copy link
Author

@burzum could you put an example? I tried also with the default route class with no success...
Thank you

rickydunlop pushed a commit to rehabstudio/i18n that referenced this issue Mar 3, 2014
… setting the language based on the url NOT for translating the url itself to something. This is related to CakeDC#18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants