Gettext nightmare again
- Loic d'Anterroches
- 2011-02-28 @ 13:10
so, again, porting the form validation from Pluf to Photon brings me to
the painful situation we all know too well. Gettext is practically
unusable in a web application context.
At the moment, I already have a nice implementation to do translations,
but, I have nothing to format dates and numbers.
So, shopping around brings the work of Zend with Zend_Locale. But...
read the code:
It looks like the guy coding this has not been thinking about
performance. When you look at the elegance of the Django way:
then, I wonder. Isn't it Zend supposed to be the reference for high
quality and readable PHP code?
So, if somebody has something good, please let me know. We will need to
take care of this issue, this is a hard one, but skipping on the hard
stuff is not the way to go to have a truly exceptional framework at the
end of the day.
A bit of a summary of the issues, locale aware handling of the data is
needed only at the interface between the web application (the system)
and the rest of the world (the client). In the system, everything is
done in utf-8, english with typed variables. Yes PHP as types, so a
float is a float, an integer an integer and so on. In the system, all
the dates + time will be timezone aware. At the moment, they are all
considered GMT dates + time (dates only, that is, whithout the time
component, have no timezone attached information anyway).
The problem is, when I submit a form as a French man, in my input for
the cost of a 100gr of chocolate, I will put: [5,5€ ]
As someone from the US, I would put: [$0.5 ] (bulk supermarkted
chocolate is not good but cheap).
Notice the decimal separator? "," and "." and the position of the
currency symbol? The same way, as a French, I read the prices as 5,5€
and in the US as $0.5.
This means that we need to convert from/to the right representation
depending of the locale. The "from" is done in the form validation and
the "to" is done in your templates (or the output you build manually).
The first really important step is to do the "from" first. That is, we
want to have sanitized values in our application. The "to" part, we can
do it a bit later.
So, annoying but needed. I will follow the lead from the Django coders
(I really admire their work) and try to keep the performance and
simplicity for all of us.
Thank you for your patience...
Indefero - Project management and code hosting - http://www.indefero.net
Photon - High Performance PHP Framework - http://photon-project.com
Céondo Ltd - Web + Science = Fun - http://www.ceondo.com