0

We have a config file for our CAKEPHP app and we want to add there some "tags" so our translation team dont have to change the customer name always. In a prior iteration of our app using CakePHP2 what we did was override in basics.php the definition of the __() function and add a str_replace with the tags we wanted.

Example: If the translator added the tag [[CUSTOMER]] then CakePHP will get the CUSTOMER constant in our config file and str_replace would replace it in the basics.php prior to being displayed.

We know this is not the way to go as we were changing framework code instead of extending it and for CakePHP4 we want to do it the correct way.

Is there anyway to do this? Where do we have to do it?

Regards.

Khel_MVA
  • 48
  • 5
  • Would it work to have a middleware layer that makes these adjustments after the entire page has been rendered? – Greg Schmidt Jun 26 '20 at 15:06
  • @GregSchmidt I need it before rendering the page so its changed before shown to the user. – Khel_MVA Jun 26 '20 at 15:17
  • Middleware can change the content after it's been internally rendered, but before it's sent to the user. – Greg Schmidt Jun 26 '20 at 19:12
  • @GregSchmidt Any place were I can check other than the usual CakePHP book or docs?? – Khel_MVA Jun 26 '20 at 22:07
  • 1
    [Here](https://github.com/oscarotero/psr7-middlewares/blob/master/src/Middleware/Gzip.php) is an example of a very simple middleware that alters the body before sending it. Instead of calling `$transformer` like they do there, you'd do your string replacements. – Greg Schmidt Jun 26 '20 at 22:57
  • @GregSchmidt Thanks :) I think we understand what to do. Care to add an answer so I can accept it and upvote it? – Khel_MVA Jun 27 '20 at 11:35

0 Answers0