Yii 1.1: localeurls

Automatic locale/language management for URLs

This extension allows to use URLs that contain a language code like


Since 1.1.3 you can also configure friendlier language names if you want:


The language code is automatically inserted into every URL created and read back on every request. No extra URL rules are required. For best user experience the language is also restored from session/cookie if the user returns to a URL without a language code.


Extract the package to your protected/extensions directory and rename it to localeurls. Then configure the components in your protected/config/main.php:

return array(
    // ...
    'components' => array(
        // ...
        'urlManager' => array(
            'class'     => 'ext.localeurls.LocaleUrlManager',
            // Advanced configuration with defaults (see below)
            //'languageParam'   => 'language',
        'request' => array(
            'class'     => 'ext.localeurls.LocaleHttpRequest',
            'languages' => array('en_us','en','de','fr'),
            // Since version 1.1.3 you can also map url => language
            // 'languages' => array(
            //      'english'   => 'en',
            //      'deutsch'   => 'de',
            //      'fr',
            //  )
            // Advanced configuration with defaults (see below)
            //'persistLanguage'         => true,
            //'languageCookieLifetime'  => 31536000,
            //'redirectDefault'         => false,
        // ...

Please head over to the github project page for all the details.



  • Fix issue where URLs that contained the language code a second time where messed up


  • Fix issue where the query string was lost when switching back to default language


  • Fix issue where you could not create URLs to reset to default language


  • Add mapping feature.
  • Add debug output under category ext.localeurls (only if YII_DEBUG is set)


  • Preferred user language is detected from the HTTP headers now. To disable, set detecLanguage to false in the request component.


  • The parameter defaultLanguage was removed. You should configure the default language in your main application config instead. If you want to redirect to your default language, you can set redirectDefault to true.

Total 11 comments

#13918 report it
tehmaestro at 2013/07/05 01:28pm

Missed that. I tried it, but here's my problem. I am creating a multilanguage app, and all my controllers have URL rules like :

en ->          appname/controller-name/1-english-name/
  other-lang ->  appname/other-lang/other-lang-controller-name/1-other-lang-name/

So every controller name has a different version depending on the language, and the slug (the id + name combination which retrieves my model for view) is also custom and specified in each language as a URL rule.

Your widget is great, but it generates the link for switching to the other language like :


which gives a 404 error. So it adds the get language param, but it generates the link based on current defined URL rules .. which is normal for the way the widget was created. The URL rules are added dynamically, based on current language selection.

If you have any idea how I could modify this, that would be awesome. Thanks again.

#13915 report it
Mike at 2013/07/05 10:58am
Re: Change Language

Have you checked the example widget on the github page?


#13892 report it
tehmaestro at 2013/07/04 10:21am
Change language

Hey, do you have an example code for changing the language? I don't really know how to do it, and keep the user on the same URL.

#12844 report it
Mike at 2013/04/15 02:13pm
problem url in modules


Hmm. Could you do me a favour and open an issue over at github? Could you also explain what you mean by "change language"? Did you manually create an URL? If yes, how?

#12843 report it
morteza at 2013/04/15 01:55pm
problem url in modules

hi.thank you

module page http://localhost/news/fr/bankSystem/bankUser/index

change language=> module page http://localhost/news/ar/bankSystem/bankSystem/bankUser/index


#12747 report it
Mike at 2013/04/09 01:10pm
Re: folder directories


You'll find the answer you are looking for in the "File Translation" section of this page: http://www.yiiframework.com/doc/guide/1.1/en/topics.i18n

If it's still unclear please ask on the forum. This comment section is only for comments that are closely related to this extension. Your question is rather a general question about i18n.

#12743 report it
freshyiiuser at 2013/04/09 09:46am
folder directories

thank you, i follow the steps to create a multilanguage app using the localeurls extension,but still i need to know about folder directories. where to put the folders/files or do i have to rename them? i put the folder under: - protected/views/ar/site/index.php -> not working object not found - protected/views/site/en/index.php not working object not found

where is the problem, i still dont know. kindly help me

#12735 report it
Mike at 2013/04/09 03:11am
Re: localurl

@rasha1489: It means exactly what it says :). You have to use URLs in path format. See here: http://www.yiiframework.com/doc/guide/1.1/en/topics.url

#12730 report it
freshyiiuser at 2013/04/08 06:29pm

thank you for this extension, i tried to use it but i got this error; LanguageUrlManager only works with urlFormat 'path', what is that means?

#11879 report it
Mike at 2013/02/11 02:31am
Re: Languages with "- or _"

It's no problem as long as you list e.g. en_gb and en_us before en.

#11875 report it
Sean Kumar at 2013/02/10 02:05pm
Languages with "- or _"

EDIT: Mike is right, the locales do work fine. Just need to add them first in the array. Sorry missed that note in the instructions.

Hey Mike,

I was using your extension on a project and noticed that languages with a "-" or "_" in them brings up a 404 error: "Unable to resolve the request -ca", this was attempting to use en-ca or en_ca.

I've added the supported languages to the config array/ 'languages' => array('en_us','en','de','fr','en_ca','en_gb'),

Is there a preferred format to enter the supported languages? Thanks for your help.

Leave a comment

Please to leave your comment.

Create extension