PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, February 3, 2022

[FIXED] 'ReflectionException' Class translator does not exists

 February 03, 2022     laravel, laravel-5, localization     No comments   

Issue

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


Solution

You can't use trans() in any config files, because they are loaded before the translation service is registered (which is why you are getting Class translator does not exist).



Answered By - ntzm
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing