merged branch clemens-tolboom/pofileloader-pluralhandling (PR #4336)

Commits
-------

4c4d889 Fixed PoFileLoader pluralhandling from interval to index.

Discussion
----------

[BUG] PoFileLoader pluralhandling uses interval instead of index.

PoFileLoaders parsed Gettext messages as interval but should have used indexed.

I added index only message strings to MessageSelectorTest to reflect this.

(this is part of https://github.com/symfony/symfony/pull/4249)

---------------------------------------------------------------------------

by travisbot at 2012-05-19T10:11:09Z

This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1373653) (merged 4c4d8890 into 58b92453).
This commit is contained in:
Fabien Potencier 2012-05-19 15:15:45 +02:00
commit 23b64b4ce2
3 changed files with 7 additions and 2 deletions

View File

@ -74,7 +74,7 @@ class PoFileLoader extends ArrayLoader implements LoaderInterface
if (isset($item['ids']['plural'])) {
$plurals = array();
foreach ($item['translated'] as $plural => $translated) {
$plurals[] = sprintf('{%d} %s', $plural, $translated);
$plurals[] = $translated;
}
$messages[$item['ids']['plural']] = stripcslashes(implode('|', $plurals));
}

View File

@ -39,7 +39,7 @@ class PoFileLoaderTest extends \PHPUnit_Framework_TestCase
$resource = __DIR__.'/../fixtures/plurals.po';
$catalogue = $loader->load($resource, 'en', 'domain1');
$this->assertEquals(array('foo' => 'bar', 'foos' => '{0} bar|{1} bars'), $catalogue->all('domain1'));
$this->assertEquals(array('foo' => 'bar', 'foos' => 'bar|bars'), $catalogue->all('domain1'));
$this->assertEquals('en', $catalogue->getLocale());
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
}

View File

@ -62,6 +62,11 @@ class MessageSelectorTest extends \PHPUnit_Framework_TestCase
array('', '{0}|{1} There is one apple|]1,Inf] There is %count% apples', 0),
array('', '{0} There is no apples|{1}|]1,Inf] There is %count% apples', 1),
// Indexed only tests which are Gettext PoFile* compatible strings.
array('There are %count% apples', 'There is one apple|There are %count% apples', 0),
array('There is one apple', 'There is one apple|There are %count% apples', 1),
array('There are %count% apples', 'There is one apple|There are %count% apples', 2),
);
}
}