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

Thursday, March 10, 2022

[FIXED] i18n translations not working in Controller

 March 10, 2022     cakephp, cakephp-3.0, php     No comments   

Issue

Why would i18n translations work in a view, but not in AppController?

Doesn't work - In AppController:

class AppController extends Controller
{
    public function initialize()
    {
        parent::initialize();
        
        debug(__('My English Text'));
        ...
    }
}

Works - In my view:

<p><?= __('My English Text') ?></p>

Solution

I simply had to set the language before calling __(). In my case, it was being set further down the chain in initialize() within AppController.



Answered By - TechFanDan
  • 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