I'm wondering the exact same thing.
The trans() helper is working but I can't seem to find a way to call something like App::setLocale($locale);
Can't find documention on how to use localization in Lumen framework,does anyone know how to use it?
I'm wondering the exact same thing.
The trans() helper is working but I can't seem to find a way to call something like App::setLocale($locale);
Hi,
You can use this syntax app('translator') to retrieve an Illuminate\Translation\Translator instance.
Regards.
In vendor/laravel/lumen-framework/src/helpers.php:363 a trans($id = null, $parameters = [], $domain = 'messages', $locale = null) function is defined, so you can use it in your views
If you don't request for a certain lang translation, it uses dotenv's APP_LOCALE setting defined in you .env file to get the localised values.
Using Blade:
trans('file.key')
(sorry, I failed to get blade syntax to be highlighted as code, just wrap it in two brackets as usual)
Using plain php:
<?php echo trans('file.key') ?>
I am using Lumen 8.0 version, is there any one who can suggest me how can I use multiple local (English and French) in Lumen? Thanks in advance.
I am using Lumen 8.0 version:
To set new local language:
$request->input('lang') can have any language code eg. en or you can set it manually by passing language code as parameter in setLocale function.
app('translator')->setLocale($request->input('lang'));
To get current local language:
app('translator')->getLocale();
output: en
This worked for me. I hope, this will also help you :)
Please or to participate in this conversation.