This extension allows to change site language. I was using this extension earlier and I decided to make my own.
Just add this code to init() method in your main controller class (protected/components/Controller.php)
public function init() { Yii::import('ext.LangPick.ELangPick'); ELangPick::setLanguage(); parent::init(); }
And in the place where you want to render Language Picker
$this->widget('ext.LanguagePicker.ELangPick', array());
And don't forget to set source language in (protected/config/main.php)
return array( 'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..', 'name'=>'Demo', ... 'sourceLanguage'=>'en', ...
You have to create translations, which should be placed in messages folder
messages de // folder strings.php // translation file pl // folder strings.php // translation file
Each translation file should contain translation array
return array ( 'Home' => 'Główna', 'About' => 'O stronie', );
finally, to use translations:
Yii::t('strings', 'Home')
For more info, please read manual.
If you want to customize it
$this->widget('ext.LanguagePicker.ELangPick', array( 'excludeFromList' => array('pl', 'en'), // list of languages to exclude from list 'pickerType' => 'buttons', // buttons, links, dropdown //'linksSeparator' => '<b> | </b>', // if picker type is set to 'links' 'buttonsSize' => 'mini', // mini, small, large 'buttonsColor' => 'success', // primary, info, success, warning, danger, inverse ));

Total 17 comments
Problem was encoding and extra hidden characters in the header. Your extension works perfect. Thank you
I can't tell you much more than error message already does... It would be useful if you could show me your config file and application.log from runtime folder (assuming that logging is enabled).
I got this naughty error : Cannot modify header information - headers already sent by (output started at /home/website_name/public_html/webapp/protected/components/Controller.php:1)
for this line: Yii::app()->request->cookies['language'] = $cookie;
I was doing it in my way but got that error. After found your extension I wished it can solve my problem but same error appeared again. This is work on localhost but not on online host and I can't understand why.
I can't check it right now, but this setting shouldn't influence my extension. It won't work if browser has disabled cookies.
This doesn't work if enableCookieValidation = true, is it right?
It's hard for me to investigate without knowing server configuration and other things...
First of all, don't worry about url - LangPick uses POST requests, you can check it using FireBug extension (or any other, depending on your browser) - example.
I'll send you private message on forum containing my whole demo page (which works both on localhost and remote host with same config file).
EDIT: You can also try to add
to your config file...
Hi Lowlliet,
I have commented the following line in /protected/config/main.php
Now there is no longer error message displayed. But nothing happend when I click on both the langage links FR|EN; nothing happend. There is no view change. The URL in the address bar stays the same:
It is the same URL than when I click on the link labelled "Curriculum vitae".
The url is correct (Language Picker uses POST requests).
Could you try disabling CSRF token validation: Link and let me know if this works for you.
Hi lowlliet,
I have updated the code as you said.
Now I have an array of 2 languages on the web page as I had wanted.
I have this into /protected/views/layouts/main.php
But when I click on both of the language symbol I have on the view, I have the following error message:
If you think this is a server error, please contact the webmaster.
When I rollover the mouse on both the language symbol, I can see this url showing into the task bar:
Hi, this extension displays all folders within messages folder, but to solve your problem I've added some feature (please download LangPick [updated].zip) and change your code to
in excludeFromList put all languages you want to prevent from displaying.
Thank you lowlliet. I no longer have error. However, I have exactly the following array displaying on the pages: "HU | FR | LV | ZH_TW | JA | BG | NL | NO | SV | SR_YU | PL | BS | HE | DE | ZH_CN | KO_KR | AR | EN | ID | TH | PT_BR | LT | PT | FA_IR | RU | UK | SK | TR | IT | KK | CS | RO | TA_IN | SR_SR | ES | VI | EL". Yet I only want 2 of them to be displayed. Did I missed something?
This is the code of /protected/views/layout/myPage.php
This is the code of protected/config:
Hi,
to make it work, just change from
to
or change Yii messages path.
Hi lowlliet,
I am getting the following error message «DirectoryIterator::__construct(/var/www/testYii/protected/messages): failed to open dir: No such file or directory» about this line:
/var/www/testYii/protected/extensions/LangPick/ELangPick.php(46)
On my system, I have this path
rather than
Thank you.
If you talk about translation providing method, in Yii you can use few ways to provide translation strings: CPhpMessageSource, CGettextMessageSource, CDbMessageSource. Translations itself you can create on your own or like you said, you can get it from any proper translated site.
how about using language files, what we get on net rather then creating translation file (strings.php) by us.
I have updated usage instruction, please let me know if you still have troubles.
Im getting only one language and ie EN, what i have to do to get more language options...
Leave a comment
Please login to leave your comment.