gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 07:24:37 24 4
gpt4 key购买 nike

来自 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');

在 View 中?

最佳答案

引自 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') // ...

关于php - CakePHP 3 : How to get current language value in views?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34571516/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com