开发者

Multilanguage validation in Kohana

开发者 https://www.devze.com 2023-03-11 03:35 出处:网络
Where should I call __() -function?In Views, or开发者_如何学JAVA Messages? 1. IN VIEWS Messages return array

Where should I call __() -function? In Views, or开发者_如何学JAVA Messages?

1. IN VIEWS

Messages

return array
(
    'username' => array(
        'not_empty'  => 'Not empty',
        'min_length' => 'Min length :param2',
        'max_length' => 'Max length :param2',
        'default'    => 'Default',
    ),
);

View

<?php
    foreach ($errors as $field => $message):
    echo '<li>'.$field.': '.__($message).'</li>'; // here
    endforeach;
?>

2. IN MESSAGES

Messages

return array
(
    'username' => array(
        'not_empty'  => __('Not empty'),          // here
        'min_length' => __('Min length :param2'), // here
        'max_length' => __('Max length :param2'), // here
        'default'    => __('Default'),            // here
    ),
);

View

<?php
    foreach ($errors as $field => $message):
    echo '<li>'.$field.': '.$message.'</li>';
    endforeach;
?>


You must translate validation messages (with placeholders) in i18n files. Read this post.

0

精彩评论

暂无评论...
验证码 换一张
取 消