'ReflectionException' Class translator does not exists

时间:2017-08-04 11:56:45

标签: laravel laravel-5 localization

I'm trying to use localization as follow,

$types = trans('constants.type');

I have created constants.php file as follows (which is in config directory) and this are it's language files,

/resources
    /lang
        /en
            constants.php
        /es
            constants.php

constants.php

return ['type' => 'Type'];

same way it translated in other file with same format, but this things gives me following error

Note: I have used this in config directory's file,

(1/1) ReflectionException Class translator does not exist

in Container.php (line 729) at ReflectionClass->__construct('translator') in Container.php (line 729) at Container->build('translator') in Container.php (line 608) at Container->resolve('translator') in Container.php (line 575) at Container->make('translator')

Problem:

trans() method not working in constants.php file which i have created in config directory as follow,

/config constants.php

1 个答案:

答案 0 :(得分:8)

您无法在任何配置文件中使用trans(),因为它们是在注册翻译服务之前加载的(这就是您获得Class translator does not exist的原因)。