static function initialize()
 {
     if (!isset($GLOBALS['eZ1337Translator']) || !$GLOBALS['eZ1337Translator'] instanceof eZ1337Translator) {
         $GLOBALS['eZ1337Translator'] = new eZ1337Translator();
     }
     $man = eZTranslatorManager::instance();
     $man->registerHandler($GLOBALS['eZ1337Translator']);
     return $GLOBALS['eZ1337Translator'];
 }
 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));
 }
 function findMessage( $context, $source, $comment = null )
 {
     $man = eZTranslatorManager::instance();
     $translation = $this->shuffleText( $source );
     return $man->createMessage( $context, $source, $comment, $translation );
 }
 /**
  * Removes the translation message with context $context and source $source.
  *
  * If you have the translation key use removeKey() instead.
  *
  * @param string $context
  * @param string $source
  * @param string $message
  *
  * @return bool true if the message was removed, false otherwise
  */
 function remove($context, $source, $message = null)
 {
     if ($context == "") {
         $context = "default";
     }
     $man = eZTranslatorManager::instance();
     $key = $man->createKey($context, $source, $message);
     if (isset($this->Messages[$key])) {
         unset($this->Messages[$key]);
     }
 }
 /**
  * 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);
 }
Exemple #6
0
 static function registerHandler($handler)
 {
     $instance = eZTranslatorManager::instance();
     $instance->Handlers[] = $handler;
 }
    static function initialize( $context, $locale, $useCache = true )
    {
        if ( !isset( $GLOBALS['eZBorkTranslator'] ) ||
             !( $GLOBALS['eZBorkTranslator'] instanceof eZBorkTranslator ) )
        {
            $GLOBALS['eZBorkTranslator'] = new eZBorkTranslator();
        }

        $man = eZTranslatorManager::instance();
        $man->registerHandler( $GLOBALS['eZBorkTranslator'] );
        return $GLOBALS['eZBorkTranslator'];
    }
    /**
     * 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 );
        }

        // Load all TranslatorHandlers from settings
        $ini = eZINI::instance();
        $useCache = $ini->variable( 'RegionalSettings', 'TranslationCache' ) != 'disabled';
        $handlerClassList = $ini->variable( 'RegionalSettings', 'TranslatorHandlers' );
        foreach( $handlerClassList as $handlerClass )
        {
            call_user_func_array( array( $handlerClass, 'initialize' ), array( $context, $localeCode, $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 && ! in_array( 'eZBorkTranslator', $handlerClassList ) )
        {
            eZBorkTranslator::initialize( $context, $localeCode, $useCache );
        }

        $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 );
    }