Author: dr Date: Wed Feb 13 17:15:38 2008 New Revision: 7360 Log: - Added support for the keepObsolete option for the TsBackend. With this enabled, the obsolete translations are not dropped while reading contexts. This is both useful for testing as well as for manipulating TS files. - Increase test-coverage. - Make sure to check for a working writer when calling storeContext() and deinitWriter().
Modified: trunk/Translation/ChangeLog trunk/Translation/src/backends/ts_backend.php trunk/Translation/src/options/ts_backend.php trunk/Translation/tests/translation_backend_ts_test.php Modified: trunk/Translation/ChangeLog ============================================================================== --- trunk/Translation/ChangeLog [iso-8859-1] (original) +++ trunk/Translation/ChangeLog [iso-8859-1] Wed Feb 13 17:15:38 2008 @@ -7,6 +7,9 @@ component. - Implemented issue #10912: Add translation entries. - Added support for the new location element in Linguist version 1.1 files. +- Added support for the keepObsolete option for the TsBackend. With this + enabled, the obsolete translations are not dropped while reading contexts. + This is both useful for testing as well as for manipulating TS files. 1.1.6 - Wednesday 05 December 2007 Modified: trunk/Translation/src/backends/ts_backend.php ============================================================================== --- trunk/Translation/src/backends/ts_backend.php [iso-8859-1] (original) +++ trunk/Translation/src/backends/ts_backend.php [iso-8859-1] Wed Feb 13 17:15:38 2008 @@ -282,7 +282,14 @@ } else if ( $message->translation['type'] == 'obsolete' ) { - return null; + if ( $this->options->keepObsolete ) + { + $status = ezcTranslationData::OBSOLETE; + } + else + { + return null; + } } $source = trim( (string) $message->source ); @@ -400,13 +407,6 @@ { throw new ezcTranslationWriterNotInitializedException(); } - foreach ( $data as $key => $cachedElement ) - { - if ( $cachedElement->status == ezcTranslationData::OBSOLETE ) - { - unset( $data[$key] ); - } - } $dom = $this->dom; $root = $dom->getElementsByTagName( 'TS' )->item( 0 ); @@ -499,6 +499,10 @@ */ public function deinitWriter() { + if ( is_null( $this->dom ) ) + { + throw new ezcTranslationWriterNotInitializedException(); + } $filename = $this->buildTranslationFileName( $this->writeLocale ); $this->dom->save( $filename ); } Modified: trunk/Translation/src/options/ts_backend.php ============================================================================== --- trunk/Translation/src/options/ts_backend.php [iso-8859-1] (original) +++ trunk/Translation/src/options/ts_backend.php [iso-8859-1] Wed Feb 13 17:15:38 2008 @@ -24,6 +24,9 @@ * filename for the translation file to be * "translations/nl_NL.xml" if the nl_NL locale is * requested. + * @property bool $keepObsolete + * When this option is set to "true" the reader will not drop + * translation messages with the "obsolete" type set. * * @package Translation * @version //autogentag// @@ -46,6 +49,7 @@ public function __construct( $array = array() ) { $this->properties['format'] = '[LOCALE].xml'; + $this->properties['keepObsolete'] = false; parent::__construct( $array ); } @@ -72,6 +76,7 @@ } break; case 'format': + case 'keepObsolete': break; default: throw new ezcBaseSettingNotFoundException( $propertyName ); Modified: trunk/Translation/tests/translation_backend_ts_test.php ============================================================================== --- trunk/Translation/tests/translation_backend_ts_test.php [iso-8859-1] (original) +++ trunk/Translation/tests/translation_backend_ts_test.php [iso-8859-1] Wed Feb 13 17:15:38 2008 @@ -216,6 +216,19 @@ self::assertEquals( $expected, $context ); } + public function testGetContextKeepObsolete() + { + $currentDir = dirname( __FILE__ ); + $backend = new ezcTranslationTsBackend( "{$currentDir}/files/translations" ); + $backend->setOptions( array ( 'format' => '[LOCALE].xml', 'keepObsolete' => true ) ); + $context = $backend->getContext( 'nl-nl', 'design/admin/collaboration/group_tree' ); + + $expected = array( + new ezcTranslationData( 'Groups', 'Groepen', false, ezcTranslationData::OBSOLETE ) + ); + self::assertEquals( $expected, $context ); + } + public function testGetMissingContext() { $currentDir = dirname( __FILE__ ); @@ -461,6 +474,56 @@ self::assertEquals( $expected, $context ); } + public function testNonInitWriter1() + { + $currentDir = dirname( __FILE__ ); + + // cp for test + copy( "{$currentDir}/files/translations/nb-no.xml", "{$currentDir}/files/translations/nb-no.test.xml" ); + + $backend = new ezcTranslationTsBackend( "{$currentDir}/files/translations" ); + $context = array(); + $context[] = new ezcTranslationData( 'Test string to be added', 'Test string die wordt toegevoegd', 'comment', ezcTranslationData::TRANSLATED, 'test.ezt', 5 ); + + unlink( "{$currentDir}/files/translations/nb-no.test.xml" ); + + $backend->setOptions( array ( 'format' => '[LOCALE].test.xml' ) ); + try + { + $backend->storeContext( 'number_two', $context ); + self::assertEquals( "Expected exception not thrown." ); + } + catch ( ezcTranslationWriterNotInitializedException $e ) + { + self::assertEquals( "The writer is not initialized with the initWriter() method.", $e->getMessage() ); + } + } + + public function testNonInitWriter2() + { + $currentDir = dirname( __FILE__ ); + + // cp for test + copy( "{$currentDir}/files/translations/nb-no.xml", "{$currentDir}/files/translations/nb-no.test.xml" ); + + $backend = new ezcTranslationTsBackend( "{$currentDir}/files/translations" ); + $context = array(); + $context[] = new ezcTranslationData( 'Test string to be added', 'Test string die wordt toegevoegd', 'comment', ezcTranslationData::TRANSLATED, 'test.ezt', 5 ); + + unlink( "{$currentDir}/files/translations/nb-no.test.xml" ); + + $backend->setOptions( array ( 'format' => '[LOCALE].test.xml' ) ); + try + { + $backend->deinitWriter(); + self::assertEquals( "Expected exception not thrown." ); + } + catch ( ezcTranslationWriterNotInitializedException $e ) + { + self::assertEquals( "The writer is not initialized with the initWriter() method.", $e->getMessage() ); + } + } + public function testChangeTranslation1() { $currentDir = dirname( __FILE__ ); @@ -509,6 +572,31 @@ self::assertEquals( $expected, $context ); } + 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 static function suite() { return new PHPUnit_Framework_TestSuite( "ezcTranslationTsBackendTest" ); -- svn-components mailing list svn-components@lists.ez.no http://lists.ez.no/mailman/listinfo/svn-components