Skip to content

Commit

Permalink
Merge pull request sonata-project#4239 from fbourigault/enhance-trans…
Browse files Browse the repository at this point in the history
…lation-admin-extractor

extract admin group and label translations
  • Loading branch information
greg0ire authored Dec 22, 2016
2 parents 6527db5 + e823e52 commit 1be584c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,20 @@ public function setUp()

$logger = $this->getMock('Psr\Log\LoggerInterface');

$this->pool = new Pool($container, '', '');
$this->pool->setAdminServiceIds(array('foo_admin', 'bar_admin'));
$this->pool = $this->getMockBuilder('Sonata\AdminBundle\Admin\Pool')
->disableOriginalConstructor()
->getMock();
$this->pool->expects($this->any())
->method('getAdminServiceIds')
->will($this->returnValue(array('foo_admin', 'bar_admin')));
$this->pool->expects($this->any())
->method('getContainer')
->will($this->returnValue($container));
$this->pool->expects($this->any())
->method('getAdminGroups')
->will($this->returnValue(array('group' => array(
'label_catalogue' => 'admin_domain',
))));

$this->adminExtractor = new AdminExtractor($this->pool, $logger);
$this->adminExtractor->setLogger($logger);
Expand Down Expand Up @@ -109,9 +121,17 @@ public function testExtract()

return;
}));
$this->fooAdmin->expects($this->any())
->method('getLabel')
->willReturn('foo_label');
$this->fooAdmin->expects($this->any())
->method('getTranslationDomain')
->willReturn('foo_admin_domain');

$catalogue = $this->adminExtractor->extract();

$this->assertCount(2, $catalogue->getDomains());

$this->assertTrue($catalogue->has(new Message('foo', 'foo_admin_domain')));
$this->assertFalse($catalogue->has(new Message('nonexistent', 'foo_admin_domain')));

Expand All @@ -120,6 +140,9 @@ public function testExtract()
$message = $catalogue->get('foo', 'foo_admin_domain');
$this->assertSame('foo', $message->getId());
$this->assertSame('foo_admin_domain', $message->getDomain());

$this->assertTrue($catalogue->has(new Message('group', 'admin_domain')));
$this->assertTrue($catalogue->has(new Message('foo_label', 'foo_admin_domain')));
}

public function testExtractWithException()
Expand Down
9 changes: 9 additions & 0 deletions Translator/Extractor/JMSTranslatorBundle/AdminExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,18 @@ public function extract()

$this->catalogue = new MessageCatalogue();

foreach ($this->adminPool->getAdminGroups() as $name => $group) {
$this->trans($name, array(), $group['label_catalogue']);
}

foreach ($this->adminPool->getAdminServiceIds() as $id) {
$admin = $this->getAdmin($id);

$label = $admin->getLabel();
if (!empty($label)) {
$this->trans($label, array(), $admin->getTranslationDomain());
}

$this->translator = $admin->getTranslator();
$this->labelStrategy = $admin->getLabelTranslatorStrategy();
$this->domain = $admin->getTranslationDomain();
Expand Down

0 comments on commit 1be584c

Please sign in to comment.