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);
 }
$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);
        $reader->deinitWriter();
        $contextItem = $manager->getContext($locale, $context);
    }
    foreach ($itemsToTranslate as $string) {
        if ($locale != 'en_EN') {
            try {
                $originalTranslation = $contextItem->getTranslation($string);
                if ($originalTranslation != '') {
                    $contextItems[] = new ezcTranslationData($string, $originalTranslation, NULL, ezcTranslationData::TRANSLATED);
                } else {
                    $contextItems[] = new ezcTranslationData($string, translateToLanguage($apiKey, substr($locale, 0, 2), $string), NULL, ezcTranslationData::UNFINISHED);
                }
            } catch (Exception $e) {
                // Translation does not exist
                $contextItems[] = new ezcTranslationData($string, translateToLanguage($apiKey, substr($locale, 0, 2), $string), NULL, ezcTranslationData::UNFINISHED);
            }
Example #3
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');