QuickForm2: messages and translations
| From: | Alexey Borzov | Date: | Tue, 10 May 2011 16:13:27 +0000 |
| Subject: | QuickForm2: messages and translations | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-54279@lists.php.net to get a copy of this message | ||
Hi,
Some of the QF2 elements (currently Date and InputFile) have built-in translatable messages (weekdays and months lists and upload errors, respectively).
About a year ago Christian Weiske mentioned that the process for providing these messages was a bit unwieldy [1]. Unfortunately this fell through the proverbial cracks and I only recently remembered about the request and started to address it [2]. There is also an old related request about using locale data for dates [3].
I've committed a prototype (meaning: no phpdoc even yet) implementation to a 'message_provider' branch in SVN, it consists of HTML_QuickForm2_MessageProvider interface defining a single get() method and a couple of implementations: one is a default provider having the same strings that previously were in Date and InputFile and the other builds lists for Date elements using strftime().
A message provider implementation is given to an element expecting it in a 'messageProvider' key of $data array. If not given, the default one will be used.
It is also now possible to set default message language via
HTML_Common2::setOption('language', '...');
as it is highly unlikely that a form will contain e.g. dates in several languages at once.
I'd really like to have some feedback (especially from Christian) on the implementation, this will be useful for custom elements as well, so should be well designed.
A couple of questions Bertrand raised:
1) Is get() a good enough method name? Won't it lead to name conflicts in MessageProvider implementations?
2) Is it OK that get() can return an array of messages rather than a single message? Of course, if it can only return strings, we'll need 12 get() calls in a loop in Date element for getting the month names.
[1] http://marc.info/?l=pear-dev&m=127437729906762&w=2
[2] http://pear.php.net/bugs/bug.php?id=18341
[3] http://pear.php.net/bugs/bug.php?id=5558