private function translateFromXML($context, $string, $params = array())
 {
     $sys = erLhcoreClassSystem::instance()->SiteDir;
     $reader = new ezcTranslationTsBackend($sys . '/translations/' . $this->languageCode);
     $reader->setOptions(array('format' => 'translation.ts'));
     $manager = new ezcTranslationManager($reader);
     $ContextTranslation = $manager->getContext($this->languageCode, $context);
     return $ContextTranslation->getTranslation($string, $params);
 }
 public function testAddTranslation4()
 {
     $currentDir = dirname(__FILE__);
     $backend = new ezcTranslationTsBackend("{$currentDir}/files/translations");
     $backend->setOptions(array('format' => '[LOCALE].xml'));
     $context = $backend->getContext('nb-no', 'contentstructuremenu/show_content_structure');
     $context[] = new ezcTranslationData('Node ID: %node_id Visibility: %visibility', 'Test string die wordt toegevoegd', 'comment', ezcTranslationData::OBSOLETE, 'test.ezt', 5);
     $context[] = new ezcTranslationData('Test string to be added', 'Test string die wordt toegevoegd', 'comment', ezcTranslationData::UNFINISHED, 'test.ezt', 6);
     $backend->setOptions(array('format' => '[LOCALE].test.xml', 'keepObsolete' => true));
     $backend->initWriter('nb-no');
     $backend->storeContext('contentstructuremenu/show_content_structure', $context);
     $backend->deinitWriter();
     $context = $backend->getContext('nb-no', 'contentstructuremenu/show_content_structure');
     unlink("{$currentDir}/files/translations/nb-no.test.xml");
     $expected = array(new ezcTranslationData('Node ID: %node_id Visibility: %visibility', 'Test string die wordt toegevoegd', 'comment', ezcTranslationData::OBSOLETE, 'test.ezt', 5), new ezcTranslationData('Test string to be added', 'Test string die wordt toegevoegd', 'comment', ezcTranslationData::UNFINISHED, 'test.ezt', 6));
     self::assertEquals($expected, $context);
 }
            $arrayTranslationsProcess[$section][] = $Matches[2][$key];
        }
        $contentFile = str_replace($Matches[0][$key], '', $contentFile);
    }
    $Matches = array();
    preg_match_all('/erTranslationClassLhTranslation::getInstance\\(\\)->getTranslation\\(\'(.*?)\',\'(.*?)\'\\)/i', $contentFile, $Matches);
    foreach ($Matches[1] as $key => $section) {
        if (!isset($arrayTranslationsProcess[$section])) {
            $arrayTranslationsProcess[$section] = array();
        }
        if (!in_array($Matches[2][$key], $arrayTranslationsProcess[$section])) {
            $arrayTranslationsProcess[$section][] = $Matches[2][$key];
        }
    }
}
$reader = new ezcTranslationTsBackend($cronjobPathOption->value . '/doc');
$reader->setOptions(array('format' => 'default.ts'));
$reader->initReader($locale);
$manager = new ezcTranslationManager($reader);
function translateToLanguage($apiKey, $toLanguage, $string)
{
    return '';
}
foreach ($arrayTranslationsProcess as $context => $itemsToTranslate) {
    $contextItems = array();
    try {
        $contextItem = $manager->getContext($locale, $context);
    } catch (Exception $e) {
        // Context does not exists
        $reader->initWriter($locale);
        $reader->storeContext($context, $contextItems);
 public function testGetContextMissing()
 {
     $currentDir = dirname(__FILE__);
     $backend = new ezcTranslationTsBackend("{$currentDir}/files/translations");
     $backend->setOptions(array('format' => '[LOCALE].xml'));
     $fillin = ezcTranslationComplementEmptyFilter::getInstance();
     $trm = new ezcTranslationManager($backend);
     $trm->addFilter($fillin);
     try {
         $context = $trm->getContext('nl-nl', 'design/admin/collaboration/admin/view/summary');
         self::fail('Expected Exception was not thrown');
     } catch (ezcTranslationContextNotAvailableException $e) {
         self::assertEquals("The context 'design/admin/collaboration/admin/view/summary' does not exist.", $e->getMessage());
     }
 }
Example #5
0
 public function testRunRegression($directory)
 {
     $template = new ezcTemplate();
     $dir = dirname($directory);
     $base = basename($directory);
     $template->configuration = new ezcTemplateConfiguration($dir, $this->getTempDir());
     $template->configuration->targetCharset = "Latin1";
     $template->configuration->translation = ezcTemplateTranslationConfiguration::getInstance();
     $template->configuration->translation->locale = 'en_us';
     $backend = new ezcTranslationTsBackend(dirname(__FILE__) . '/translations');
     $backend->setOptions(array('format' => '[LOCALE].xml'));
     $manager = new ezcTranslationManager($backend);
     $template->configuration->translation->manager = $manager;
     // $template->configuration->cachePath = $this->getTempDir() . "/cached";
     // $template->configuration->cachePath = "/tmp/cache";
     /*
         if ( !is_dir( $template->configuration->cachePath ) )
         {
             mkdir( $template->configuration->cachePath);
         }
     */
     $template->configuration->addExtension("TestBlocks");
     $template->configuration->addExtension("LinksCustomBlock");
     $template->configuration->addExtension("cblockTemplateExtension");
     $template->configuration->addExtension("Sha1CustomBlock");
     if (preg_match("#^(\\w+)@(\\w+)\\..*\$#", $base, $match)) {
         $contextClass = "ezcTemplate" . ucfirst(strtolower($match[2])) . "Context";
         $template->configuration->context = new $contextClass();
     } else {
         $template->configuration->context = new ezcTemplateNoContext();
     }
     $send = substr($directory, 0, -3) . ".send";
     if (file_exists($send)) {
         $template->send = (include $send);
     }
     $out = "";
     $exceptionText = "";
     try {
         $out = $template->process($base);
     } catch (Exception $e) {
         $out = $e->getMessage();
         $exceptionText = get_class($e) . "(" . $e->getCode() . "):\n" . $out;
         // Begin of the error message contains the full path. We replace this with 'mock' so that the
         // tests work on other systems as well.
         if (strncmp($out, $directory, strlen($directory)) == 0) {
             $out = "mock" . substr($out, strlen($directory));
         }
         $exceptionText .= "\n" . $e->getTraceAsString();
     }
     $expected = substr($directory, 0, -3) . ".out";
     if (!file_exists($expected)) {
         $help = "The out file: '{$expected}' could not be found.";
         if (!self::$skipMissingTests && $this->interactiveMode) {
             echo "\n", $help, "\n";
             self::interact($template, $directory, false, $out, $expected, $help, $exceptionText);
             return;
         } else {
             throw new PHPUnit_Framework_ExpectationFailedException($help);
         }
     }
     $expectedText = file_get_contents($expected);
     try {
         $this->assertEquals($expectedText, $out, "In:  <{$expected}>\nOut: <{$directory}>");
     } catch (PHPUnit_Framework_ExpectationFailedException $e) {
         $help = "The evaluated template <" . $this->regressionDir . "/current.tmp> differs ";
         $help .= "from the expected output: <{$expected}>.";
         if ($this->interactiveMode) {
             // Touch the file. It will be run first, next time.
             if (isset($_ENV['EZC_TEST_TEMPLATE_SORT']) && $_ENV['EZC_TEST_TEMPLATE_SORT'] == 'mtime') {
                 touch($directory);
             }
             $exceptionText = get_class($e) . "(" . $e->getCode() . "):\n" . $e->getMessage();
             $exceptionText .= "\n" . $e->getTraceAsString();
             echo "\n", $help, "\n";
             self::interact($template, $directory, file_get_contents($expected), $out, $expected, $help, $exceptionText);
             return;
         }
         // Rethrow with new and more detailed message
         throw new PHPUnit_Framework_ExpectationFailedException($help, $e->getComparisonFailure());
     }
     // check the receive variables.
     $receive = substr($directory, 0, -3) . ".receive";
     if (file_exists($receive)) {
         $expectedVar = (include $receive);
         $foundVar = $template->receive;
         $this->assertEquals($expectedVar, $foundVar, "Received variables does not match");
     }
 }
Example #6
0
<?php

require_once 'tutorial_autoload.php';
$backend = new ezcTranslationTsBackend(dirname(__FILE__) . '/translations');
$backend->setOptions(array('format' => 'translation-[LOCALE].xml'));
$manager = new ezcTranslationManager($backend);
$manager->addFilter(ezcTranslationComplementEmptyFilter::getInstance());
$headersContext = $manager->getContext('nl_NL', 'tutorial/headers');
echo $headersContext->getTranslation('header1'), "\n";
Example #7
0
<?php

require_once 'tutorial_autoload.php';
// copy so that we can play with the file
copy(dirname(__FILE__) . '/translations/mod-example-nl_NL.xml', '/tmp/mod-example-nl_NL.xml');
// setup the backend to read from /tmp
$backend = new ezcTranslationTsBackend('/tmp');
$backend->setOptions(array('format' => 'mod-example-[LOCALE].xml'));
// get the original context
$context = $backend->getContext('nl_NL', 'existing');
// the modifications
$context[] = new ezcTranslationData('added', 'toegevoeg', 'comment', ezcTranslationData::TRANSLATED);
$context[] = new ezcTranslationData('update with new translation', 'ingevuld', NULL, ezcTranslationData::TRANSLATED);
$context[] = new ezcTranslationData('update translation', 'bijgewerkt', NULL, ezcTranslationData::TRANSLATED);
$context[] = new ezcTranslationData('to obsolete', 'markeren als ongebruikt', NULL, ezcTranslationData::OBSOLETE);
// init the writer, and write the modified context
$backend->initWriter('nl_NL');
$backend->storeContext('existing', $context);
// create a new context and write it
$context = array();
$context[] = new ezcTranslationData('new string', 'nieuwe string', NULL, ezcTranslationData::TRANSLATED);
$backend->storeContext('new', $context);
// deinit the writer
$backend->deinitWriter();
// read the context again, while keeping obsolete strings
$backend->setOptions(array('keepObsolete' => true));
$context = $backend->getContext('nl_NL', 'existing');
// re-format the written file and show it
`cat /tmp/mod-example-nl_NL.xml | xmllint --format - > /tmp/formatted.xml`;
echo file_get_contents('/tmp/formatted.xml');
Example #8
0
<?php

require_once 'tutorial_autoload.php';
$backend = new ezcTranslationTsBackend(dirname(__FILE__) . '/translations');
$backend->setOptions(array('format' => 'translation-[LOCALE].xml'));
$backend->initReader('nb_NO');
foreach ($backend as $contextName => $contextData) {
    echo $contextName, "\n";
    foreach ($contextData as $context) {
        echo "\toriginal string:   {$context->original}\n";
        echo "\ttranslated string: {$context->translation}\n\n";
    }
}
Example #9
0
<?php

require_once 'tutorial_autoload.php';
$reader = new ezcTranslationTsBackend(dirname(__FILE__) . '/translations');
$reader->setOptions(array('format' => 'translation-[LOCALE].xml'));
$reader->initReader('nb_NO');
$cacheObj = new ezcCacheStorageFileArray(dirname(__FILE__) . '/translations-cache');
$writer = new ezcTranslationCacheBackend($cacheObj);
$writer->initWriter('nb_NO');
foreach ($reader as $contextName => $contextData) {
    $writer->storeContext($contextName, $contextData);
}
$reader->deInitReader();
$writer->deInitWriter();
Example #10
0
 public function testUnObsolete()
 {
     copy('TemplateTranslationTiein/tests/test_files/extractor/test-new-elements/original.xml', "{$this->tmpDirTranslationFiles}/en.xml");
     $backend = new ezcTranslationTsBackend($this->tmpDirTranslationFiles, array('keepObsolete' => true));
     $context = $backend->getContext('en', 'test5');
     self::assertEquals('test2.ezt', $context[0]->filename);
     self::assertEquals('fourteen', $context[0]->original);
     self::assertEquals('thirteen', $context[0]->translation);
     self::assertEquals(2, $context[0]->status);
     self::assertEquals(6, $context[0]->line);
     $res = `php TemplateTranslationTiein/src/runextractor.php -t TemplateTranslationTiein/tests/test_files/extractor/templates {$this->tmpDirTranslationFiles}`;
     $context = $backend->getContext('en', 'test5');
     self::assertEquals('test2.ezt', $context[0]->filename);
     self::assertEquals('fourteen', $context[0]->original);
     self::assertEquals('thirteen', $context[0]->translation);
     self::assertEquals(0, $context[0]->status);
     self::assertEquals(10, $context[0]->line);
 }