gettext translations (block.t.php) with Smarty 3.17 prepends pofile header in every translated message

107 views
Skip to first unread message

Francisco Diéguez

unread,
Jan 18, 2012, 10:01:58 AM1/18/12
to Smarty Developers
Hi all,

I have a weird issue with the block {t}{/t} in Smarty 3.1.7. This
block was working with Smarty 3.0.
For every single message that handles the block, smarty always
prepends the po file header:

Project-Id-Version: onmadmin 0.8
Report-Msgid-Bugs-To:
POT-Creation-Date: 2012-01-18 15:31+0100
PO-Revision-Date: 2012-01-03 13:34+0100
Last-Translator: #######
Language-Team: ####
Language: gl_ES
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Plural-Forms: nplurals=2; plural=(n!=1);


If I put my application in english (no translations) all works like a
charm.

Here is the code for from block.t.php (I have stripped php coments for
making this message shorter)
<?php
function smarty_gettext_strarg($str)
{
$tr = array();
$p = 0;

for ($i=1; $i < func_num_args(); $i++) {
$arg = func_get_arg($i);

if (is_array($arg)) {
foreach ($arg as $aarg) {
$tr['%'.++$p] = $aarg;
}
} else {
$tr['%'.++$p] = $arg;
}
}

return strtr($str, $tr);
}


function smarty_block_t($params, $text, &$smarty)
{
$text = stripslashes($text);

// set escape mode
if (isset($params['escape'])) {
$escape = $params['escape'];
unset($params['escape']);
}

// set plural version
if (isset($params['plural'])) {
$plural = $params['plural'];
unset($params['plural']);

// set count
if (isset($params['count'])) {
$count = $params['count'];
unset($params['count']);
}
}

// use plural if required parameters are set
if (isset($count) && isset($plural)) {
$text = ngettext($text, $plural, $count);
} else { // use normal
$text = gettext($text);
}

// run strarg if there are parameters
if (count($params)) {
$text = smarty_gettext_strarg($text, $params);
}

if (!isset($escape) || $escape == 'html') { // html escape,
default
$text = nl2br(htmlspecialchars($text));
} elseif (isset($escape)) {
switch ($escape) {
case 'javascript':
case 'js':
// javascript escape
$text = str_replace('\'', '\\\'',
stripslashes($text));
break;
case 'url':
// url escape
$text = urlencode($text);
break;
}
}

return $text;
}

uwe.tews

unread,
Feb 2, 2012, 10:08:16 AM2/2/12
to Smarty Developers
This was already answered here
http://groups.google.com/group/smarty-developers/browse_thread/thread/43c1d435b2a61954?hl=en


On Jan 18, 4:01 pm, Francisco Diéguez <fran.dieg...@mabishu.com>
wrote:
Reply all
Reply to author
Forward
0 new messages