我正在尝试使用cakephp中的本地化功能。在app_model.php我有一个获取不同付款方式的方法。
function getDistinctFields($model, $field)
{
$list = ClassRegistry::init($model)->find('all', array(
'fields'=>array("DISTINCT $model.$field"),
'conditions' => array('not' => array("$model.$field" => null))
));
debug($list);
$translated = "{n}.$model.$field";
$return = Set::combine($list, "{n}.$model.$field", __($translated, true));
return $return;
}
调试的结果($ list)如下所示:
[0] => Array
(
[InstantPaymentNotification] => Array
(
[payment_status] => Pending
)
)
[1] => Array
(
[InstantPaymentNotification] => Array
(
[payment_status] => Completed
)
)
[2] => Array
(
[InstantPaymentNotification] => Array
(
[payment_status] => Denied
)
)
[3] => Array
(
[InstantPaymentNotification] => Array
(
[payment_status] => Refunded
)
)
该方法的输出如下所示:
> Array (
> [Pending] => Pending
> [Completed] => Completed
> [Denied] => Denied
> [Refunded] => Refunded
> [Reversed] => Reversed
> [Canceled_Reversal] => Canceled_Reversal )
更好,但价值未按原样转换。我在正确的位置创建了default.po文件并进行了测试,看它是否适用于其他页面。但是,它似乎不适用于Set类。
答案 0 :(得分:0)
您需要在致电foreach
后在Set::combine
内手动进行本地化。您当前正在做的是本地化字符串“{n} .InstantPaymentNotification.payment_status”,然后将该值发送到Set::combine
函数。
你需要做更多这样的事情:
function getDistinctFields($model, $field) {
$list = ClassRegistry::init($model)->find('all', array(
'fields'=>array("DISTINCT $model.$field"),
'conditions' => array('not' => array("$model.$field" => null))
));
$list = Set::combine($list, "{n}.$model.$field", "{n}.$model.$field");
foreach ($list as &$item) {
$item = __($item, true);
}
return $list;
}