FEATURE #2503: add easier installer
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<?php namespace App\Providers;
|
||||
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
||||
@@ -8,8 +9,19 @@ class LaravelLocalizationServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function register()
|
||||
{
|
||||
$languages = DB::table('languages')
|
||||
->get();
|
||||
try {
|
||||
$languages = DB::table('languages')
|
||||
->get();
|
||||
} catch (QueryException $e) {
|
||||
$supportedLocales[config('app.locale')] = [
|
||||
'native' => env('LOCALE_NATIVE_NAME', config('app.locale')),
|
||||
'script' => env('LOCALE_SCRIPT', 'Latn'),
|
||||
'name' => env('LOCALE_TRANSLATED_NAME', config('app.locale')),
|
||||
'code' => config('app.locale'),
|
||||
];
|
||||
$this->setSupportedLocales($supportedLocales);
|
||||
return;
|
||||
}
|
||||
|
||||
$supportedLocales = [];
|
||||
if (empty($languages)) {
|
||||
@@ -32,15 +44,20 @@ class LaravelLocalizationServiceProvider extends ServiceProvider
|
||||
];
|
||||
}
|
||||
|
||||
config([
|
||||
'laravellocalization.supportedLocales' => $supportedLocales,
|
||||
'laravellocalization.useAcceptLanguageHeader' => true,
|
||||
'laravellocalization.hideDefaultLocaleInURL' => true
|
||||
]);
|
||||
$this->setSupportedLocales($supportedLocales);
|
||||
}
|
||||
|
||||
public function boot()
|
||||
{
|
||||
\App::setLocale(LaravelLocalization::getCurrentLocale());
|
||||
}
|
||||
|
||||
private function setSupportedLocales($supportedLocales)
|
||||
{
|
||||
config([
|
||||
'laravellocalization.supportedLocales' => $supportedLocales,
|
||||
'laravellocalization.useAcceptLanguageHeader' => true,
|
||||
'laravellocalization.hideDefaultLocaleInURL' => true
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user