Ejemplo n.º 1
0
 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));
 }
// file  bin/php/ezgeneratetranslationcache.php
/**************************************************************
* script initializing                                         *
***************************************************************/
require_once 'autoload.php';
$cli = eZCLI::instance();
$script = eZScript::instance(array('description' => "\n" . "This script will generate caches for translations.\n" . "Default usage: ./bin/php/ezgeneratetranslationcache -s setup\n", 'use-session' => false, 'use-modules' => true, 'use-extensions' => true, 'user' => true));
$script->startup();
$scriptOptions = $script->getOptions("[ts-list:]", "", array('ts-list' => "A list of translations to generate caches for, for example 'rus-RU nor-NO'\n" . "By default caches for all translations will be generated"), false, array('user' => true));
$script->initialize();
/**************************************************************
* process options                                             *
***************************************************************/
//
// 'ts-list' option
//
$translations = isset($scriptOptions['ts-list']) ? explode(' ', $scriptOptions['ts-list']) : array();
$translations = eZTSTranslator::fetchList($translations);
/**************************************************************
* do the work
***************************************************************/
$cli->output($cli->stylize('blue', "Processing: "), false);
$ini = eZINI::instance();
foreach ($translations as $translation) {
    $cli->output("{$translation->Locale} ", false);
    $ini->setVariable('RegionalSettings', 'Locale', $translation->Locale);
    eZTranslationCache::resetGlobals();
    $translation->load('');
}
$cli->output("", true);
$script->shutdown(0);
Ejemplo n.º 3
0
 /**
  * Clears the .ts translation cache
  * @param array $cacheItem
  * @return void
  */
 public static function clearTSTranslationCache($cacheItem)
 {
     eZTSTranslator::expireCache();
 }
Ejemplo n.º 4
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);
 }
Ejemplo n.º 5
0
 static function resetTranslations()
 {
     eZTranslatorManager::resetGlobals();
     eZTSTranslator::resetGlobals();
     eZLocale::resetGlobals();
     eZTranslationCache::resetGlobals();
 }
Ejemplo n.º 6
0
 /**
  * Expires the translation cache
  *
  * @param int $timestamp An optional timestamp cache should be exired from. Current timestamp used by default
  *
  * @return void
  */
 public static function expireCache($timestamp = false)
 {
     eZExpiryHandler::registerShutdownFunction();
     if ($timestamp === false) {
         $timestamp = time();
     }
     $handler = eZExpiryHandler::instance();
     $handler->setTimestamp(self::EXPIRY_KEY, $timestamp);
     $handler->store();
     self::$expiryTimestamp = $timestamp;
 }
Ejemplo n.º 7
0
    $script->shutdown( 1, "Translation file $translationFile does not exist" );

$cli->output( $cli->stylize( 'file', $translationFile ) . ":", false );
$cli->output( " loading", false );
$fd = fopen( $translationFile, "rb" );
$transXML = fread( $fd, filesize( $translationFile ) );
fclose( $fd );


$cli->output( " parsing", false );

$tree = new DOMDOcument();
$success = $tree->loadXML( $transXML );

$cli->output( " validating", false );
if ( !eZTSTranslator::validateDOMTree( $tree ) )
    $script->shutdown( 1, "XML text for file $translationFile did not validate" );


function handleContextNode( $context, $cli, $data )
{
    $contextName = null;
    $messages = array();
    $context_children = $context->childNodes;
    foreach ( $context_children as $context_child )
    {
        if ( $context_child->nodeType == XML_ELEMENT_NODE )
        {
            if ( $context_child->localName == "name" )
            {
                $data['context_count']++;