2016-07-19 19:04:31 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\ViewComposers;
|
|
|
|
|
|
|
|
use Illuminate\View\View;
|
|
|
|
|
|
|
|
class AppLanguageComposer
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Bind data to the view.
|
|
|
|
*
|
2017-01-30 20:40:43 +01:00
|
|
|
* @param View $view
|
2016-07-19 19:04:31 +02:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function compose(View $view)
|
|
|
|
{
|
|
|
|
$view->with('appLanguage', $this->getLanguage());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-01-30 20:40:43 +01:00
|
|
|
* Get the language from the current locale.
|
2016-07-19 19:04:31 +02:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function getLanguage()
|
|
|
|
{
|
|
|
|
$code = app()->getLocale();
|
|
|
|
|
2017-01-30 17:05:31 +01:00
|
|
|
if (preg_match('/_/', $code)) {
|
2016-07-19 19:04:31 +02:00
|
|
|
$codes = explode('_', $code);
|
|
|
|
$code = $codes[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $code;
|
|
|
|
}
|
2017-01-30 17:05:31 +01:00
|
|
|
}
|