8000 merged branch hason/translationrequest (PR #4650) · Rodsevich/symfony@84e619c · GitHub
[go: up one dir, main page]

Skip to content

Commit 84e619c

Browse files
committed
merged branch hason/translationrequest (PR symfony#4650)
Commits ------- 8ae0fa2 [FrameworkBundle] Fixed locale detection from request Discussion ---------- [FrameworkBundle] Fixed locale detection from request --------------------------------------------------------------------------- by travisbot at 2012-06-25T10:09:24Z This pull request [passes](http://travis-ci.org/symfony/symfony/builds/1699743) (merged 8ae0fa2 into 03c8d4d).
2 parents b5e6613 + 8ae0fa2 commit 84e619c

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/Translation/TranslatorTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,46 @@ public function testTransWithCaching()
8080
$this->assertEquals('no translation', $translator->trans('no translation'));
8181
}
8282

83+
public function testGetLocale()
84+
{
85+
$request = $this->getMock('Symfony\Component\HttpFoundation\Request');
86+
87+
$request
88+
->expects($this->once())
89+
->method('getLocale')
90+
->will($this->returnValue('en'))
91+
;
92+
93+
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
94+
95+
$container
96+
->expects($this->exactly(2))
97+
->method('isScopeActive')
98+
->with('request')
99+
->will($this->onConsecutiveCalls(false, true))
100+
;
101+
102+
$container
103+
->expects($this->once())
104+
->method('has')
105+
->with('request')
106+
->will($this->returnValue(true))
107+
;
108+
109+
$container
110+
->expects($this->once())
111+
->method('get')
112+
->with('request')
113+
->will($this->returnValue($request))
114+
;
115+
116+
$translator = new Translator($container, new MessageSelector());
117+
118+
$this->assertNull($translator->getLocale());
119+
$this->assertSame('en', $translator->getLocale());
120+
$this->assertSame('en', $translator->getLocale());
121+
}
122+
83123
protected function getCatalogue($locale, $messages)
84124
{
85125
$catalogue = new MessageCatalogue($locale);

src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function __construct(ContainerInterface $container, MessageSelector $sele
6565
*/
6666
public function getLocale()
6767
{
68-
if (null === $this->locale && $this->container->isScopeActive('request')) {
68+
if (null === $this->locale && $this->container->isScopeActive('request') && $this->container->has('request')) {
6969
$this->locale = $this->container->get('request')->getLocale();
7070
}
7171

0 commit comments

Comments
 (0)
0