zlibproxy/vendor/illuminate/support/Traits/Localizable.php

35 lines
629 B
PHP
Raw Permalink Normal View History

2023-01-02 19:56:44 +08:00
<?php
namespace Illuminate\Support\Traits;
use Illuminate\Container\Container;
trait Localizable
{
/**
* Run the callback with the given locale.
*
* @param string $locale
* @param \Closure $callback
* @return mixed
*/
public function withLocale($locale, $callback)
{
if (! $locale) {
return $callback();
}
$app = Container::getInstance();
$original = $app->getLocale();
try {
$app->setLocale($locale);
return $callback();
} finally {
$app->setLocale($original);
}
}
}