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

Sunday, January 9, 2022

[FIXED] CakePHP 3: How to get current language value in views?

 January 09, 2022     cakephp, cakephp-3.0, internationalization, php     No comments   

Issue

From CakePHP 3 Book

// Before (CakePHP 2)
Configure::write('Config.language', 'fr_FR');

// Now
I18n::locale('en_US');

Before in our CakePHP 2 app

<?php if(Configure::read('Config.language') != 'hrv') {  ?>
    <li>
        <a href="<?php echo $this->Html->url('/hrv'); ?>" class="flag flag-hr">
        <?php echo __('Hrv', true); ?>
        </a>
    </li>
<?php } ?>

How now in CakePHP 3?

in bootstrap:

ini_set('intl.default_locale', 'hr_HR');

in View?


Solution

Quote from the I18n::getLocale() docs:

[...] Will return the currently configure locale as stored in the intl.default_locale PHP setting. [...]

https://api.cakephp.org/3.5/class-Cake.I18n.I18n.html#_getLocale

So

use Cake\I18n\I18n;

if (I18n::getLocale() !== 'hr_HR') // ...


Answered By - ndm
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

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