Language switcher

I have read topic from cookbook Setting and maintaining the language in Application (i18n), and it is helpfull. Only it should be tweaked to use _lang from GET instead of POST. That way it colud be possible to save url to page written in any language.

I changed example file components/views/langBox.php to


    $url = ''; 

    echo CHtml::form($url, 'get') ?>

    <div id="langdrop">

        <?php echo CHtml::dropDownList('_lang', $currentLang, array(

            'en_us' => 'English', 'is_is' => 'Icelandic'), array('submit' => '')) ?>


<?php echo CHtml::endForm()?> 

The problem is that normalized $url is appdended _lang after every language switch.

What would be the best solution to obtain valid $url, which is pointing to the current page and have just one _lang=en_us or lang=is_is ?

My solution is to parse CHttpRequest::getQueryString(), remove all previous _lang and append just the current one. It is not very elegant.

I use a link helper like this…

public static function i18n($text, $lang = null, $url = null){        


            $url[] = '/'.Yii::app()->controller->route;

            foreach($_GET as $key => $val){

                $url[$key] = $val;





            $url['lang'] = $lang;


        return CHtml::link($text,$url);