Title: Lumen fails to change locale
Tags: php;lumen
Question: I have an almost fresh installation of Lumen.
I have a POST route which leads to one Controller. In the request I send lang parameter with a string value.
public function form(Request $request)
if ($request-&gt;has('lang')) {
app('config')-&gt;set('app.locale', $request-&gt;input('lang'));
return view('form');
I have one folder more in my /resources/lang/ folder called bg. In this folder I have simple file which has an array just like in resources/lang/en/validation.php - called static.php.
In the view I'm displaying I have few lines that say:
<input type="text" name="email" value="" class="input-default" placeholder="{{trans('static.enter_email')}}"/&gt;
The text I've set in those lang files in resources/lang/... are properly displayed, but I cannot change the locale before displaying the form.
For example, if in my dotenv file I set:
APP_LOCALE=en
And load the view the strings in resources/lang/en/static.php are loaded.
If I change the APP_LOCALE to bg and load the view again, I get the strings from resources/lang/bg/static.php.
All I want is to set the locale before rendering the view, which doesn't seem to work with the code (in my controller) I provided above.
Also I couldn't find any information about localization in Lumen on the official site, but I suppose it supports such, since trans() is working.
Comment: `Shouldn't it be $app('config') not app('config')` what do you want to say?

Comment: Shouldn't it be $app('config') not app('config') ?

Here is the accepted answer: You are changing the config after it is loaded, which has no effect. To change the locale at runtime use the setLocale() method on the app instance:
app()-&gt;setLocale($request-&gt;input('lang'));
The first answer seem to only work on Laravel. To change the locale at runtime with Lumen use this:
app('translator')-&gt;setLocale($request-&gt;input('lang'));
Comment for this answer: Are you sure that this method is present in Lumen? Because I get this error: `Call to undefined method Laravel\Lumen\Application75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0setLocale()`
Comment for this answer: Thanks it works now! Obviously, Lumen's docs are not that new-to-laravel developers friendly.
Comment for this answer: I have more than 20 languages in my lumen api project and each language has more than 50 files and each file has more than 100 labels/messages to translate. Could you please suggest me how can translate all the files in all the languages by command line or any easy method instead of changing language file manually one-by-one. Thanks a lot. Look forward to hear you.
Comment for this answer: In `bootstrap/app.php`, I added `app('translator')->setLocale('fr');` and that doesn't work with Lumen 5.1. How to solve that ?
Comment for this answer: You're right. I just assumed that it would work with Lumen as well. Sorry about that. I've updated my answer with new information.

Here is another answer: Changing locale at the runtime varying depends on the framework.
You can use facade or helper function:
For Lumen:
Lang75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0setLocale('lang');
app('translator')-&gt;setLocale('lang');
For Laravel:
App75b5:f2c1:f5d7:b954:8dc3:cee9:baf:a8c0setLocale('lang');
app()-&gt;setLocale('lang');
Comment for this answer: I am using Lumen 8.0 version and `app('translator')->setLocale('en');` helped me to set english language. Thanks dear.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2015:00:07/06/15', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<php><lumen>', 'Title': 'Lumen fails to change locale', 'ViewCount': 6626, 'id': 31244624, 'user_AboutMe': '<p><code>(‘‘,)</code></p>\n', 'user_AccountId': 464113.0, 'user_DisplayName': 'Ivanka Todorova', 'user_Reputation': 9641.0, 'user_Views': 4705.0, 'user_id': 867418.0}}