I'm making a js localizator using service provider, and I need to get current locale to fetch current lang translations and pass to js. Everything works, but App::getLocale() keeps returning default app language.
I tried to do this using both middlware and view composer based on others issue threads in laracasts and stackoverflow, but nothing helps. Here's links
https://laracasts.com/discuss/channels/laravel/get-current-locale-in-app-service-provider
Getting locale language at provider class in Laravel
Laravel get getCurrentLocale() in AppServiceProvider
class JstranslateServiceProvider extends ServiceProvider
{
protected $langPath;
public function __construct()
{
$locale = App::getLocale();
$this->langPath = resource_path('lang/'.$locale);
dd($locale);
}
}
dd($locale);
output is always 'en'
, despite the current language.
I made js localization using this guide Link, it seems to be working for them