Url With Language Code And Translated Controllers

Hi to all,

i’m starting to use Yii and I’m trying to adapt some default behaviors. One of them is the way Yii manage languages in URL.

The objective is get this kind of URLs for example:

subdomain.domain.com/search -> Language: en; Controller: search

subdomain.domain.com/es/buscar -> Language: es, Controller: search

subdomain.domain.com/fr/rechercher -> Language: fr, Controller: search

subdomain.domain.com/en -> Error 404. Default language do not require language code in url

subdomain.domain.com/es/search -> Error 404. Translated controller not found for language code ‘es’

So, I would like to translate controllers in URL and make that all controller translations point to same controller.

I’m investigating this extension: yiiframework.com/wiki/55/i18n-subdomains-and-url-rules that fits pretty well on what I want to get. The problem where i’m now is that this regular expression of this extension:


is based on language code in subdomain and I want language code as a path and I’m trying this but it fails getting it:


I would appreciate if someone could detect the error on this regular expression.

Also if you know some other solution for getting URLs this way it would be very useful otherwise I will try to publish an extension with this kind of URLs.

Thank you!

Everybody stand back!

I’m not sure that this will work, because it seems that the regex is matched against $_SERVER’s “SERVER_PROTOCOL” and “HTTP_HOST”.

Maybe there’s a way for you to change that.

"/^(?<protocol>(http|https):\/\/)(?<domain>[^\/]+)\/(?<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />?<languageCode>[\w]{2})\/)?/"

Hi Rodrigo,

you are right, regex is matched against $_SERVER, I didn’t realize :angry: . Now I decided this extension is better for what i want: www.yiiframework.com/wiki/294/seo-conform-multilingual-urls-language-selector-widget-i18n with this rules for full multilingual urls:

'es/contactenos' => array('site/contact', 'defaultParams' => array('language' => 'es')),

'de/kontakten' => array('site/contact', 'defaultParams' => array('language' => 'de')),

'en/contact-us' => array('site/contact', 'defaultParams' => array('language' => 'en')),

I’m working on it.

Thank you for answering!