Welcome Guest, Not a member yet? Register   Sign In
Language Parser Helper
#11

[eluser]wiredesignz[/eluser]
Ok, but lang->load will use $config['language'] if none is supplied, I guess you see that.

Is there something I need to change in the helper class?
#12

[eluser]wiredesignz[/eluser]
Another feature would be to use the text {value} literally if a lang->line{"value") returns false
#13

[eluser]xwero[/eluser]
I think this will work
Code:
class Language
{
    function parse($view, $data = array(), $lang_files = array(), $lang = 'english') // changed
    {
        $this->load->language($lang_files,$lang); // changed

        if ($template = $this->load->view($view, $data, TRUE))     //build the view normally
        {            
            while(preg_match('/\{(\w*)\}/siU', $template, $match)) //parse the language variables
            {
                $template = str_replace($match[0], $this->lang->line("$match[1]"), $template);
            }
                        
            return $template;
        }
    }
    
}
#14

[eluser]wiredesignz[/eluser]
Good work xwero Wink

Could you also look at adding the feature I mentioned above xwero.

So {Value} is translated by $this->lang->line("Value") but if it returns FALSE then "Value" is inserted

Update #3 added langfiles and language. Thanks xwero Wink
#15

[eluser]xwero[/eluser]
something like this?
Code:
$lang_line =  $this->lang->line($match[1]);
if($lang_line === FALSE)
{
   $template = str_replace($match[0], $match[1], $template);
}
else
{
   $template = str_replace($match[0], $lang_line, $template);
}
#16

[eluser]wiredesignz[/eluser]
Yes, great. Thanks xwero Wink
Code:
$line = $this->lang->line("$match[1]") OR $line = $match[1];

$template = str_replace($match[0], $line, $template);

...
Update #4

EDIT: My recode of xwero's method may fail if an empty string is returned!
#17

[eluser]wiredesignz[/eluser]
Maybe this instead
Code:
if (($line = $this->lang->line("$match[1]")) === FALSE) $line = $match[1];

$template = str_replace($match[0], $line, $template);

...
Update #5
#18

[eluser]xwero[/eluser]
You didn't tell me you needed less code Smile
Code:
$line =  $this->lang->line($match[1]);
if($line === FALSE){ $line = $match[1]; }
$template = str_replace($match[0], $line, $template);

edit : your last code will work as well Smile
#19

[eluser]wiredesignz[/eluser]
I like my code lean and mean :lol:
#20

[eluser]sikkle[/eluser]
You should join this with something to make it easy to use /domain.com/en/home etc. etc.

good job.




Theme © iAndrew 2016 - Forum software by © MyBB