Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

armix's avatar

Laravel 5 how I can change language Auth, Password Reminders & Reset ?

Laravel 5 how I can change language at Auth, Password Reminders & Reset ? When I open:: http://localhost/password/email/ http://localhost/auth/register/ http://localhost/auth/login/

I can see a default EN forms and errors messages! When I try Middleware set RU language its not help! How I can set different languages Auth, Password Reminders & Reset ?

0 likes
13 replies
bestmomo's avatar

Language is set in config/app.php :

'locale' => 'en',

Just add your language pack in resources/lang. You can find it there.

If I well understand what you mean.

1 like
armix's avatar

I need dynamic change the language for multilang site with setLocale! When I make this URL http://localhost/ru/password/email/ , I can change lang the blade template, but errors or other messages still by EN

zachleigh's avatar

In the lang file, you should make an "ru" folder and translate all the messages in the "en" folder.

armix's avatar

I created ru folder and all the massage translated! I try to middleware, but its don't work! How I can run middleware here:

Route::controllers([ 'auth' => 'Auth\AuthController', 'password' => 'Auth\PasswordController', ]);

This route control all auth and password urls

bestmomo's avatar

If you use for example a "lang" middleware, just create group in routes :

Route::group(['middleware' => 'lang'], function()
{
    Route::controllers([ 'auth' => 'Auth\AuthController', 'password' => 'Auth\PasswordController', ]);
});
armix's avatar

I created a global middleware for all routes ($middleware property app/Http/Kernel.php class)

<?php namespace App\Http\Middleware;

use Closure;

class SetLangMiddleware {

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        

        if (strlen($request->segment(1))=='2')
        {
            $request->setLocale($request->segment(1));
        }
        print $request->segment(1)."!!!";
        return $next($request);
    }

}

and when I'm opened URL for example http://localhost/ru/ - I saw EN blade template!

But, if I write code

if (strlen(Request::segment(1))=='2')
{
    App::setLocale($request->segment(1));
}

into a routes.php - I successfully change the language!

I will try to explain my problem:

  1. I create route for Password reminder http://localhost/ru/password/email/ - how you can see I used RU(or other lang) in my URL for create Multilanguage form. If I open http://localhost/password/email/ without RU - I can't set language into routes.php , my form will be open only EN language! So that's why I use http://localhost/ru/password/email/ !!!
  2. But, when I send my form, I get a message by EN (We have e-mailed your password reset link! ), while my template by RU!!!

How I can explain it: after click Button http://localhost/ru/password/email/ my page was reloaded to default page http://localhost/password/email/ and e-mail was send, and then I redirect back to http://localhost/ru/password/email/ but with EN errors/status messages.

ivanv's avatar

It's a rough workaround, but maybe you can try this:

  • create views/ru/emails/password.blade.php
  • create views/en/emails/password.blade.php
  • create views/emails/password.blade.php

That last one will be loaded by default, so you could replace its content with this:

@include( App::getLocale() . '.emails.password')

Now it should load the correct language... You might want to check somewhere if the locale is valid (you have views for it)...

For error messages you'll have to create a language file in resources/lang/ru. You can just copy and translate the ones from the resources/lang/en folder.

pmall's avatar

@armix your code seem fine. Are you sure the middleware is run ? What happends if you put dd() in the handle method does it kill the app ?

Are you sure you put a ru subfolder in resources/lang ? With the correct files like https://github.com/caouecs/Laravel4-lang/tree/laravel5 ? Because if it doesnt exist it will put the en translations.

@ivanv please don't post ugly workaround. This thread will probably be read by other people and we don't want to mislead them by making them create a subfolder in view for each locale. The correct approach for internationalization is to set the locale through a middleware so we will get this to work.

ivanv's avatar

@pmall How would you translate static views if they have alot of content? It's not very handy to put it all in a language file... Wouldn't you achieve the same result with the middleware (load the correct translated view)?

armix's avatar
armix
OP
Best Answer
Level 1

I decided my problem, when used into POST a hide form element with language parameter!

armix's avatar

I used DB for save and fetch static content!

Please or to participate in this conversation.