prgrm
prgrm

Reputation: 3833

I cannot retrieve locale strings in Laravel

For somewhat reason Laravel won't return the string but simply the key:

Here is my messages.php saved in /resources/lang/en/

return[
    'Example' => 'Ejemplo',
    'Otroejemplo' => 'Beispiel',
];

This is my routing:

Route::get('myexample/{locale}', function ($locale)  {
    App::setLocale($locale);
    return view('admin.pages.forms.myexample');
});

And this is myexample.blade.php:

@lang('messages.Example');

I expect to get Ejemplo in return when I open localhost:8000/myexample/en but I get message.Example instead.

Upvotes: 2

Views: 204

Answers (1)

Rahul
Rahul

Reputation: 2474

Tested your code, it's working fine the only issue I got is instead of

   Route::get('myexample/{locale}', function ($locale)  {
    App::setLocale($locale);
    return view('admin.pages.forms.myexample');
});

use

Route::get('myexample/{locale}', function ($locale)  {
    App::setLocale($locale);
    return view('myexample'); // in case your view is in resources folder
});

Upvotes: 2

Related Questions