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'));
#2

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

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

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




Theme © iAndrew 2016 - Forum software by © MyBB