Welcome Guest, Not a member yet? Register   Sign In
Character encoding using lang()
#5

[eluser]rossmurphy[/eluser]
I extended the lang library so that i could pass in vars and return a line with html. It also takes care of the problem i was having with special chars and html in the same lang line.

Let me know how it could be improved.

Code:
<?php
class MY_Language extends CI_Language{
    
    function line($lang_key, $parameters = NULL){

        $lang_return = parent::line($lang_key);
        
        if($lang_return === false) {
            return "???$lang_key???";
        } else {
        
            // parse variables if passed
            if(!is_null($parameters)) {
                $return_line = $this->parse_lang_vars($lang_return, $parameters);
            }
                
            // set translation table
            $translation_table = get_html_translation_table(HTML_ENTITIES);
            
            // encode trans line
            $encoded_line = strtr($return_line, $translation_table);
            
            // decode html elements
            $line = htmlspecialchars_decode($encoded_line);
            
            return $line;
            
        }
    }
    
    function parse_lang_vars($lang_return, $parameters) {
        
        // check for array
        $parameters = is_array($parameters) ? $parameters : array($parameters);
        
        foreach($parameters as $key => $value) {
            $line = str_replace('{'.$key.'}', $value, $lang_return);
        }

        return $line;
                
    }
    
}


Messages In This Thread
Character encoding using lang() - by El Forum - 11-27-2009, 08:24 AM
Character encoding using lang() - by El Forum - 11-27-2009, 09:09 AM
Character encoding using lang() - by El Forum - 11-27-2009, 01:30 PM
Character encoding using lang() - by El Forum - 11-28-2009, 02:48 PM
Character encoding using lang() - by El Forum - 12-05-2009, 09:49 AM
Character encoding using lang() - by El Forum - 12-05-2009, 11:53 AM
Character encoding using lang() - by El Forum - 12-06-2009, 09:45 AM



Theme © iAndrew 2016 - Forum software by © MyBB