function i18nTrans($operatorName, &$node, $tpl, &$resourceData, $element, $lastElement, $elementList, $elementTree, &$parameters) { // i18n( $input, $context, $comment, $arguments ) // Check if if the three first parameters are constants, if not we cannot compile it foreach (array_slice($parameters, 0, 3) as $parameter) { if ($parameter !== null && !eZTemplateNodeTool::isConstantElement($parameter)) { return false; } } $value = eZTemplateNodeTool::elementConstantValue($parameters[0]); $numParameters = count($parameters); $context = $numParameters > 1 ? eZTemplateNodeTool::elementConstantValue($parameters[1]) : null; $comment = $numParameters > 2 ? eZTemplateNodeTool::elementConstantValue($parameters[2]) : null; if ($numParameters < 4) { return array(eZTemplateNodeTool::createStringElement(ezpI18n::tr($context, $value, $comment, null))); } $values = array(); $ini = eZINI::instance(); if ($ini->variable('RegionalSettings', 'TextTranslation') != 'disabled') { $language = eZLocale::instance()->localeFullCode(); if ($language != "eng-GB") { $file = 'translation.ts'; $ini = eZINI::instance(); $useCache = $ini->variable('RegionalSettings', 'TranslationCache') != 'disabled'; eZTSTranslator::initialize($context, $language, $file, $useCache); $man = eZTranslatorManager::instance(); $newValue = $man->translate($context, $value, $comment); if ($newValue) { $value = $newValue; } } } $values[] = array(eZTemplateNodeTool::createStringElement($value)); $values[] = $parameters[3]; $code = '%tmp1% = array();' . "\n" . 'foreach ( %2% as %tmp2% => %tmp3% )' . "\n" . '{' . "\n" . ' if ( is_int( %tmp2% ) )' . "\n" . ' %tmp1%[\'%\' . ( (%tmp2%%9) + 1 )] = %tmp3%;' . "\n" . ' else' . "\n" . ' %tmp1%[%tmp2%] = %tmp3%;' . "\n" . '}' . "\n" . '%output% = strtr( %1%, %tmp1% );' . "\n"; return array(eZTemplateNodeTool::createCodePieceElement($code, $values, false, 3)); }
/** * Translates the source \a $source with context \a $context and optional comment \a $comment * and returns the translation if locale code is not eng-GB. * Uses {@link eZTranslatorMananger::translate()} to do the actual translation * * Example: * translateText( 'content/view', 'There are %count nodes in this list out of %total total nodes.', 'Children view of nodes for whole site', array( '%count' => $c, '%total' => $t ) ); * * @param string $context * @param string $source * @param string|null $comment * @param array|null $arguments * @return string */ protected static function translateText($context, $source, $comment = null, $arguments = null) { $localeCode = eZLocale::instance()->localeFullCode(); if ($localeCode == 'eng-GB') { // we don't have ts-file for 'eng-GB'. return self::insertArguments($source, $arguments); } $ini = eZINI::instance(); $useCache = $ini->variable('RegionalSettings', 'TranslationCache') != 'disabled'; eZTSTranslator::initialize($context, $localeCode, 'translation.ts', $useCache); // Bork translation: Makes it easy to see what is not translated. // If no translation is found in the eZTSTranslator, a Bork translation will be returned. // Bork is different than, but similar to, eng-GB, and is enclosed in square brackets []. $developmentMode = $ini->variable('RegionalSettings', 'DevelopmentMode') != 'disabled'; if ($developmentMode) { eZBorkTranslator::initialize(); } $man = eZTranslatorManager::instance(); $trans = $man->translate($context, $source, $comment); if ($trans !== null) { return self::insertArguments($trans, $arguments); } if ($comment != null and strlen($comment) > 0) { eZDebug::writeDebug("Missing translation for message in context: '{$context}' with comment: '{$comment}'. The untranslated message is: '{$source}'", __METHOD__); } else { eZDebug::writeDebug("Missing translation for message in context: '{$context}'. The untranslated message is: '{$source}'", __METHOD__); } return self::insertArguments($source, $arguments); }