with a constant value, so
class Model {
var $validate = array('message' => __('My message', true));
}
is invalid PHP. I suppose this is the problem OP encountered.
Of the top of my head I'd say you could try to redeclare these vars in
__construct(), where it would be allowed to use function calls:
class Model {
var $validate = null;
function __construct() {
$this->validate = array('message' => __('...', true));
parent::__construct(); // make sure to call this
}
}
The problem here may or may not be that the models are constructed
before any language switching can take place? I don't know enough
about the internals for that. If that's the case, redeclare the
variable later in another method that will get called for sure.
The alternative is to declare "rules with names", with the multiple
rule syntax:
http://book.cakephp.org/view/133/Multiple-Rules-per-Field
$validate = array(
'field_id' => array(
'myRuleName' => array(
'rule' => ...
)
)
);
Then in the view the error message can be specified in the input field:
http://book.cakephp.org/view/198/options-error
On 15 Sep 2008, at 19:37, martin.westin.gc@gmail.com wrote:
>
> The function prints by default. You need to ass true as a second
> attribute like this:
> __('Username required', true);
>
> IMHO this default behaviour is wrong. I generally need a return value
> more often than I need a print.
> I have put this little wrapper in my bootstrap.php to get the
> behaviour I prefer:
> function ___($singular, $return = true) {
> return __($singular, $return);
> }
>
>
>
>
>
> On Sep 15, 12:31 pm, stefanski <stefansc...@googlemail.com> wrote:
>> some texts in cake are defined in arrays (like model's $validate).
>> What is the best practive to bring the i18n into these texts, because
>> var $validate = array(... 'message' => __('Username required'))
>> doesn't work ... ?
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---
No comments:
Post a Comment