Author: Derick Rethans
Date: 2006-01-25 15:52:48 +0100 (Wed, 25 Jan 2006)
New Revision: 2028
Log:
- Fixed behavior of Bork and Leet filters to work on the translated string,
and not on the original string.
- Fixed replacing in Leet filter to not to touch parameters identifiers in the
translated string.
- Updated test-cases.
Modified:
packages/Translation/trunk/src/filters/bork_filter.php
packages/Translation/trunk/src/filters/leet_filter.php
packages/Translation/trunk/tests/translation_filter_borkify_test.php
packages/Translation/trunk/tests/translation_filter_leetify_test.php
packages/Translation/trunk/tests/translation_manager_test.php
Modified: packages/Translation/trunk/src/filters/bork_filter.php
===================================================================
--- packages/Translation/trunk/src/filters/bork_filter.php 2006-01-25
14:51:20 UTC (rev 2027)
+++ packages/Translation/trunk/src/filters/bork_filter.php 2006-01-25
14:52:48 UTC (rev 2028)
@@ -68,7 +68,7 @@
);
$text = preg_replace( $searchMap, $replaceMap, $text );
- if ( $orgtext == $text )
+ if ( $orgtext == $text && count( $newTextBlocks ) )
{
$text .= '-a';
}
@@ -93,7 +93,7 @@
{
foreach ( $context as $element )
{
- $element->translation = self::borkify( $element->original );
+ $element->translation = self::borkify( $element->translation );
}
}
}
Modified: packages/Translation/trunk/src/filters/leet_filter.php
===================================================================
--- packages/Translation/trunk/src/filters/leet_filter.php 2006-01-25
14:51:20 UTC (rev 2027)
+++ packages/Translation/trunk/src/filters/leet_filter.php 2006-01-25
14:52:48 UTC (rev 2028)
@@ -45,7 +45,21 @@
{
$searchMap = array( '/to/i', '/for/i', '/ate/i', '/your/i', '/you/i',
'/l/i', '/e/i', '/o/i', '/a/i', '/t/i' );
$replaceMap = array( '2', '4', '8', 'ur', 'u', '1', '3', '0', '4', '7'
);
- $text = preg_replace( $searchMap, $replaceMap, $text );
+
+ $textBlocks = preg_split( '/(%[^ ]+)/', $text, -1,
PREG_SPLIT_DELIM_CAPTURE );
+ $newTextBlocks = array();
+ foreach ( $textBlocks as $text )
+ {
+ if ( strlen( $text ) && $text[0] == '%' )
+ {
+ $newTextBlocks[] = $text;
+ continue;
+ }
+ $text = preg_replace( $searchMap, $replaceMap, $text );
+
+ $newTextBlocks[] = $text;
+ }
+ $text = implode( '', $newTextBlocks );
return $text;
}
@@ -62,7 +76,7 @@
{
foreach ( $context as $element )
{
- $element->translation = self::leetify( $element->original );
+ $element->translation = self::leetify( $element->translation );
}
}
}
Modified: packages/Translation/trunk/tests/translation_filter_borkify_test.php
===================================================================
--- packages/Translation/trunk/tests/translation_filter_borkify_test.php
2006-01-25 14:51:20 UTC (rev 2027)
+++ packages/Translation/trunk/tests/translation_filter_borkify_test.php
2006-01-25 14:52:48 UTC (rev 2028)
@@ -22,7 +22,7 @@
$context[] = new ezcTranslationData( "Group list for '%1'",
"Groeplijst voor %1", false, ezcTranslationData::TRANSLATED );
$expected = array();
- $expected[] = new ezcTranslationData( "Group list for '%1'", "[Groop
leest for '%1'-a]", false, ezcTranslationData::TRANSLATED );
+ $expected[] = new ezcTranslationData( "Group list for '%1'",
"[Groepleejst foor %1-a]", false, ezcTranslationData::TRANSLATED );
$bork->runFilter( $context );
self::assertEquals( $expected, $context );
@@ -61,7 +61,7 @@
$bork = ezcTranslationBorkFilter::getInstance();
$context = array();
- $context[] = new ezcTranslationData( 'Via an auto gehen few goof',
"[Veea un ooto gehee foo gooff]", false, ezcTranslationData::TRANSLATED );
+ $context[] = new ezcTranslationData( 'Via an auto gehen few goof',
"Via an auto gehen few goof", false, ezcTranslationData::TRANSLATED );
$expected = array();
$expected[] = new ezcTranslationData( 'Via an auto gehen few goof',
"[Veea un ooto gehee foo gooff]", false, ezcTranslationData::TRANSLATED );
@@ -75,7 +75,7 @@
$bork = ezcTranslationBorkFilter::getInstance();
$context = array();
- $context[] = new ezcTranslationData( 'Vi gir sow phone booth', "[Vee
gur soo fone boot]", false, ezcTranslationData::TRANSLATED );
+ $context[] = new ezcTranslationData( 'Vi gir sow phone booth', "Vi gir
sow phone booth", false, ezcTranslationData::TRANSLATED );
$expected = array();
$expected[] = new ezcTranslationData( 'Vi gir sow phone booth', "[Vee
gur soo fone boot]", false, ezcTranslationData::TRANSLATED );
@@ -89,7 +89,7 @@
$bork = ezcTranslationBorkFilter::getInstance();
$context = array();
- $context[] = new ezcTranslationData( 'Attention! Ku Ut sy veg weg',
"[Attenshun Koo Oot sai feg veg!]", false, ezcTranslationData::TRANSLATED );
+ $context[] = new ezcTranslationData( 'Attention! Ku Ut sy veg weg',
"Attention! Ku Ut sy veg weg", false, ezcTranslationData::TRANSLATED );
$expected = array();
$expected[] = new ezcTranslationData( 'Attention! Ku Ut sy veg weg',
"[Attenshun Koo Oot sai feg veg!]", false, ezcTranslationData::TRANSLATED );
@@ -98,6 +98,20 @@
self::assertEquals( $expected, $context );
}
+ public function testGetContextWithFilter7()
+ {
+ $leet = ezcTranslationBorkFilter::getInstance();
+
+ $context = array();
+ $context[] = new ezcTranslationData( "The %fruit is round.", "%Fruit
er rund.", false, ezcTranslationData::TRANSLATED );
+
+ $expected = array();
+ $expected[] = new ezcTranslationData( "The %fruit is round.", "[%Fruit
er roond.]", false, ezcTranslationData::TRANSLATED );
+
+ $leet->runFilter( $context );
+ self::assertEquals( $expected, $context );
+ }
+
public static function suite()
{
return new ezcTestSuite( "ezcTranslationFilterBorkifyTest" );
Modified: packages/Translation/trunk/tests/translation_filter_leetify_test.php
===================================================================
--- packages/Translation/trunk/tests/translation_filter_leetify_test.php
2006-01-25 14:51:20 UTC (rev 2027)
+++ packages/Translation/trunk/tests/translation_filter_leetify_test.php
2006-01-25 14:52:48 UTC (rev 2028)
@@ -19,7 +19,7 @@
$leet = ezcTranslationLeetFilter::getInstance();
$context = array();
- $context[] = new ezcTranslationData( "Group list for you", false,
false, ezcTranslationData::TRANSLATED );
+ $context[] = new ezcTranslationData( "Group list for you", "Group list
for you", false, ezcTranslationData::TRANSLATED );
$expected = array();
$expected[] = new ezcTranslationData( "Group list for you", "Gr0up
1is7 4 u", false, ezcTranslationData::TRANSLATED );
@@ -33,7 +33,7 @@
$leet = ezcTranslationLeetFilter::getInstance();
$context = array();
- $context[] = new ezcTranslationData( 'No items to group.', false,
false, ezcTranslationData::TRANSLATED );
+ $context[] = new ezcTranslationData( 'No items to group.', "No items
to group.", false, ezcTranslationData::TRANSLATED );
$expected = array();
$expected[] = new ezcTranslationData( 'No items to group.', 'N0 i73ms
2 gr0up.', false, ezcTranslationData::TRANSLATED );
@@ -47,7 +47,7 @@
$leet = ezcTranslationLeetFilter::getInstance();
$context = array();
- $context[] = new ezcTranslationData( "You ate a cookie", false, false,
ezcTranslationData::TRANSLATED );
+ $context[] = new ezcTranslationData( "You ate a cookie", "You ate a
cookie", false, ezcTranslationData::TRANSLATED );
$expected = array();
$expected[] = new ezcTranslationData( "You ate a cookie", "u 8 4
c00ki3", false, ezcTranslationData::TRANSLATED );
@@ -55,6 +55,21 @@
$leet->runFilter( $context );
self::assertEquals( $expected, $context );
}
+
+ public function testGetContextWithFilter4()
+ {
+ $leet = ezcTranslationLeetFilter::getInstance();
+
+ $context = array();
+ $context[] = new ezcTranslationData( "The %fruit is round.", "%Fruit
er rund.", false, ezcTranslationData::TRANSLATED );
+
+ $expected = array();
+ $expected[] = new ezcTranslationData( "The %fruit is round.", "%Fruit
3r rund.", false, ezcTranslationData::TRANSLATED );
+
+ $leet->runFilter( $context );
+ self::assertEquals( $expected, $context );
+ }
+
public static function suite()
{
return new ezcTestSuite( "ezcTranslationFilterLeetifyTest" );
Modified: packages/Translation/trunk/tests/translation_manager_test.php
===================================================================
--- packages/Translation/trunk/tests/translation_manager_test.php
2006-01-25 14:51:20 UTC (rev 2027)
+++ packages/Translation/trunk/tests/translation_manager_test.php
2006-01-25 14:52:48 UTC (rev 2028)
@@ -67,6 +67,29 @@
self::assertEquals( $expected, $context );
}
+ public function testGetContextWithFilters()
+ {
+ $currentDir = dirname( __FILE__ );
+ $backend = new ezcTranslationTsBackend(
"{$currentDir}/files/translations" );
+ $backend->setOptions( array ( 'format' => '[LOCALE].xml' ) );
+
+ $fillin = ezcTranslationComplementEmptyFilter::getInstance();
+ $bork = ezcTranslationBorkFilter::getInstance();
+
+ $trm = new ezcTranslationManager( $backend );
+ $trm->addFilter( $fillin );
+ $trm->addFilter( $bork );
+ $context = $trm->getContext( 'nl-nl',
'design/admin/content/browse_bookmark' );
+
+ $expected = array();
+ $expected[] = new ezcTranslationData( "Choose items to bookmark",
"[Keees items oom toe te foegee eun uv feforeeetee]", false,
ezcTranslationData::TRANSLATED );
+ $expected[] = new ezcTranslationData( "Select the items that you want
to bookmark using the checkboxes and click \"OK\".", "[Select the items thet
yoo vunt to bookmerk useeng the checkboxes und cleeck \"OK\".]", false,
ezcTranslationData::UNFINISHED );
+ $expected[] = new ezcTranslationData( "Navigate using the available
tabs (above), the tree menu (left) and the content list (middle).", "[Nefeegete
useeng the efeeeleble tebs (ebofe), the tree menoo (lefft) und the content
leest (meeddle).]", false, ezcTranslationData::UNFINISHED );
+ $expected = new ezcTranslation( $expected );
+
+ self::assertEquals( $expected, $context );
+ }
+
public function testGetContextWithObsolete()
{
$currentDir = dirname( __FILE__ );
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components