Quick Tip - Translating Model Variables
While working on a now defunct cms, I was attempting to internationalize model validation messages. I thought I had a pretty good idea as to how to internationalize those messages. Usually, you do the following to any string in CakePHP:
1
| |
And then run the following shell command:
1 2 | |
That should somehow generate .pot files, which is where CakePHP will grab translations.
So I did the following to my rules:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
Don't do that! It will break the entire application! The error message will be something like the following:
1
| |
Not very helpful.
It turns out I forgot to call the parent Model::__construct() function when redefining the constructor. So I did the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | |
Note that you do not need to do var $validate = array(); before the constructor. You can also place any other variables that you would like to translate in the constructor, like I do with my $visibilities variable. Then you'll no longer get that silly trigger() error message. And your app will work again. Hurray! Whoagies unite!
Discussion