-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'pr/21129' of https://github.com/themsaid/framework into…
… themsaid-pr/21129
- Loading branch information
Showing
8 changed files
with
227 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Illuminate\Support\Traits; | ||
|
||
trait Localizable | ||
{ | ||
/** | ||
* Run the callback with the given locale. | ||
* | ||
* @param string $locale | ||
* @param \Illuminate\Contracts\Translation\Translator $translator | ||
* @param \Closure $callback | ||
* @return bool | ||
*/ | ||
public function withLocale($locale, $translator, $callback) | ||
{ | ||
if (! $locale || ! $translator) { | ||
return $callback(); | ||
} | ||
|
||
$original = $translator->getLocale(); | ||
|
||
try { | ||
$translator->setLocale($locale); | ||
|
||
return $callback(); | ||
} finally { | ||
$translator->setLocale($original); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{__('nom')}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Integration\Mail\SendingMailWithLocale; | ||
|
||
use Mockery; | ||
use Illuminate\Mail\Mailable; | ||
use Orchestra\Testbench\TestCase; | ||
use Illuminate\Support\Facades\Mail; | ||
use Illuminate\Support\Facades\View; | ||
|
||
/** | ||
* @group integration | ||
*/ | ||
class SendingMailWithLocaleTest extends TestCase | ||
{ | ||
public function tearDown() | ||
{ | ||
parent::tearDown(); | ||
|
||
Mockery::close(); | ||
} | ||
|
||
protected function getEnvironmentSetUp($app) | ||
{ | ||
$app['config']->set('app.debug', 'true'); | ||
|
||
$app['config']->set('mail.driver', 'array'); | ||
|
||
$app['config']->set('app.locale', 'en'); | ||
|
||
View::addLocation(__DIR__.'/Fixtures'); | ||
|
||
app('translator')->setLoaded([ | ||
'*' => [ | ||
'*' => [ | ||
'en' => ['nom' => 'name'], | ||
'ar' => ['nom' => 'esm'], | ||
], | ||
], | ||
]); | ||
} | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
} | ||
|
||
public function test_mail_is_sent_with_default_locale() | ||
{ | ||
Mail::to('test@mail.com')->send(new TestMail()); | ||
|
||
$this->assertContains('name', | ||
app('swift.transport')->messages()[0]->getBody() | ||
); | ||
} | ||
|
||
public function test_mail_is_sent_with_selected_locale() | ||
{ | ||
Mail::to('test@mail.com')->locale('ar')->send(new TestMail()); | ||
|
||
$this->assertContains('esm', | ||
app('swift.transport')->messages()[0]->getBody() | ||
); | ||
} | ||
|
||
public function test_locale_is_set_back_to_default_after_mail_sent() | ||
{ | ||
Mail::to('test@mail.com')->locale('ar')->send(new TestMail()); | ||
Mail::to('test@mail.com')->send(new TestMail()); | ||
|
||
$this->assertEquals('en', app('translator')->getLocale()); | ||
|
||
$this->assertContains('esm', | ||
app('swift.transport')->messages()[0]->getBody() | ||
); | ||
|
||
$this->assertContains('name', | ||
app('swift.transport')->messages()[1]->getBody() | ||
); | ||
} | ||
} | ||
|
||
class TestMail extends Mailable | ||
{ | ||
/** | ||
* Build the message. | ||
* | ||
* @return $this | ||
*/ | ||
public function build() | ||
{ | ||
return $this->view('view'); | ||
} | ||
} |