CakePHP 3:如何在视图中获取当前语言值?

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

来自 CakePHP 3 书

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

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

之前在我们的 CakePHP 2 应用程序中

<?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 } ?>

现在 CakePHP 3 怎么样?

在bootstrap中:

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

在视图中?

引自 I18n::getLocale() 文档:

[...] 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

所以

use Cake\I18n\I18n;

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