Merge remote branch 'cristiangsp/Translation_FallbackLocale'
* cristiangsp/Translation_FallbackLocale: [Translation] Modified Translation unit test "testTransWithFallbackLocale" [Translation] Fixed the addition of the fallbackLocale catalogue to the current locale catalogue. [Translation] Added search to FallbackLocale Catalogue.
This commit is contained in:
commit
c58b6afc38
@ -134,15 +134,15 @@ class Translator implements TranslatorInterface
|
||||
protected function loadCatalogue($locale)
|
||||
{
|
||||
$this->catalogues[$locale] = new MessageCatalogue($locale);
|
||||
if (!isset($this->resources[$locale])) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($this->resources[$locale] as $resource) {
|
||||
if (!isset($this->loaders[$resource[0]])) {
|
||||
throw new \RuntimeException(sprintf('The "%s" translation loader is not registered.', $resource[0]));
|
||||
if (isset($this->resources[$locale])) {
|
||||
|
||||
foreach ($this->resources[$locale] as $resource) {
|
||||
if (!isset($this->loaders[$resource[0]])) {
|
||||
throw new \RuntimeException(sprintf('The "%s" translation loader is not registered.', $resource[0]));
|
||||
}
|
||||
$this->catalogues[$locale]->addCatalogue($this->loaders[$resource[0]]->load($resource[1], $locale, $resource[2]));
|
||||
}
|
||||
$this->catalogues[$locale]->addCatalogue($this->loaders[$resource[0]]->load($resource[1], $locale, $resource[2]));
|
||||
}
|
||||
|
||||
$this->optimizeCatalogue($locale);
|
||||
|
@ -43,11 +43,13 @@ class TranslatorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testTransWithFallbackLocale()
|
||||
{
|
||||
$translator = new Translator('en_US', new MessageSelector());
|
||||
$translator = new Translator('fr_FR', new MessageSelector());
|
||||
$translator->addLoader('array', new ArrayLoader());
|
||||
$translator->addResource('array', array('foo' => 'foofoo'), 'en_US');
|
||||
$translator->addResource('array', array('bar' => 'foobar'), 'en');
|
||||
|
||||
$translator->setFallbackLocale('en');
|
||||
|
||||
$this->assertEquals('foobar', $translator->trans('bar'));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user