Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding pluralRule to the getText adapter so that Message::_translated…

… can process plural words
  • Loading branch information...
commit b806f13b6a821399a6427ea5b5f99801d60e34fe 1 parent b6a48ad
@Howard3 Howard3 authored
View
3  g11n/catalog/adapter/Gettext.php
@@ -120,6 +120,9 @@ public function read($category, $locale, $scope) {
fclose($stream);
if ($data) {
+ $data['pluralRule'] = function($count) {
+ return $count != 1;
+ };
return $data;
}
}
View
73 tests/cases/g11n/catalog/adapter/GettextTest.php
@@ -105,6 +105,10 @@ public function testReadPoSingleItem() {
)
);
$result = $this->adapter->read('message', 'de', null);
+
+ $this->assertTrue(is_callable($result['pluralRule']));
+ unset($result['pluralRule']);
+
$this->assertEqual($expected, $result);
}
@@ -138,6 +142,10 @@ public function testReadPoMultipleItems() {
)
);
$result = $this->adapter->read('message', 'de', null);
+
+ $this->assertTrue(is_callable($result['pluralRule']));
+ unset($result['pluralRule']);
+
$this->assertEqual($expected, $result);
}
@@ -162,6 +170,10 @@ public function testReadPoPlural() {
)
);
$result = $this->adapter->read('message', 'de', null);
+
+ $this->assertTrue(is_callable($result['pluralRule']));
+ unset($result['pluralRule']);
+
$this->assertEqual($expected, $result);
}
@@ -203,6 +215,10 @@ public function testReadPoWithGnuHeader() {
)
);
$result = $this->adapter->read('message', 'de', null);
+
+ $this->assertTrue(is_callable($result['pluralRule']));
+ unset($result['pluralRule']);
+
$this->assertEqual($expected, $result);
}
@@ -258,6 +274,10 @@ 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);
@@ -299,6 +319,10 @@ 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";
@@ -325,6 +349,10 @@ 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
@@ -360,6 +388,10 @@ public function testReadPoMultiline() {
)
);
$result = $this->adapter->read('message', 'de', null);
+
+ $this->assertTrue(is_callable($result['pluralRule']));
+ unset($result['pluralRule']);
+
$this->assertEqual($expected, $result);
}
@@ -373,6 +405,10 @@ 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
@@ -382,6 +418,10 @@ 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);
}
@@ -418,6 +458,10 @@ public function testReadMoLittleEndian() {
)
);
$result = $this->adapter->read('message', 'de', null);
+
+ $this->assertTrue(is_callable($result['pluralRule']));
+ unset($result['pluralRule']);
+
$this->assertEqual($expected, $result);
}
@@ -505,10 +549,16 @@ 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);
}
@@ -589,6 +639,10 @@ 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);
@@ -683,6 +737,10 @@ 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}`";
$message .= "\n{:message}";
$this->assertEqual($catalog, $result, $message);
@@ -770,6 +828,21 @@ public function testFixDoubleEscapedOnWrite() {
$result = file_get_contents($file);
$this->assertPattern('/' . preg_quote($po, '/') . '/', $result);
}
+
+ public function testPluralRule() {
+ $file = "{$this->_path}/de/LC_MESSAGES/default.po";
+ $data = <<<EOD
+msgid "singular 1"
+msgid_plural "plural 1"
+msgstr[0] "translated 1-0"
+msgstr[1] "translated 1-1"
+EOD;
+ file_put_contents($file, $data);
+
+ $result = $this->adapter->read('message', 'de', null);
+ $this->assertEqual(true, $result['pluralRule'](3));
+ $this->assertEqual(0, $result['pluralRule'](1));
+ }
}
?>
Please sign in to comment.
Something went wrong with that request. Please try again.