added auto lang switcher for browser

This commit is contained in:
vedatakd 2020-12-30 12:48:02 +03:00
parent 8884e1be03
commit e625fc7fd6
5 changed files with 41 additions and 18 deletions

View File

@ -83,6 +83,7 @@ return [
'translations' => [ 'translations' => [
'title' => 'visiosoft.module.advs::section.translations', 'title' => 'visiosoft.module.advs::section.translations',
'fields' => [ 'fields' => [
'lang_switcher_for_browser',
'override_text', 'override_text',
], ],
], ],

View File

@ -367,5 +367,10 @@ return [
"config" => [ "config" => [
"default_value" => 25 "default_value" => 25
] ]
] ],
'lang_switcher_for_browser' => [
'type' => 'anomaly.field_type.boolean',
'bind' => 'advs.lang_switcher_for_browser',
'env' => 'LANG_SWITCHER_FOR_BROWSER',
],
]; ];

View File

@ -219,4 +219,8 @@ return [
'name' => 'Create Ad Button Color', 'name' => 'Create Ad Button Color',
'instructions' => 'Changes the button that shows up when the new ad category selection is finished.' 'instructions' => 'Changes the button that shows up when the new ad category selection is finished.'
], ],
'lang_switcher_for_browser' => [
'name' => 'Lang Switcher For Browser',
'instructions' => 'Allows you to choose browser language as active language'
],
]; ];

View File

@ -219,4 +219,8 @@ return [
'name' => 'Reklam Düğmesi Rengi Oluştur', 'name' => 'Reklam Düğmesi Rengi Oluştur',
'instructions' => 'Yeni reklam kategorisi seçimi bittiğinde görünen düğmeyi değiştirir.' 'instructions' => 'Yeni reklam kategorisi seçimi bittiğinde görünen düğmeyi değiştirir.'
], ],
'lang_switcher_for_browser' => [
'name' => 'Tarayıcı Diline Geç',
'instructions' => 'Seçili aktif bir dil olmadığında tarayıcı dilini aktif dil olarak seçmenize izin verir'
],
]; ];

View File

@ -14,7 +14,16 @@ class AppServiceProvider extends ServiceProvider
*/ */
public function boot() public function boot()
{ {
// //Auto Language Switcher
view()->composer('*', function ($view) {
if (config('advs.lang_switcher_for_browser') and is_null(Request()->session()->get('_locale'))) {
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);//Get Browser Language
$acceptLang = config('streams::locales.enabled'); //Supported Language
$lang = in_array($lang, $acceptLang) ? $lang : config('streams::locales.default', 'en');
App()->setLocale($lang);
Request()->session()->put('_locale', $lang);
}
});
} }
/** /**