Changeset 24988


Ignore:
Timestamp:
Oct 19, 2013, 11:21:01 AM (7 years ago)
Author:
mistic100
Message:

feature 2978: l10n() and {translate} with additional arguments
TODO: apply in core

Location:
trunk/include
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/functions.inc.php

    r24833 r24988  
    901901
    902902/**
    903  * returns the corresponding value from $lang if existing. Else, the key is
    904  * returned
    905  *
    906  * @param string key
     903 * translation function
     904 * returns the corresponding value from $lang if existing, else the key is returned
     905 * if more than one parameter is provided sprintf is applied
     906 * @param string $key
     907 * @param mixed $args,... optional arguments
    907908 * @return string
    908909 */
     
    915916    if ($conf['debug_l10n'] and !isset($lang[$key]) and !empty($key))
    916917    {
    917       trigger_error('[l10n] language key "'.$key.'" is not defined', E_USER_WARNING);
     918      trigger_error('[l10n] language key "'. $key .'" not defined', E_USER_WARNING);
    918919    }
    919920    $val = $key;
    920921  }
     922
     923  if (func_num_args() > 1)
     924  {
     925    $val = vsprintf($val, array_slice(func_get_args(), 1));
     926  }
     927
    921928  return $val;
    922929}
    923930
    924931/**
    925  * returns the prinft value for strings including %d
     932 * returns the printf value for strings including %d
    926933 * return is concorded with decimal value (singular, plural)
    927934 *
  • trunk/include/template.class.php

    r23688 r24988  
    9696    $this->smarty->registerPlugin('modifiercompiler', 'translate_dec', array('Template', 'modcompiler_translate_dec') );
    9797    $this->smarty->registerPlugin('modifier', 'explode', array('Template', 'mod_explode') );
    98     $this->smarty->registerPlugin( 'modifier', 'get_extent', array($this, 'get_extent') );
     98    $this->smarty->registerPlugin('modifier', 'get_extent', array($this, 'get_extent') );
    9999    $this->smarty->registerPlugin('block', 'html_head', array($this, 'block_html_head') );
    100100    $this->smarty->registerPlugin('block', 'html_style', array($this, 'block_html_style') );
     
    488488  }
    489489
    490   static function get_php_str_val($str)
     490  private static function get_php_str_val($str)
    491491  {
    492492    if (is_string($str) && strlen($str)>1)
     
    508508  {
    509509    global $conf, $lang;
    510     if ( $conf['compiled_template_cache_language']
    511       && ($key=self::get_php_str_val($params[0])) !== null)
    512     {
    513       if (isset($lang[$key]))
     510
     511    switch (count($params))
     512    {
     513    case 1:
     514      if ($conf['compiled_template_cache_language']
     515        && ($key=self::get_php_str_val($params[0])) !== null
     516        && isset($lang[$key])
     517      ) {
    514518        return var_export($lang[$key], true);
    515     }
    516     return 'l10n('.$params[0].')';
     519      }
     520      return 'l10n('.$params[0].')';
     521     
     522    default:
     523      if ($conf['compiled_template_cache_language'])
     524      {
     525        $ret = 'sprintf(';
     526        $ret .= self::modcompiler_translate( array($params[0]) );
     527        $ret .= ','. implode(',', array_slice($params, 1));
     528        $ret .= ')';
     529        return $ret;
     530      }
     531      return 'l10n('.$params[0].','.implode(',', array_slice($params, 1)).')';
     532    }
    517533  }
    518534
     
    520536  {
    521537    global $conf, $lang, $lang_info;
    522     if ( $conf['compiled_template_cache_language'])
     538    if ($conf['compiled_template_cache_language'])
    523539    {
    524540      $ret = 'sprintf(';
Note: See TracChangeset for help on using the changeset viewer.