This extension allows to use URLs that contain a language code like
/en/some/page /de/some/page http://www.example.com/en/some/page http://www.example.com/de/some/page
Since 1.1.3 you can also configure friendlier language names if you want:
http://www.example.com/english/some/page http://www.example.com/deutsch/some/page
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.
ext.localeurls (only if YII_DEBUG is set)detecLanguage to false in the request component.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 8 comments
@morteza
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?
hi.thank you
module page http://localhost/news/fr/bankSystem/bankUser/index
change language=> module page http://localhost/news/ar/bankSystem/bankSystem/bankUser/index
help!!!!!!
@rasha1489:
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.
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
@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
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?
It's no problem as long as you list e.g.
en_gbanden_usbeforeen.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 login to leave your comment.