Here are the crucial fragments. As you can see, the use of three
letter and two letter language codes is confusing, more so because
catalan doesn't seem to have a xx_xx code.
I hope you can understand the following. I've included my version of
p28n.php because I think I might have made some changes to it.
In locale, the folder names for each language use th three letter
code, e.g. spa & cat
In config/routes.php:
//route to switch locale
Router::connect('/lang/*', array('controller' => 'p28n', 'action' =>
'change'));
//forgiving routes that allow users to change the lang of any page
Router::connect('/eng?/*', array(
'controller' => "p28n",
'action' => "shuntRequest",
'lang' => 'en-gb'
));
Router::connect('/ca?/*', array(
'controller' => "p28n",
'action' => "shuntRequest",
'lang' => 'cat'
));
Router::connect('/es?/*', array(
'controller' => "p28n",
'action' => "shuntRequest",
'lang' => 'es_es'
));
In app_controller.php:
var $components = array('P28n');
In views/layouts/default.ctp:
<?php
$currLang = Configure::read('Config.language');
if ($currLang<>"ca" && $currLang<>"spa")
{
$currLang = "ca";
Configure::write('Config.language',$currLang);
}
?>
<li><?php echo ($currLang<>"ca") ? '<a href="'.router::url("/").'lang/
ca">Català</a>' : 'Català' ; ?></li>
<li><?php echo ($currLang<>"spa") ? '<a href="'.router::url("/").'lang/
spa">Castellano</a>' : 'Castellano' ; ?></li>
controllers/components/p28n.php:
<?php
class P28nComponent extends Object
{
var $components = array('Session', 'Cookie');
function startup()
{
if (!$this->Session->check('Config.language'))
{
$this->change(($this->Cookie->read('lang') ? $this->Cookie-
>read('lang') : 'cat'));
}
}
function change($lang = null)
{
if (!empty($lang))
{
$this->Session->write('Config.language', $lang);
$this->Cookie->write('lang', $lang, null, '+350 day');
}
}
}
?>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---
No comments:
Post a Comment