Multilanguage validation in Kohana
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.
精彩评论