Tuesday, February 07, 2012

Codeigniter: Language lines into javascript

I’ve extend language_helper and I’ve added a langJs function.

For use it you only call it with an array including lines for pass to javascript.


In the controller
$this->lang->load('calendar', 'spanish');

In the view

echo langJs(array('cal_wednesday', 'cal_january'));


Load all lines
If you need load all lines, you can do something like this:

In the Controller

$this->lang->load('calendar', 'spanish');
$data['lang_keys'] = array_keys($this->lang->language);

In the View
echo langJs($lang_keys);

As you can see, is very easy passing messages to javascript.
Download Language Helper

No comments: