CodeIgniter Forums
Language helper - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Language helper (/showthread.php?tid=7264)



Language helper - El Forum - 04-01-2008

[eluser]Référencement Google[/eluser]
If this could make life easier of some of you, here is a language helper:

Code:
function lang($line_key = '', $args = '', $lang = '')
{
    $ci =& get_instance();

    if( ! is_array($args))
    {
        $args = array($args);
    }

    $line_key = $ci->lang->line($line_key, $lang);
    return vsprintf($line_key, $args);
}

You may put it in a helper file in your application/helpers directory.

Then you in a language file you will have something like:
Code:
$lang['test'] = "I am %s and I am %d years old";

The main advantage is that it let you pass arguments as second parameter that can be use in your language strings (like you would make with vsprintf function), here is how:

USAGE:
Code:
$this->lang->load('langagefile');
echo lang('test', array('Christophe', '35'));



Language helper - El Forum - 04-01-2008

[eluser]wiredesignz[/eluser]
This is the kind of thing that should be added to the CI core. Great work Wink


Language helper - El Forum - 04-13-2008

[eluser]Young Caveman[/eluser]
This is what i need Smile ;P Thanks!


Language helper - El Forum - 04-13-2008

[eluser]Thoer[/eluser]
It looks really good! Thanks!