I'm trying to port one of my applications to Smarty 3.1.7 (currently
using 3.0.8. All seems to work properly but if I try to use gettext
block.t.php plugin, Smarty outputs the translation string appended to
the po file header:
Project-Id-Version: applicationname 0.8
Report-Msgid-Bugs-To:
POT-Creation-Date: 2012-01-14 04:33+0100
PO-Revision-Date: 2012-01-03 13:33+0100
Last-Translator: Translator name <translatormail###>
Language-Team: Group name <groupmail###>
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);
THE TRANSLATED STRING GOES HERE
All the translations managed directly by php (using _()), without smarty
code involved, are showed perfectly but those using {t}Original
text{/t} have this error.
All the translations and code was working properly with Smarty 3.0.8 and
I have cleared all the APC caches, smarty compile and cache files.
Below is the smarty block.t.php plugin code without comments (this code
is the standard smarty block.t.php plugin).
<?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;
}
Cheers
--
Fran Di�guez
http://www.mabishu.com
GPG: 43DD 1B00 035F A764 4986 E695 98BB 6626 A2A4 F9B8
Do you think that is a good idea to use this plugin with Smarty 3.X?
Really thanks.
Fran Diéguez
http://www.mabishu.com
GPG: 43DD 1B00 035F A764 4986 E695 98BB 6626 A2A4 F9B8