Changeset 2427

Show
Ignore:
Timestamp:
09/01/08 18:08:38 (3 months ago)
Author:
ringmaster
Message:

Update Locale functions to accept parameters for replacement, circumvent sprintf().

For example: _e('My name: $s', array('Name'), 'domain') outputs-> My name: Name

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/htdocs/system/classes/locale.php

    r2380 r2427  
    260260     * @param string $domain (optional) The domain to search for the message      
    261261     **/ 
    262     public static function _e( $text, $domain= 'habari' ) 
    263     { 
    264         echo self::_t( $text, $domain ); 
     262    public static function _e( ) 
     263    { 
     264        $args = func_get_args(); 
     265        echo call_user_func_array(array('Locale', '_t'), $args); 
    265266    } 
    266267 
    267268    /** 
    268269     * Return a version of the string translated into the current locale 
    269      *  
     270     * 
    270271     * @param string $text The text to echo translated 
    271      * @param string $domain (optional) The domain to search for the message      
     272     * @param string $domain (optional) The domain to search for the message 
    272273     * @return string The translated string 
    273274     **/ 
    274     public static function _t( $text, $domain= 'habari' ) 
    275     { 
     275    public static function _t($text, $args = array(), $domain = 'habari') 
     276    { 
     277        if( is_string($args) ) { 
     278            $domain = $args; 
     279        } 
     280 
    276281        if ( isset( self::$messages[$domain][$text] ) ) { 
    277             return self::$messages[$domain][$text][1][0]; 
     282            $t = self::$messages[$domain][$text][1][0]; 
    278283        } 
    279284        else { 
    280             return $text; 
    281         } 
     285            $t = $text; 
     286        } 
     287 
     288        if(!empty($args) && is_array($args)) { 
     289            array_unshift($args, $t); 
     290            $t = call_user_func_array('sprintf', $args); 
     291        } 
     292 
     293        return $t; 
    282294    } 
    283295 
     
    324336 * @param string $text The text to translate 
    325337 **/ 
    326 function _e( $text, $domain= 'habari' ) 
    327 { 
    328     return Locale::_e( $text, $domain ); 
     338function _e( $text, $args = array(), $domain= 'habari' ) 
     339{ 
     340    return Locale::_e( $text, $args, $domain ); 
    329341} 
    330342 
     
    348360 * @return string The translated string 
    349361 **/ 
    350 function _t( $text, $domain= 'habari' ) 
    351 { 
    352     return Locale::_t( $text, $domain ); 
     362function _t( $text, $args = array(), $domain= 'habari' ) 
     363{ 
     364    return Locale::_t( $text, $args, $domain ); 
    353365} 
    354366