CapsuleManagerTrait.php
2 years ago
ForwardsCalls.php
2 years ago
Localizable.php
2 years ago
ReflectsClosures.php
2 years ago
Tappable.php
6 months ago
Localizable.php
31 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWPSCOPED\Illuminate\Support\Traits; |
| 4 | |
| 5 | use IAWPSCOPED\Illuminate\Container\Container; |
| 6 | /** @internal */ |
| 7 | trait Localizable |
| 8 | { |
| 9 | /** |
| 10 | * Run the callback with the given locale. |
| 11 | * |
| 12 | * @param string $locale |
| 13 | * @param \Closure $callback |
| 14 | * @return mixed |
| 15 | */ |
| 16 | public function withLocale($locale, $callback) |
| 17 | { |
| 18 | if (!$locale) { |
| 19 | return $callback(); |
| 20 | } |
| 21 | $app = Container::getInstance(); |
| 22 | $original = $app->getLocale(); |
| 23 | try { |
| 24 | $app->setLocale($locale); |
| 25 | return $callback(); |
| 26 | } finally { |
| 27 | $app->setLocale($original); |
| 28 | } |
| 29 | } |
| 30 | } |
| 31 |