Skip to content

Commit

Permalink
Merge pull request #8402 from cakephp/fix-magic-plural-form
Browse files Browse the repository at this point in the history
Avoding errors when there is no translation for the given plural form.
  • Loading branch information
markstory committed Mar 4, 2016
2 parents b2a62ae + ce3b972 commit 88e1bb8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/I18n/Formatter/IcuFormatter.php
Expand Up @@ -65,7 +65,7 @@ public function format($locale, $message, array $vars)
$count = isset($vars['_count']) ? $vars['_count'] : 0;
unset($vars['_count'], $vars['_singular']);
$form = PluralRules::calculate($locale, $count);
$message = $message[$form];
$message = isset($message[$form]) ? $message[$form] : end($message);
}

return $this->_formatMessage($locale, $message, $vars);
Expand Down
16 changes: 16 additions & 0 deletions tests/TestCase/I18n/TimeTest.php
Expand Up @@ -15,6 +15,7 @@
namespace Cake\Test\TestCase\I18n;

use Cake\I18n\FrozenTime;
use Cake\I18n\I18n;
use Cake\I18n\Time;
use Cake\TestSuite\TestCase;

Expand Down Expand Up @@ -55,6 +56,7 @@ public function tearDown()
FrozenTime::$defaultLocale = $this->locale;
FrozenTime::resetToStringFormat();
date_default_timezone_set('UTC');
I18n::locale(I18n::DEFAULT_LOCALE);
}

/**
Expand Down Expand Up @@ -807,6 +809,20 @@ public function testParseTime($class)
$this->assertNull($time);
}

/**
* Tests that timeAgoInWords when using a russian locale does not break things
*
* @dataProvider classNameProvider
* @return void
*/
public function testRussianTimeAgoInWords($class)
{
I18n::locale('ru_RU');
$time = new $class('5 days ago');
$result = $time->timeAgoInWords();
$this->assertEquals('5 days ago', $result);
}

/**
* Tests that parsing a date respects de default timezone in PHP.
*
Expand Down

0 comments on commit 88e1bb8

Please sign in to comment.