PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, February 10, 2022

[FIXED] Laravel 5 config locale, does not works

 February 10, 2022     laravel, laravel-5, locale, php, validation     No comments   

Issue

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?


Solution

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.



Answered By - felipe_dmz
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing