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

Hrach's avatar

How to use localization in Lumen?

Can't find documention on how to use localization in Lumen framework,does anyone know how to use it?

0 likes
5 replies
clem's avatar

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);

Mike-e's avatar

Hi,

You can use this syntax app('translator') to retrieve an Illuminate\Translation\Translator instance.

Regards.

1 like
m4grio's avatar

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') ?>
1 like
kamleshcgtechno's avatar

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.

1 like
pappupasshogaya's avatar

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 :)

1 like

Please or to participate in this conversation.