Ignore:
Timestamp:
Jun 23, 2013, 8:39:31 PM (11 years ago)
Author:
rvelices
Message:

Smarty3 added 'translate_dec' compilermodifier (generated code is a lot better than $pwg->l10n_dec)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/template.class.php

    r23425 r23476  
    5656    global $conf, $lang_info;
    5757
     58    SmartyException::$escape = false;
     59
    5860    $this->scriptLoader = new ScriptLoader;
    5961    $this->smarty = new SmartyBC;
     
    9294    $this->smarty->assign( 'pwg', new PwgTemplateAdapter() );
    9395    $this->smarty->registerPlugin('modifiercompiler', 'translate', array('Template', 'modcompiler_translate') );
     96    $this->smarty->registerPlugin('modifiercompiler', 'translate_dec', array('Template', 'modcompiler_translate_dec') );
    9497    $this->smarty->registerPlugin('modifier', 'explode', array('Template', 'mod_explode') );
    9598    $this->smarty->registerPlugin( 'modifier', 'get_extent', array($this, 'get_extent') );
     
    332335  function clear_assign($tpl_var)
    333336  {
    334     $this->smarty->clear_assign( $tpl_var );
     337    $this->smarty->clearAssign( $tpl_var );
    335338  }
    336339
     
    362365    if ( $conf['compiled_template_cache_language'] and isset($lang_info['code']) )
    363366    {
    364       $this->smarty->compile_id .= '.'.$lang_info['code'];
     367      $this->smarty->compile_id .= '_'.$lang_info['code'];
    365368    }
    366369
     
    512515    }
    513516    return 'l10n('.$params[0].')';
     517  }
     518
     519  static function modcompiler_translate_dec($params)
     520  {
     521    global $conf, $lang, $lang_info;
     522    if ( $conf['compiled_template_cache_language'])
     523    {
     524      $ret = 'sprintf(';
     525      if ($lang_info['zero_plural'])
     526      {
     527        $ret .= '($tmp=('.$params[0].'))>1||$tmp==0';
     528      }
     529      else
     530      {
     531        $ret .= '('.$params[0].')>1';
     532      }
     533      $ret .= '?';
     534      $ret .= self::modcompiler_translate( array($params[2]) );
     535      $ret .= ':';
     536      $ret .= self::modcompiler_translate( array($params[1]) );
     537      $ret .= ','.$params[0];
     538      $ret .= ')';
     539      return $ret;
     540    }
     541    return 'l10n_dec('.$params[1].','.$params[2].','.$params[0].')';
    514542  }
    515543
     
    770798          list($type, $callback) = $filter;
    771799          $compile_id .= $type.( is_array($callback) ? implode('', $callback) : $callback );
    772           call_user_func(array($this->smarty, 'register_'.$type), $callback);
     800          $this->smarty->registerFilter($type, $callback);
    773801        }
    774802      }
     
    786814        {
    787815          list($type, $callback) = $filter;
    788           call_user_func(array($this->smarty, 'unregister_'.$type), $callback);
     816          $this->smarty->unregisterFilter($type, $callback);
    789817        }
    790818      }
Note: See TracChangeset for help on using the changeset viewer.