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

git-svn-id: http://piwigo.org/svn/trunk@23476 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
rvelices
2013-06-23 18:39:31 +00:00
parent 67d736e3fd
commit b93085c7fb
7 changed files with 41 additions and 18 deletions
+1 -1
View File
@@ -150,7 +150,7 @@ $("#searchInput").on( "keydown", function() {
{/if}
<ul class="tagSelection">
{foreach from=$all_tags item=tag}
<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}
<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}
<a class="icon-info-circled-1 showInfo" title="{$smarty.capture.showInfo|@htmlspecialchars}"></a>
<label>
<input type="checkbox" name="tags[]" value="{$tag.id}"> {$tag.name}
+32 -4
View File
@@ -55,6 +55,8 @@ class Template {
{
global $conf, $lang_info;
SmartyException::$escape = false;
$this->scriptLoader = new ScriptLoader;
$this->smarty = new SmartyBC;
$this->smarty->debugging = $conf['debug_template'];
@@ -91,6 +93,7 @@ class Template {
$this->smarty->assign( 'pwg', new PwgTemplateAdapter() );
$this->smarty->registerPlugin('modifiercompiler', 'translate', array('Template', 'modcompiler_translate') );
$this->smarty->registerPlugin('modifiercompiler', 'translate_dec', array('Template', 'modcompiler_translate_dec') );
$this->smarty->registerPlugin('modifier', 'explode', array('Template', 'mod_explode') );
$this->smarty->registerPlugin( 'modifier', 'get_extent', array($this, 'get_extent') );
$this->smarty->registerPlugin('block', 'html_head', array($this, 'block_html_head') );
@@ -331,7 +334,7 @@ class Template {
/** see smarty append http://www.smarty.net/manual/en/api.clear_assign.php */
function clear_assign($tpl_var)
{
$this->smarty->clear_assign( $tpl_var );
$this->smarty->clearAssign( $tpl_var );
}
/** see smarty get_template_vars http://www.smarty.net/manual/en/api.get_template_vars.php */
@@ -361,7 +364,7 @@ class Template {
global $conf, $lang_info;
if ( $conf['compiled_template_cache_language'] and isset($lang_info['code']) )
{
$this->smarty->compile_id .= '.'.$lang_info['code'];
$this->smarty->compile_id .= '_'.$lang_info['code'];
}
$v = $this->smarty->fetch($this->files[$handle]);
@@ -513,6 +516,31 @@ class Template {
return 'l10n('.$params[0].')';
}
static function modcompiler_translate_dec($params)
{
global $conf, $lang, $lang_info;
if ( $conf['compiled_template_cache_language'])
{
$ret = 'sprintf(';
if ($lang_info['zero_plural'])
{
$ret .= '($tmp=('.$params[0].'))>1||$tmp==0';
}
else
{
$ret .= '('.$params[0].')>1';
}
$ret .= '?';
$ret .= self::modcompiler_translate( array($params[2]) );
$ret .= ':';
$ret .= self::modcompiler_translate( array($params[1]) );
$ret .= ','.$params[0];
$ret .= ')';
return $ret;
}
return 'l10n_dec('.$params[1].','.$params[2].','.$params[0].')';
}
/**
* explode variable modifier - similar to php explode
* 'Yes;No'|@explode:';' -> array('Yes', 'No')
@@ -769,7 +797,7 @@ var s,after = document.getElementsByTagName(\'script\')[document.getElementsByTa
{
list($type, $callback) = $filter;
$compile_id .= $type.( is_array($callback) ? implode('', $callback) : $callback );
call_user_func(array($this->smarty, 'register_'.$type), $callback);
$this->smarty->registerFilter($type, $callback);
}
}
$this->smarty->compile_id .= '.'.base_convert(crc32($compile_id), 10, 36);
@@ -785,7 +813,7 @@ var s,after = document.getElementsByTagName(\'script\')[document.getElementsByTa
foreach ($filters as $filter)
{
list($type, $callback) = $filter;
call_user_func(array($this->smarty, 'unregister_'.$type), $callback);
$this->smarty->unregisterFilter($type, $callback);
}
}
}
@@ -28,5 +28,5 @@
{/foreach}
{'</li></ul>'|@str_repeat:$ref_level}
<p class="totalImages">{$pwg->l10n_dec('%d photo', '%d photos', $block->data.NB_PICTURE)}</p>
<p class="totalImages">{$block->data.NB_PICTURE|@translate_dec:'%d photo':'%d photos'}</p>
</dd>
+1 -1
View File
@@ -5,7 +5,7 @@
<span>{strip}
<a class="tagLevel{$tag.level}" href=
{if isset($tag.U_ADD)}
"{$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">+
"{$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">+
{else}
"{$tag.URL}" title="{'display photos linked to this tag'|@translate}">
{/if}
+2 -2
View File
@@ -12,7 +12,7 @@
&nbsp;
{else}
{foreach from=$bar.items item=item}
<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}>
<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}>
{if isset($item.URL)}
<a href="{$item.URL}">{$item.LABEL}</a>
{else}
@@ -68,7 +68,7 @@ TABLE.calMonth TBODY TD, TABLE.calMonth TBODY TD DIV.calImg {ldelim}
<div class="calBackDate">{$day.DAY}</div><div class="calForeDate">{$day.DAY}</div>
<div class="calImg">
<a href="{$day.U_IMG_LINK}">
<img style="{$day.IMAGE_STYLE}" src="{$day.IMAGE}" alt="{$day.IMAGE_ALT}" title="{$pwg->l10n_dec('%d photo','%d photos', $day.NB_ELEMENTS)}">
<img style="{$day.IMAGE_STYLE}" src="{$day.IMAGE}" alt="{$day.IMAGE_ALT}" title="{$day.NB_ELEMENTS|@translate_dec:'%d photo':'%d photos'}">
</a>
</div>
{else}
+2 -7
View File
@@ -212,12 +212,7 @@ y.callService(
<dt>{'Rating score'|@translate}</dt>
<dd>
{if $rate_summary.count}
{if $rate_summary.count == 1}
{assign var='rate_text' value='%d rate'|@translate}
{else}
{assign var='rate_text' value='%d rates'|@translate}
{/if}
<span id="ratingScore">{$rate_summary.score}</span> <span id="ratingCount">({$pwg->sprintf($rate_text, $rate_summary.count)})</span>
<span id="ratingScore">{$rate_summary.score}</span> <span id="ratingCount">({$rate_summary.count|@translate_dec:'%d rate':'%d rates'})</span>
{else}
<span id="ratingScore">{'no rate'|@translate}</span> <span id="ratingCount"></span>
{/if}
@@ -335,7 +330,7 @@ function togglePrivacyLevelBox()
{if isset($COMMENT_COUNT)}
<div id="comments" {if (!isset($comment_add) && ($COMMENT_COUNT == 0))}class="noCommentContent"{else}class="commentContent"{/if}><div id="commentsSwitcher"></div>
<h3>{$pwg->l10n_dec('%d comment', '%d comments',$COMMENT_COUNT)}</h3>
<h3>{$COMMENT_COUNT|@translate_dec:'%d comment':'%d comments'}</h3>
<div id="pictureComments">
{if isset($comment_add)}
+2 -2
View File
@@ -23,7 +23,7 @@
{if $display_mode == 'cloud' and isset($tags)}
<div id="fullTagCloud">
{foreach from=$tags item=tag}
<span><a href="{$tag.URL}" class="tagLevel{$tag.level}" title="{$pwg->l10n_dec('%d photo', '%d photos', $tag.counter)}">{$tag.name}</a></span>
<span><a href="{$tag.URL}" class="tagLevel{$tag.level}" title="{$tag.counter|@translate_dec:'%d photo':'%d photos'}">{$tag.name}</a></span>
{/foreach}
</div>
{/if}
@@ -39,7 +39,7 @@
{foreach from=$letter.tags item=tag}
<tr class="tagLine">
<td><a href="{$tag.URL}" title="{$tag.name}">{$tag.name}</a></td>
<td class="nbEntries">{$pwg->l10n_dec('%d photo', '%d photos', $tag.counter)}</td>
<td class="nbEntries">{$tag.counter|@translate_dec:'%d photo':'%d photos'}</td>
</tr>
{/foreach}
</table>