<?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');
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); }
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); }