Kohana的多语言验证

时间:2011-06-06 08:04:33

标签: validation internationalization kohana multilingual

我应该在哪里致电__() -function? 在视图或消息中?

  

1。在视图中

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。在消息中

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

1 个答案:

答案 0 :(得分:1)

您必须在i18n文件中翻译验证消息(带占位符)。阅读this post