nhayder
204
7
Laravel

Change app default locale dynamically

Posted 3 weeks ago by nhayder

i'm using mcamara localization package https://github.com/mcamara/laravel-localization in app an with default language set to english as per default laravel installation config/app.php


/*
    |--------------------------------------------------------------------------
    | Application Locale Configuration
    |--------------------------------------------------------------------------
    |
    | The application locale determines the default locale that will be used
    | by the translation service provider. You are free to set this value
    | to any of the locales which will be supported by the application.
    |
    */

    'locale' => 'en',

i need to give the user ability to change the default language dynamically using a from, ...

when i don this

    $locale = 'es'; // passed from the form

        Session::put('locale', $locale);

        app()->setLocale(Session::get('locale'));

after submitting the form i can see the locale is changing but mcamara is not picking up the changes, It still seed the default locale = 'en'; as shown above,

not sure if there is another way to do this but i think if i can change the locale in the config/app.php file dynamically and (i mean access the file and change the locale value in php) will do the job.

Is that possible ???? is there is any better way to do this??

Any ideas ?

Please sign in or create an account to participate in this conversation.