Welcome Guest, Not a member yet? Register   Sign In
Language helper
#1

[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'));


Messages In This Thread
Language helper - by El Forum - 04-01-2008, 09:22 AM
Language helper - by El Forum - 04-01-2008, 01:54 PM
Language helper - by El Forum - 04-13-2008, 03:15 PM
Language helper - by El Forum - 04-13-2008, 03:27 PM



Theme © iAndrew 2016 - Forum software by © MyBB