42 lines
1.3 KiB
PHP
42 lines
1.3 KiB
PHP
<?php namespace App\Providers;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
|
use Symfony\Component\Translation\Translator;
|
|
|
|
class LaravelLocalizationServiceProvider extends ServiceProvider
|
|
{
|
|
public function register()
|
|
{
|
|
|
|
$languages = DB::table('languages')
|
|
->get();
|
|
|
|
$supportedLocales = [
|
|
config('app.locale') => [
|
|
'native' => env('LOCALE_NATIVE_NAME'),
|
|
'script' => env('LOCALE_SCRIPT'),
|
|
'name' => env('LOCALE_TRANSLATED_NAME'),
|
|
]
|
|
];
|
|
foreach ($languages as $language) {
|
|
$supportedLocales[$language->code] = [
|
|
'native' => $language->native,
|
|
'name' => $language->name,
|
|
'script' => $language->script
|
|
];
|
|
}
|
|
|
|
config([
|
|
'laravellocalization.supportedLocales' => $supportedLocales,
|
|
'laravellocalization.useAcceptLanguageHeader' => true,
|
|
'laravellocalization.hideDefaultLocaleInURL' => true
|
|
]);
|
|
}
|
|
|
|
public function boot()
|
|
{
|
|
\App::setLocale(LaravelLocalization::getCurrentLocale());
|
|
}
|
|
} |