felipe_dmz
felipe_dmz

Reputation: 95

Laravel 5 config locale, does not works

Modifications done:

on config/app.php

'locale' => env('APP_LOCALE', 'en'),
'fallback_locale' => 'en',

on .env

APP_LOCALE=pt

I've also duplicated the /resources/lang/en files to /resources/lang/pt files as docs suggests.

The problem:

All my validation messages are still in english, and running php artisan tinker:

>>> Lang::getLocale()
=> "en"

>>> env('APP_LOCALE')
=> "pt"

Help?

Upvotes: 1

Views: 10220

Answers (2)

Maulik Shah
Maulik Shah

Reputation: 421

php artisan config:clear

php artisan cache:clear 

php artisan config:cache

If you are using the config:cache command during deployment, you must make sure that you are only calling the env() from within your configuration files, and not from anywhere else in your application.

If you are calling env from within your application, it is strongly recommended you add proper configuration values to your configuration files and call env from that location instead, allowing you to convert your env calls to config calls.

Read whole thread over issue here.

Upvotes: 0

felipe_dmz
felipe_dmz

Reputation: 95

I've already figured out how to solve that:

<?php namespace App\Http\Middleware;

use Closure;
use Session;
use App;
use Config;

class Locale {

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        App::setLocale(env('APP_LOCALE'));
        return $next($request);
    }

}

On Kernel.php

protected $middleware = [
    .
    .
    .

    'App\Http\Middleware\Locale'
];

UPDATE:

My config was cached by command:

php artisan config:cache

So, I've done:

php artisan config:clear

And the middleware above isn't necessary anymore.

Upvotes: 3

Related Questions