I am using language prefix in my app:
Router::connect('/:language/:controller/:action/*',
array(),
array('language' => '[a-z]{3}'));
When I use $this->Html->link('title',$url_array) I have to set the language prefix manually.
And what I want is when the prefix is present in current url then when I use ->link(...) it should add this prefix automaticly to url. Only when I set this prefix explicite then it should be different.
Is it possible?
If you want to manage your locale application wide (not per user) you should check what the current locale setting is in the URL in your AppController’s beforeFilter(). The :language prefix in your
Routerwill ensure that you provide unique URLs for differently localized content.$this->Html->link()will act as you expect if the Config.language configuration setting is managed in the right manner.So in your
AppController::beforeFilter()make an if() statement to detect which locale is being requested and depending on that do:or
Doing this will ensure that both I18n and TranslateBehavior access the same language value.
If you would like to manage application locale per user you can store the current locale in the Session:
Of course you should also use the Translation Function __(). Check out the Internationalization and Localization section of the Cake Book.
Oh yeah, there is also something very important which is mentioned in the “fine print” of that article: