laravel-admin-extensions / multi-language

MIT License
25 stars 19 forks source link

When i change lang in login page, not working. #9

Open hh0210 opened 4 years ago

hh0210 commented 4 years ago

Code i had run

composer require laravel-admin-extensions/multi-language

edited config/admin.php with this 2 parts

'extensions' => [
    'multi-language' => [
        'enable' => true,
        // the key should be same as var locale in config/app.php
        // the value is used to show
        'languages' => [
            'en' => 'English',
            'zh-CN' => '简体中文',
        ],
        // default locale
        'default' => 'zh-CN',
        // if or not show multi-language login page, optional, default is true
        'show-login-page' => true,
        // if or not show multi-language navbar, optional, default is true
        'show-navbar' => true,
        // the cookie name for the multi-language var, optional, default is 'locale'
        'cookie-name' => 'locale'
    ],
],

'auth' => [ 'excepts' => [ 'auth/login', 'auth/logout', 'locale', '_handleaction', ], ],

Screenshot (45)

keoy7am commented 3 years ago

You can try to do these things:

  1. Find auth.excepts in config/admin.php And add 'locale' . Looks like this

    'excepts' => [
        'auth/login',
        'auth/logout',
        'locale',
    ],
  2. Open MultiLanguageMiddleware.php and add the code below in the first line of handle() function

    config(['admin.auth.excepts' => ['auth/login','locale']]);

    Same as PullRequest#12

  3. If it still doesn't work, Please check whether the current URL follows the https protocol If yes, Find https in config/admin.php . Make sure its value is true .

kai890707 commented 1 year ago

Hi, @hh0210 . I had this problem today too. Sorry my English is not very good, but I hope to answer your question. Maybe you can try this.

  1. find app/Http/Kernel.php And in this file search to middlewareGroups array.
  2. add this code to in side, \KevinSoft\MultiLanguage\Middlewares\MultiLanguageMiddleware::class. Look like this

    protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
            // add this line.
            \KevinSoft\MultiLanguage\Middlewares\MultiLanguageMiddleware::class
        ],
    
        'api' => [
            // \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
            'throttle:api',
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
        ],
    ];

    I am not sure if this method is suitable for your project, but I can run it successfully !!!

blackcolt commented 11 months ago

@kai890707 this fixed the translation for me, thanks. :)