Skip to content
This repository has been archived by the owner on May 16, 2018. It is now read-only.

Commit

Permalink
Fixes #66 - Gettext adapter cannot translate plurals when the target …
Browse files Browse the repository at this point in the history
…language has only one plural form
  • Loading branch information
froschdesign committed Jan 3, 2014
1 parent a382a5e commit 4a7f3c8
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 1 deletion.
2 changes: 1 addition & 1 deletion library/Zend/Translate/Adapter/Gettext.php
Expand Up @@ -122,7 +122,7 @@ protected function _loadTranslationData($filename, $locale, array $options = arr
fseek($this->_file, $transtemp[$count * 2 + 2]);
$translate = fread($this->_file, $transtemp[$count * 2 + 1]);
$translate = explode("\0", $translate);
if ((count($original) > 1) && (count($translate) > 1)) {
if ((count($original) > 1)) {
$this->_data[$locale][$original[0]] = $translate;
array_shift($original);
foreach ($original as $orig) {
Expand Down
46 changes: 46 additions & 0 deletions tests/Zend/Translate/Adapter/GettextTest.php
Expand Up @@ -254,6 +254,52 @@ public function testMissingAdapterInfo()
$this->assertContains('No adapter information available', current($adapter->getAdapterInfo()));
}

/**
* @group GH-66
*/
public function testPluralToPlural()
{
$adapter = new Zend_Translate_Adapter_Gettext(
dirname(__FILE__) . '/_files/translation_plural_fr.mo', 'fr'
);

$this->assertEquals(
'Il ya %d message',
$adapter->plural('There is %d message', 'There are %d messages', 0)
);
$this->assertEquals(
'Il ya %d message',
$adapter->plural('There is %d message', 'There are %d messages', 1)
);
$this->assertEquals(
'Il ya %d messages',
$adapter->plural('There is %d message', 'There are %d messages', 2)
);
}

/**
* @group GH-66
*/
public function testPluralToSingular()
{
$adapter = new Zend_Translate_Adapter_Gettext(
dirname(__FILE__) . '/_files/translation_plural_tr.mo', 'tr'
);

$this->assertEquals(
'%d mesaj var',
$adapter->plural('There is %d message', 'There are %d messages', 0)
);
$this->assertEquals(
'%d mesaj var',
$adapter->plural('There is %d message', 'There are %d messages', 1)
);
$this->assertEquals(
'%d mesaj var',
$adapter->plural('There is %d message', 'There are %d messages', 2)
);
}

/**
* Ignores a raised PHP error when in effect, but throws a flag to indicate an error occurred
*
Expand Down
Binary file not shown.
18 changes: 18 additions & 0 deletions tests/Zend/Translate/Adapter/_files/translation_plural_fr.po
@@ -0,0 +1,18 @@
msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Plural-Forms: nplurals=2; plural=n > 1;\n"
"Project-Id-Version: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: fr\n"
"X-Generator: Poedit 1.6.3\n"

msgid "There is %d message"
msgid_plural "There are %d messages"
msgstr[0] "Il ya %d message"
msgstr[1] "Il ya %d messages"
Binary file not shown.
17 changes: 17 additions & 0 deletions tests/Zend/Translate/Adapter/_files/translation_plural_tr.po
@@ -0,0 +1,17 @@
msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"Project-Id-Version: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: tr\n"
"X-Generator: Poedit 1.6.3\n"

msgid "There is %d message"
msgid_plural "There are %d message"
msgstr[0] "%d mesaj var"

0 comments on commit 4a7f3c8

Please sign in to comment.