This is a simple widget to pick a language from your internalizations available! It automatically searches your /application/messages/ for available translations and put it in the list, and user can pick it. This little CPortel, so it is easy to make it look cooler via css or even little flags for languages ;-)
Ability to follow instructions, and have Yii installed ;-)
Download the extension, and put it in your extensions directory. I'm sure most of you extend CController...
it uses CPhpMessageSource
so in your main config should be
'messages' => array( 'class' => 'CPhpMessageSource' ),
Actually it is the default, so you can omit it ...
Put inside CController::init() , or in beforeAction method
Yii::import('ext.LanguagePicker.ELanguagePicker'); ELanguagePicker::setLanguage();
In your view, put:
$this->widget('ext.LanguagePicker.ELanguagePicker', array( ));
And you're done...
If you don't have any directories inside messages/ just create some, for example : ru, he, en etc. and you will the the list created
feel free to customize it, improve it, and don't forget to share your improvements ;-)
Make sure you check out my theme picker also http://www.yiiframework.com/extension/themepicker
If you new to Yii maybe you don't know how to use internalization: Create 2 directories under APPPATH/messages/ lang1 and lang2
than, create there a file app.php
put inside lang1/app.php the following:
return array( 'abc' => ''this is first language translation', );
put inside lang2/app.php the following:
return array( 'abc' => 'this is second language translation', );
Now insert in your view
echo Yii::t('app', 'abc');
And try to play with language selector, and you will understand in seconds how it works
you can add for example in main.php
'sourceLanguage' => 'en', 'language' => 'ru',
language will be the default translation, and you must know that translation happens only if sourceLanguage differs from language
Total 6 comments
you may add this code in function setLanguage,
so this extension can be applied to a html link tag (with GET parameter) like this
Hi, tks for the extension. Just wanna share how I apply this extension. I also use MultilingualBehavior which required to add params in config/main.php and I want so that there is conformity between these two extension and there is no multiple locale values. So this is how I apply this :
i. Set the params in config/main.php (params' key should be the same with the directory names):
ii. In ELanguagePicker :
iii. This is how I call the extension (add "params" to tell the name of your params. If you dont tell the params name, the it will get the list from the directories' name):
Im interested in changing drowdown menu for flags too
Would it be possible to have different values and names for the options? Ie.
I could use 'English' as the folder name for English translations, however, accented folders are not displayed in the select so this isn't an option in every case.
LE: I did this by having a language table with language codes (folder names) and language names :)
If you ask for simple solution just replace text with images:
etc.
TO do so, the simplest way is to customize the dropDownOptions array,
this is a good start:
Also some more advanced javascript / jQuery will make it look even cooler
If you want to see an implementation of jQuery solution with dialog box, check out this project
http://www.chive-project.com/
It has very cool language picker with dialog box...
Its Wonder full, and easy to understand... I like it. Can you please explain, how to use, Flags, instead of Dropdown language select?
Leave a comment
Please login to leave your comment.