Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel class translator does not exist in a configuration file

Is there any way that allows inserting translatable value in configuration file in laravel-5.4 application?

I have a custom configuration file at config/fox-reports.php and I'm trying to set a translatable configuration value looks like the following:

return [
    'attrs' => [
       'Product' => __('Product Title')
    ]
] 

When I run php artisan config:cache the following error is generated:

In Container.php line 729:

  Class translator does not exist
like image 234
SaidbakR Avatar asked Dec 31 '17 15:12

SaidbakR


1 Answers

You can't use the __() helper in config files because it uses Translator class. Laravel loads config at the very beginning of the cycle when most of the services were not initialized yet.

like image 152
Alexey Mezenin Avatar answered Oct 01 '22 04:10

Alexey Mezenin