Changeset 23476


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

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

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/themes/default/template/tags.tpl

    r23426 r23476  
    151151<ul class="tagSelection">
    152152{foreach from=$all_tags item=tag}
    153         <li>{capture name='showInfo'}<b>{$tag.name}</b> ({$pwg->l10n_dec('%d photo', '%d photos', $tag.counter)}) <br> <a href="{$tag.U_VIEW}">{'View in gallery'|@translate}</a> | <a href="{$tag.U_EDIT}">{'Manage photos'|@translate}</a>{if !empty($tag.alt_names)}<br>{$tag.alt_names}{/if}{/capture}
     153        <li>{capture name='showInfo'}<b>{$tag.name}</b> ({$tag.counter|@translate_dec:'%d photo':'%d photos'}) <br> <a href="{$tag.U_VIEW}">{'View in gallery'|@translate}</a> | <a href="{$tag.U_EDIT}">{'Manage photos'|@translate}</a>{if !empty($tag.alt_names)}<br>{$tag.alt_names}{/if}{/capture}
    154154                <a class="icon-info-circled-1 showInfo" title="{$smarty.capture.showInfo|@htmlspecialchars}"></a>
    155155                <label>
  • 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      }
  • trunk/themes/default/template/menubar_categories.tpl

    r23384 r23476  
    2929{'</li></ul>'|@str_repeat:$ref_level}
    3030
    31         <p class="totalImages">{$pwg->l10n_dec('%d photo', '%d photos', $block->data.NB_PICTURE)}</p>
     31        <p class="totalImages">{$block->data.NB_PICTURE|@translate_dec:'%d photo':'%d photos'}</p>
    3232</dd>
  • trunk/themes/default/template/menubar_tags.tpl

    r8774 r23476  
    66                        <a class="tagLevel{$tag.level}" href=
    77                        {if isset($tag.U_ADD)}
    8                                 "{$tag.U_ADD}" title="{$pwg->l10n_dec('%d photo is also linked to current tags', '%d photos are also linked to current tags', $tag.counter)}" rel="nofollow">+
     8                                "{$tag.U_ADD}" title="{$tag.counter|@translate_dec:'%d photo is also linked to current tags':'%d photos are also linked to current tags'}" rel="nofollow">+
    99                        {else}
    1010                                "{$tag.URL}" title="{'display photos linked to this tag'|@translate}">
  • trunk/themes/default/template/month_calendar.tpl

    r14028 r23476  
    1313        {else}
    1414                {foreach from=$bar.items item=item}
    15                 <span class="calItem{if !isset($item.URL)}Empty{/if}" {if isset($item.NB_IMAGES)}title="{$pwg->l10n_dec('%d photo', '%d photos', $item.NB_IMAGES)}"{/if}>
     15                <span class="calItem{if !isset($item.URL)}Empty{/if}" {if isset($item.NB_IMAGES)}title="{$item.NB_IMAGES|@translate_dec:'%d photo':'%d photos'}"{/if}>
    1616                {if isset($item.URL)}
    1717                <a href="{$item.URL}">{$item.LABEL}</a>
     
    6969                                <div class="calImg">
    7070                                        <a href="{$day.U_IMG_LINK}">
    71                                                 <img style="{$day.IMAGE_STYLE}" src="{$day.IMAGE}" alt="{$day.IMAGE_ALT}" title="{$pwg->l10n_dec('%d photo','%d photos', $day.NB_ELEMENTS)}">
     71                                                <img style="{$day.IMAGE_STYLE}" src="{$day.IMAGE}" alt="{$day.IMAGE_ALT}" title="{$day.NB_ELEMENTS|@translate_dec:'%d photo':'%d photos'}">
    7272                                        </a>
    7373                                </div>
  • trunk/themes/default/template/picture.tpl

    r23437 r23476  
    213213                <dd>
    214214                {if $rate_summary.count}
    215                   {if $rate_summary.count == 1}
    216                     {assign var='rate_text' value='%d rate'|@translate}
    217                   {else}
    218                     {assign var='rate_text' value='%d rates'|@translate}
    219                   {/if}
    220                         <span id="ratingScore">{$rate_summary.score}</span> <span id="ratingCount">({$pwg->sprintf($rate_text, $rate_summary.count)})</span>
     215                        <span id="ratingScore">{$rate_summary.score}</span> <span id="ratingCount">({$rate_summary.count|@translate_dec:'%d rate':'%d rates'})</span>
    221216                {else}
    222217                        <span id="ratingScore">{'no rate'|@translate}</span> <span id="ratingCount"></span>
     
    336331{if isset($COMMENT_COUNT)}
    337332<div id="comments" {if (!isset($comment_add) && ($COMMENT_COUNT == 0))}class="noCommentContent"{else}class="commentContent"{/if}><div id="commentsSwitcher"></div>
    338         <h3>{$pwg->l10n_dec('%d comment', '%d comments',$COMMENT_COUNT)}</h3>
     333        <h3>{$COMMENT_COUNT|@translate_dec:'%d comment':'%d comments'}</h3>
    339334
    340335        <div id="pictureComments">
  • trunk/themes/default/template/tags.tpl

    r18455 r23476  
    2424<div id="fullTagCloud">
    2525        {foreach from=$tags item=tag}
    26         <span><a href="{$tag.URL}" class="tagLevel{$tag.level}" title="{$pwg->l10n_dec('%d photo', '%d photos', $tag.counter)}">{$tag.name}</a></span>
     26        <span><a href="{$tag.URL}" class="tagLevel{$tag.level}" title="{$tag.counter|@translate_dec:'%d photo':'%d photos'}">{$tag.name}</a></span>
    2727        {/foreach}
    2828</div>
     
    4040                <tr class="tagLine">
    4141                        <td><a href="{$tag.URL}" title="{$tag.name}">{$tag.name}</a></td>
    42                         <td class="nbEntries">{$pwg->l10n_dec('%d photo', '%d photos', $tag.counter)}</td>
     42                        <td class="nbEntries">{$tag.counter|@translate_dec:'%d photo':'%d photos'}</td>
    4343                </tr>
    4444                {/foreach}
Note: See TracChangeset for help on using the changeset viewer.