Configure supported locales via a Service Provider
masterInstead of using a static config file, you can use a ConfigServiceProvider to dynamically set the laravellocalization configuration settings. This is useful for overriding default settings or setting them based on application logic.
Common keys include:
laravellocalization.supportedLocales: An array defining supported languages with theirname,script, andnativenames.laravellocalization.useAcceptLanguageHeader: Boolean to determine if theAccept-Languageheader should be used.laravellocalization.hideDefaultLocaleInURL: Boolean to determine if the default locale should be hidden from the URL.
<?php namespace App\Providers;
use Illuminate\
Support\ServiceProvider;
class ConfigServiceProvider extends ServiceProvider {
public function register()
{
config([
'laravellocalization.supportedLocales' => [
'ace' => array( 'name' => 'Achinese', 'script' => 'Latn', 'native' => 'Aceh' ),
'ca' => array( 'name' => 'Catalan', 'script' => 'Latn', 'native' => 'català' ),
'en' => array( 'name' => 'English', 'script' => 'Latn', 'native' => 'English' ),
],
'laravellocalization.useAcceptLanguageHeader' => true,
'laravellocalization.hideDefaultLocaleInURL' => true
]);
}
}