Welcome Guest, Not a member yet? Register   Sign In
How can I use lang() function in helper class
#1

[eluser]fuksito[/eluser]
Is it posible?
I made helper for building color-picker and I need to translate it dynamicly
#2

[eluser]Colin Williams[/eluser]
Of course it's possible. It's just a function. Call it when and where you need to.
#3

[eluser]xwero[/eluser]
It's better to use
Code:
$CI =& get_instance();
$CI->lang->line('some_line');
In your functions because the language helper isn't loaded by default.
#4

[eluser]Colin Williams[/eluser]
Or just autoload the lang helper...
#5

[eluser]xwero[/eluser]
[quote author="Colin Williams" date="1220238472"]Or just autoload the lang helper...[/quote]
You can do that but then you have to do it for each application you want to use the helper in. I think for helper it's saver to use language library which is loaded by default.
#6

[eluser]Colin Williams[/eluser]
By that same token, xwero, he can load the helper with the Loader::helper() function. The benefit is that the syntax of lang() is much cleaner.
#7

[eluser]xwero[/eluser]
True you have to type less but if he wants to contribute the helper then he has to put in the requirements load language helper. Which is restrictive IMO.
#8

[eluser]Colin Williams[/eluser]
Not if he loads it in his helper.. I don't think you're following me.

Code:
$ci =& get_instance();
$ci->load->helper('language');

function color_picker()
{
  $title = lang('cp_title');
  $red = lang('cp_red');
}
#9

[eluser]xwero[/eluser]
Ok you got a point there but what if people use a version where the helper isn't present. It's a recent addition, 1.6.1 i believe. This means you have to add the language helper too with his helper. I believe you should strive to create as less dependencies as possible.

The lang() function is nothing more than a wrapper for the lang->line method.
#10

[eluser]Colin Williams[/eluser]
Is it not in your fabric to not find a problem with an alternative suggestion? Smile

If pre-language helper support is a goal of yours, fuksito, use the language class like xwero mentioned. Or, better yet, define your own language class wrapper:

Code:
function color_lang($line, $id = '')
{
    $CI =& get_instance();
    $line = $CI->lang->line($line);

    if ($id != '')
    {
        $line = '<label for="'.$id.'">'.$line."</label>";
    }

    return $line;
}

function color_picker()
{
  $title = color_lang('title');
}




Theme © iAndrew 2016 - Forum software by © MyBB