本文整理汇总了PHP中Illuminate\Foundation\Application::setLocale方法的典型用法代码示例。如果您正苦于以下问题:PHP Application::setLocale方法的具体用法?PHP Application::setLocale怎么用?PHP Application::setLocale使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Foundation\Application
的用法示例。
在下文中一共展示了Application::setLocale方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* @param $request
* @param callable $next
* @return mixed
*/
public function handle($request, \Closure $next)
{
if ($this->auth->check()) {
$this->app->setLocale($this->auth->user()->getLocale());
}
return $next($request);
}
示例2: handle
/**
* Handle the event.
*/
public function handle()
{
if ($locale = $this->preferences->get('streams::locale')) {
$this->application->setLocale($locale);
$this->config->set('app.locale', $locale);
}
}
示例3: handle
public function handle(Request $request, Closure $next)
{
$default = $request->session()->get('locale', 'en');
$locale = $request->input('locale', $default);
$locale = Str::substr($locale, 0, 2);
$request->session()->put('locale', $locale);
$this->app->setLocale($locale);
return $next($request);
}
示例4: setAppLocale
/**
* Sets the app locale
*
* @param string $locale
* @param bool $session
* @return void
*/
public function setAppLocale($locale = null, $session = true)
{
$locale = $locale ?: $this->session->get('_locale', null);
if ($locale) {
$this->app->setLocale($locale);
if ($session) {
$this->session->put('_locale', $locale);
}
$this->setTimeLocale($locale);
}
}
示例5: handle
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
*
* @return mixed
*/
public function handle($request, Closure $next)
{
$this->app->setLocale($this->settings->get('user.language', 'en'));
$langDir = ['left' => 'left', 'right' => 'right'];
if (trans('general.direction') == 'rtl') {
$langDir['left'] = 'right';
$langDir['right'] = 'left';
}
$this->viewFactory->share('langDir', $langDir);
return $next($request);
}
示例6: handle
/**
* Handle the command.
*
* @param Application $app
* @param Repository $config
* @param Request $request
* @param PreferenceRepositoryInterface $preferences
*/
function handle(Application $app, Repository $config, Request $request, PreferenceRepositoryInterface $preferences)
{
// Set using admin locale if in admin.
if ($request->segment(1) === 'admin' && ($locale = $preferences->get('streams::admin_locale'))) {
$app->setLocale($locale->getValue());
$config->set('app.locale', $locale->getValue());
}
// Set using public locale if NOT in admin.
if (!defined('LOCALE') && $request->segment(1) !== 'admin' && ($locale = $preferences->get('streams::public_locale'))) {
$app->setLocale($locale->getValue());
$config->set('app.locale', $locale->getValue());
}
}
示例7: setLocale
/**
* Set and return current locale
*
* @param string $locale Locale to set the App to (optional)
*
* @return string Returns locale (if route has any) or null (if route does not have a locale)
*/
public function setLocale($locale = null)
{
if (empty($locale) || !is_string($locale)) {
// If the locale has not been passed through the function
// it tries to get it from the first segment of the url
$locale = $this->request->segment(1);
}
if (!empty($this->supportedLocales[$locale])) {
$this->currentLocale = $locale;
} else {
// if the first segment/locale passed is not valid
// the system would ask which locale have to take
// it could be taken by the browser
// depending on your configuration
$locale = null;
// if we reached this point and hideDefaultLocaleInURL is true
// we have to assume we are routing to a defaultLocale route.
if ($this->hideDefaultLocaleInURL()) {
$this->currentLocale = $this->defaultLocale;
} else {
$this->currentLocale = $this->getCurrentLocale();
}
}
$this->app->setLocale($this->currentLocale);
// Regional locale such as de_DE, so formatLocalized works in Carbon
$regional = $this->getCurrentLocaleRegional();
if ($regional) {
setlocale(LC_TIME, $regional . '.utf8');
}
return $locale;
}
示例8: setLocale
/**
* Set and return current locale
*
* @param string $locale Locale to set the App to (optional)
*
* @return string Returns locale (if route has any) or null (if route does not have a locale)
*/
public function setLocale($locale = null)
{
if (empty($locale) || !is_string($locale)) {
// If the locale has not been passed through the function
// it tries to get it from the first segment of the url
$locale = $this->request->segment(1);
}
if (!empty($this->supportedLocales[$locale])) {
$this->currentLocale = $locale;
} else {
// if the first segment/locale passed is not valid
// the system would ask which locale have to take
// it could be taken by the browser
// depending on your configuration
$locale = null;
// if we reached this point and hideDefaultLocaleInURL is true
// we have to assume we are routing to a defaultLocale route.
if ($this->hideDefaultLocaleInURL()) {
$this->currentLocale = $this->defaultLocale;
} else {
$this->currentLocale = $this->getCurrentLocale();
}
}
//save locale in session
session('locale', $this->currentLocale);
$this->app->setLocale($this->currentLocale);
return $locale;
}
示例9: handle
/**
* Look for locale=LOCALE in the query string.
*
* @param Request $request
* @param \Closure $next
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
if (defined('LOCALE')) {
return $next($request);
}
if ($locale = $request->get('_locale')) {
if ($locale) {
$request->session()->put('_locale', $locale);
} else {
$request->session()->remove('_locale');
}
return $this->redirect->to($request->path());
}
if ($locale = $request->session()->get('_locale')) {
$this->application->setLocale($locale);
$this->config->set('_locale', $locale);
}
if (!$locale) {
$this->application->setLocale($this->config->get('streams::locales.default'));
}
return $next($request);
}
示例10: setLocale
/**
* Set the current application locale.
*
* @param string $locale
* @return void
*/
public function setLocale($locale)
{
parent::setLocale($locale);
$localeMapping = $this['config']->get('locale-mapping');
$mappedValue = array_get($localeMapping, 'locales.' . $locale);
if ($mappedValue) {
$mappedCategories = array_get($localeMapping, 'categories');
if (in_array(LC_ALL, $mappedCategories)) {
setlocale(LC_ALL, $mappedValue);
} else {
foreach ($mappedCategories as $mappedCategory) {
setlocale($mappedCategory, $mappedValue);
}
}
}
}
示例11: setLocale
/**
* Set and return current locale.
*
* @param string|null $locale
*
* @return string
*/
public function setLocale($locale = null)
{
if (empty($locale) || !is_string($locale)) {
// If the locale has not been passed through the function
// it tries to get it from the first segment of the url
$locale = $this->request()->segment(1);
}
if ($this->isSupportedLocale($locale)) {
$this->setCurrentLocale($locale);
} else {
// if the first segment/locale passed is not valid the system would ask which locale have to take
// it could be taken by the browser depending on your configuration
$locale = null;
$this->getCurrentOrDefaultLocale();
}
$this->app->setLocale($this->getCurrentLocale());
return $locale;
}
示例12: handle
/**
* Handle the command.
*
* @param Repository $config
* @param Application $application
*/
public function handle(Repository $config, Application $application)
{
// First trigger to resolve.
$application->make('translator');
/*
* Change the lang loader so we can
* add a few more necessary override
* paths to the API.
*/
$application->singleton('translation.loader', function ($application) {
return new Loader($application['files'], $application['path.lang']);
});
/*
* Re-bind the translator so we can use
* the new loader defined above.
*/
$application->singleton('translator', function ($application) {
$loader = $application->make('translation.loader');
// When registering the translator component, we'll need to set the default
// locale as well as the fallback locale. So, we'll grab the application
// configuration so we can easily get both of these values from there.
$locale = $application['config']['app.locale'];
$trans = new Translator($loader, $locale);
$trans->setFallback($application['config']['app.fallback_locale']);
return $trans;
});
/*
* Set the locale if LOCALE is defined.
*
* LOCALE is defined first thing in our
* HTTP Kernel. Respect it!
*/
if (defined('LOCALE')) {
$application->setLocale(LOCALE);
$config->set('app.locale', LOCALE);
}
// Set our locale namespace.
$application->make('translator')->addNamespace('streams', realpath(__DIR__ . '/../../../resources/lang'));
}
示例13: setLocale
/**
* Set app locale if we have a query parameter named
* lang then it will be used else we check for sub domain
* If nothing found fallback will be used
*
* @return void
*/
private function setLocale()
{
$availableLangs = $this->config->get('app.available_languages', []);
if ($this->input->has('lang')) {
$lang = $this->input->input('lang');
if (in_array($this->input->input('lang'), $availableLangs)) {
$this->app->setLocale($lang);
Session::put(self::SESSION_LOCALE, $lang);
return;
}
}
$subDomain = $this->router->getCurrentRoute();
if (!empty($subDomain)) {
$subDomain = $subDomain->getParameter('locale');
$this->app->setLocale($subDomain);
return;
}
if ($this->session->has(self::SESSION_LOCALE)) {
$this->app->setLocale($this->session->get(self::SESSION_LOCALE));
return;
}
}
示例14: setLocale
/**
* Set the current application locale.
*
* @param string $locale
* @return void
* @static
*/
public static function setLocale($locale)
{
\Illuminate\Foundation\Application::setLocale($locale);
}
示例15: testSetLocaleSetsLocaleAndFiresLocaleChangedEvent
public function testSetLocaleSetsLocaleAndFiresLocaleChangedEvent()
{
$app = new Application();
$app['config'] = $config = m::mock('StdClass');
$config->shouldReceive('set')->once()->with('app.locale', 'foo');
$app['translator'] = $trans = m::mock('StdClass');
$trans->shouldReceive('setLocale')->once()->with('foo');
$app['events'] = $events = m::mock('StdClass');
$events->shouldReceive('fire')->once()->with('locale.changed', array('foo'));
$app->setLocale('foo');
}