Skip to content
Browse files

updating gettext implementation of pluralRule

  • Loading branch information...
1 parent b806f13 commit 09cd81392384dd2c5dc12b3a63983129ac158471 @Howard3 Howard3 committed Feb 2, 2012
Showing with 9 additions and 46 deletions.
  1. +6 −3 g11n/catalog/adapter/Gettext.php
  2. +3 −43 tests/cases/g11n/catalog/adapter/GettextTest.php
View
9 g11n/catalog/adapter/Gettext.php
@@ -120,9 +120,12 @@ public function read($category, $locale, $scope) {
fclose($stream);
if ($data) {
- $data['pluralRule'] = function($count) {
- return $count != 1;
- };
+ $data['pluralRule'] = array(
+ 'id' => 'pluralRule',
+ 'translated' => function($count) {
+ return $count != 1;
+ }
+ );
return $data;
}
}
View
46 tests/cases/g11n/catalog/adapter/GettextTest.php
@@ -105,10 +105,7 @@ public function testReadPoSingleItem() {
)
);
$result = $this->adapter->read('message', 'de', null);
-
- $this->assertTrue(is_callable($result['pluralRule']));
unset($result['pluralRule']);
-
$this->assertEqual($expected, $result);
}
@@ -142,10 +139,7 @@ public function testReadPoMultipleItems() {
)
);
$result = $this->adapter->read('message', 'de', null);
-
- $this->assertTrue(is_callable($result['pluralRule']));
unset($result['pluralRule']);
-
$this->assertEqual($expected, $result);
}
@@ -170,8 +164,6 @@ public function testReadPoPlural() {
)
);
$result = $this->adapter->read('message', 'de', null);
-
- $this->assertTrue(is_callable($result['pluralRule']));
unset($result['pluralRule']);
$this->assertEqual($expected, $result);
@@ -215,10 +207,7 @@ public function testReadPoWithGnuHeader() {
)
);
$result = $this->adapter->read('message', 'de', null);
-
- $this->assertTrue(is_callable($result['pluralRule']));
unset($result['pluralRule']);
-
$this->assertEqual($expected, $result);
}
@@ -274,10 +263,7 @@ public function testReadAndWritePoWithFlagsAndComments() {
EOD;
file_put_contents($file, $po);
$result = $this->adapter->read('message', 'de', null);
-
- $this->assertTrue(is_callable($result['pluralRule']));
unset($result['pluralRule']);
-
$this->assertEqual($catalog, $result);
unlink($file);
@@ -319,10 +305,7 @@ public function testReadPoMultiline() {
)
);
$result = $this->adapter->read('message', 'de', null);
-
- $this->assertTrue(is_callable($result['pluralRule']));
unset($result['pluralRule']);
-
$this->assertEqual($expected, $result);
$file = "{$this->_path}/de/LC_MESSAGES/default.po";
@@ -349,10 +332,7 @@ public function testReadPoMultiline() {
)
);
$result = $this->adapter->read('message', 'de', null);
-
- $this->assertTrue(is_callable($result['pluralRule']));
unset($result['pluralRule']);
-
$this->assertEqual($expected, $result);
$data = <<<EOD
@@ -388,10 +368,7 @@ public function testReadPoMultiline() {
)
);
$result = $this->adapter->read('message', 'de', null);
-
- $this->assertTrue(is_callable($result['pluralRule']));
unset($result['pluralRule']);
-
$this->assertEqual($expected, $result);
}
@@ -405,10 +382,7 @@ public function testReadPoLongIdsAndTranslations() {
file_put_contents($file, $data);
$result = $this->adapter->read('message', 'de', null);
-
- $this->assertTrue(is_callable($result['pluralRule']));
unset($result['pluralRule']);
-
$this->assertTrue(isset($result[$dummy]));
$data = <<<EOD
@@ -418,10 +392,7 @@ public function testReadPoLongIdsAndTranslations() {
file_put_contents($file, $data);
$result = $this->adapter->read('message', 'de', null);
-
- $this->assertTrue(is_callable($result['pluralRule']));
unset($result['pluralRule']);
-
$this->assertEqual($result['singular 1']['translated'], $dummy);
}
@@ -458,10 +429,7 @@ public function testReadMoLittleEndian() {
)
);
$result = $this->adapter->read('message', 'de', null);
-
- $this->assertTrue(is_callable($result['pluralRule']));
unset($result['pluralRule']);
-
$this->assertEqual($expected, $result);
}
@@ -549,15 +517,11 @@ public function testWriteReadPo() {
$this->adapter->write('message', 'de', null, $data);
$result = $this->adapter->read('message', 'de', null);
-
- $this->assertTrue(is_callable($result['pluralRule']));
unset($result['pluralRule']);
-
$this->assertEqual($data, $result);
$this->adapter->write('messageTemplate', 'root', null, $data);
$result = $this->adapter->read('messageTemplate', 'root', null);
- $this->assertTrue(is_callable($result['pluralRule']));
unset($result['pluralRule']);
$this->assertEqual($data, $result);
}
@@ -639,10 +603,7 @@ public function testReadAndWritePoValidation() {
file_put_contents($file, $po);
$result = $this->adapter->read('validation', 'de', null);
-
- $this->assertTrue(is_callable($result['pluralRule']));
unset($result['pluralRule']);
-
$this->assertEqual($catalog, $result);
unlink($file);
@@ -737,8 +698,6 @@ public function testEscapeUnescape() {
EOD;
file_put_contents($file, $po);
$result = $this->adapter->read('message', 'de', null);
-
- $this->assertTrue(is_callable($result['pluralRule']));
unset($result['pluralRule']);
$message = "`{$unescaped}` (ASCII octal {$ord}) was not escaped to `{$escaped}`";
@@ -840,8 +799,9 @@ public function testPluralRule() {
file_put_contents($file, $data);
$result = $this->adapter->read('message', 'de', null);
- $this->assertEqual(true, $result['pluralRule'](3));
- $this->assertEqual(0, $result['pluralRule'](1));
+ $this->assertTrue(is_callable($result['pluralRule']['translated']));
+ $this->assertEqual(true, $result['pluralRule']['translated'](3));
+ $this->assertEqual(0, $result['pluralRule']['translated'](1));
}
}

0 comments on commit 09cd813

Please sign in to comment.
Something went wrong with that request. Please try again.