language as part of the url

29 views
Skip to first unread message

chem

unread,
Jul 14, 2011, 4:58:19 AM7/14/11
to limo...@googlegroups.com
Hello,

if i want the language selection as part of the url, like "www.homepage.com/en/contact" what is the best
way to do so?  

best regards

Chem

Fabrice Luraine

unread,
Jul 14, 2011, 11:30:00 AM7/14/11
to Limonade
Hello,

you can manage it in directly in your routes

## Detect language in routes

dispatch('/:locale/contact', 'contact');

function contact($locale)
{
# Check if $locale is part of the available languages
# or provide a fallback… then set current language
#
# set-language($locale);
#
}

You can also detect the language directly in your bootstrap file and
use the selected language to write your routes

$uri = request_uri();
$localized = preg_match('%^/(\w{2})%', $uri, $matches);
$locale = $matches[1];

# Then set routes
#
$options = array('params' => array('locale' => $locale));
dispatch("/$locale/contact", 'contact', $options);
dispatch("/$locale/my_page", 'my_page', $options);

# Using options params provide locale value to controllers
#

function contact($locale)
{
#
}

++ Fabrice

chem

unread,
Jul 14, 2011, 5:49:36 PM7/14/11
to limo...@googlegroups.com
Hello,

merci beaucoup for your helpful hints. This gave me a push in the right direction.

best regards
chem


Reply all
Reply to author
Forward
0 new messages