Building cake application (Part VI)

Saturday (Day 6)

Problem with validation messages while translating
Although my native language is Bulgarian and the requirement from the client was to have this site only in Bulgarian, I’ve preferred to have it in English and to make the translation with the i18n functions of CakePHP. There are 2 reasons to do this:

1. This will give me the possibility to show you the result of all these days of coding and
2. I can reuse some part of the codes the same as I’ve used in this project

So, up to my experience having application in English is never a bad idea. 🙂

You know, that the translating process is not very exciting process, but someone need to do it and because there is no one who can help me with this I’ve start the translation. Anyway. 🙁

While translating I noticed that the most of the validation messages are not appear of the translation file. I knew this from my past experience, but I needed to find an easy and elegant solution to translate these messages instead of putting them in all views. Putting in the view you need to do this at least 2 times.

The problem – it’s not possible to use a function in class variable definition like:

var $validate = array(
'email' => array(
'unique' => array(
            'rule' => 'isUnique',
                'message'=>__('This e-mail has already been used', true),
            'emailAddress' => array(
                'rule' => array('email', true),
                'message' => __('Please supply a valid email address.', true)

The PHP script returns an error: Parse error.

I immediately start thinking of a function which will parse the $validate var and to wrap all messages with __() function. Not very wise solution, anyway. The solution here is very simple – just place the $validate array in the beforeValidate() function. Simple and elegant.

Tuning the design
It was pain of course, some of the form elements were totally messed up, but it wasn’t unsolvable problem 🙂 Now everything look like as it should. I’ve tested this app for FF3, IE7, IE6 and Safari for Win, and so far it look without big differences.

Testing the whole system
I am not going to writing test scripts, while i should do sometimes. I would really like to know how it’s working the search query with large amount of data /at least this is the most “heavy” part of the application.

The conclusion
That’s it. For six days I’ve build that application without working “day and night”. I’ve deliver it on time, as agreed with the client and so far they are happy with the final result which is the most important task in the development process.

Hope you enjoy this series of posts, and I hope they weren’t too boring without any technical details, but this was the idea from the beginning – to make a diary instead of How to.

The result
If you are curious what I’ve build, then visit

External part:
user: demo
pass: demo

Admin part:
user: admin
pass: admin

For security reasons, I’ve disabled the e-mail validation, as well as all e-mails sent from the application. Passwords cannot be changed as well. You have to trust me, but they working in the real application. 🙂

See also
Building cake application (Part I)
Building cake application (Part II)
Building cake application (Part III)
Building cake application (Part IV)
Building cake application (Part V)

Leave a Reply

Your email address will not be published. Required fields are marked *