My site has english and spanish content. If the user chooses to read the spanish content, then the urls are like www.exampleweb.com/es/contenido, and if the user chooses to read the english content, then the url has to be like www.exampleweb.com/en/content.
I already managed to change between the "es" and "en", but i cant change the word "contenido" for "content.
Create a bahavior and put inside the components folder.
components/applicationBehavior.php
<?php
class applicationBehavior extends CBehavior
{ private $_owner;
public function events()
{
return array(
'onBeginRequest'=>'addRule',
);
}
public function addRule()
{
$owner=$this->_owner=$this->getOwner();
if($owner->language=='en_us')
{
$owner->urlManager->addRules(array(
//declare rules for english
));
}
if($owner->language=='sp') // I assumed it.
{
$owner->urlManager->addRules(array(
//declare rules for spanish
));
}
}
}
Attach this behavior as a property to main configuration file.
My friend, thank you for your time. Your solution doesnt work dinamically. The custom behavior is not checking which is the current language that the user selected, instead uses the language that is set statically in the main.php:
<?php
class applicationBehavior extends CBehavior
{ private $_owner;
public function events()
{
return array(
'onBeginRequest'=>'addRule',
);
}
public function addRule()
{
$owner=$this->_owner=$this->getOwner();
if(something is true) //Add the logic here by which you are assigning the laguage .
$owner->language='en_us';
if($owner->language=='en_us')
{
$owner->urlManager->addRules(array(
//declare rules for english
));
}
if($owner->language=='es')
{
$owner->urlManager->addRules(array(
//declare rules for spanish
));
}
}
}
Would you please share the means by which you are assigning language with us.