Example #1
0
require_once 'HTML/Template/Xipe/Filter/Translate.php';
$DB_DSN = 'mysql://root@localhost/test';
$translator = new I18N_Messages_Translate($DB_DSN, array('tablePrefix' => 'translate_'));
function translateAndPrint($string)
{
    global $translator, $lang;
    $translated = $translator->simpleTranslate($string, $lang);
    // only translate exact matches
    echo $translated;
}
if (@$_REQUEST['lang']) {
    $lang = $_REQUEST['lang'];
} else {
    $lang = 'en';
}
$tpl->setOption('locale', $lang);
$tpl->registerPostfilter(array(&$translator, 'translateMarkUpString'), $lang);
// this filter translates PHP-generated text
// it simply does out of < ? =$text ? >  this < ? =translateAndPrint($text) ? >
// but only within the $translator->possibleMarkUpDelimiters, so not every
// < ?= is translated !!! since that is not wanted anyway,
// i.e. think of "<td colspan={$colspan}>" - doesnt need translation
$translateFilter = new HTML_Template_Xipe_Filter_Translate($tpl->getOptions());
// this filter will only translate PHP-variables that start with 'T_', i.e. $T_foo
// but not $foo as the method above would
$tpl->registerPostfilter(array(&$translateFilter, 'translateMarkedOnly'), array('translateAndPrint', 'T_'));
//
//   fill variables used in the template
//   no assign-method necessary
//
$repeatValue = 3;