Exemplo n.º 1
0
 /**
  * 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);
 }
Exemplo n.º 2
0
    /**
     * 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 );
    }