CakePHP: 本地化选择框里面的数据

If you have a configurable list in table(t_credit_types) like:

1->Gold

2->Silver

3->Bronze


and you have get all data from that table by a find.

Now instead of using the english string in a selection box, you are required to display localized strings.


There are two ways of localizing the selection box in cakephp.


Solution 1. provide localized strings in db table

t_credits_types_lang

(credit_type_id+lang+description)

1->zh_CN->黄金
2->zh_CN->白银
3->zh_CN->黄铜

now you can find all localized strings from this additional table by certain language code.

$types = $this->CreditType->find('list', array(
'conditions' => array('lang'=>'zh_CN'),
'fields' => array('type','description'),
));

echo $form->input('type', array('type' => 'select', 'options' => $types));


Solution 2. localize these strings in view template

say, if you retreived all types by below sql:

$types = $this->CreditType->find('list', array(
'fields' => array('type','description'),
));

in view template, what we need to do is simply as:

$lc_types = array();
foreach($types as $key=>$value) {
$lc_types[$key] = __($value, true);
}
echo $form->input('type', array('type' => 'select', 'options' => $lc_types));


iefreer
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值