Monday
20
July
2009

Pluralization

I have great news for you…

As with release 1.9 Zend Framework supports pluralization.
Yes you heard correct… pluralization.

I added this amazing feature to Zend_Translate at 1.May and today it was accepted for core.
Support for plural forms depends on the used adapter. Therefor it is actually only available for
Array, Csv and Gettext. Until now I found no way to support it for other formats. When you know details for a unsupported format feel free to give them to me.

So how does this work…

First off, there is no change to existing applications and code.
When you take a look at plural support within php’s gettext extension you will see that you must use another method for it.

That’s not the case for Zend_Translate. You can use the existing translate() method and get a pluralized translation. Of course, when you like it the old fashion way you can still use a own method. :-)

Let’s go into code:
You can eighter do:

$translate->plural('Car', 'Cars', $number);

when you want to use a own method. Or you can use the translate() method like described here:

$translate->translate(array('Car', 'Cars', $number));

So when you want to use plural translation simply give an array with the original plural forms as messageid.
Easy, isn’t it ?

But Zend_Translate supports another feature with pluralization..
Actually pluralization is limited to languages which use english forms.
Look at php’s ngettext() method. It needs to have one plural and one singular form to be able to translate. But several languages have more than 1 plural forms. This means on the other side that ngettext can not be used with languages like russian or indian which have more than 2 plural forms.

With Zend_Translate your source code can be ANY language… you can do things like

$translate->translate(array('Auto', 'Autos', 'Auti', 'Autom', $number));

Not that I know the proper plural forms, but you get a feeling for what I meant.

For more details about how plural translations work take a look at the manual. I added a own chapter for it and hope you find it usefull.

As always I will keep you informed about my work.

Greetings
Thomas Weidner
I18N Team Leader, Zend Framework

Zend Framework Advisory Board Member
Zend Certified Engineer for Zend Framework

Back to top
Sunday
19
July
2009

News from the back

A few days ago several proposals which I’ve written in past have been accepted.
I’m sorry to say that, but as 1.9 is already waiting at the door non of this proposals will be within ZF 1.9.

Let’s take a look at the components which are accepted and what 1.10 could have as new feature from my side:

*) Zend_Filter_Compress:
A compression filter… this one can already be found within the incubator in a preview version. It supports ZIP, GZ, BZ2 and LZF. It will be within 1.10. I’m not sure if I will add also other compression formats.

*) Zend_Filter_Boolean:
A filter converting all things to boolean BUT additionaly supports “true”, “false” strings and “yes”, “no” strings from any language.

*) Zend_Validate_PostCode:
A validator which checks if a input is a postal code regardless of its country

*) Zend_Validate_Phone:
A validator which checks if a input is a phone number in a defined format. This one is a little bit tricky and should have a cousine Zend_Filter_Phone. In the time I wanted to add it another guy added his own idea of a phone filter. As I saw it does not conform the ITU standard nor does it work with non-US numbers. I will add my version and look if those two can be combined. As I am originally a certified professional telecommunication engineer I should be the best for creating such a component :-) So this one will still take some time.

*) Zend_Validate_Callback:
A validator which can use your own custom functions as validator.

*) Zend_View_Helper_Currency:
A view helper to simplify the handling of currencies.

*) Zend_View_Helper_Date:
A view helper to simplify the handling of dates.

Additionally Zend has accepted the proposal from Mikael and me regarding a completly reworked documentation. It is already cored (even if the work itself is not done for now :-) ) and will add things like
- Translated Quickstart Guide
- Comments for the manual
- A great tool for translators which simplifies finding errors and problems (this one will propably added to Zend’s CI server)
- and much much more

Now you may say this is enough work for one person… you may be right… but I still have some ideas for which I have not written proposals until now.

For 1.9 I have added plural support for Zend_Translate in May. But until now it has not been accepted, so I expect that this feature will be delayed to 1.10.

As always I will keep you informed about my work. Have a nice ZF-ing.

Greetings
Thomas Weidner
I18N Team Leader, Zend Framework

Zend Framework Advisory Board Member
Zend Certified Engineer for Zend Framework

Back to top
Wednesday
8
July
2009

Zend_Date support for complete localized dates

Today I added a new feature within Zend_Date which allows to use complete localized dates.

Until Zend Framework 1.8 you had eighter to create your own format manually, or to concat the output manually to get a string like “13.April.2009 10:20:10”.

Actually this formats are very common and as with Zend Framework 1.9 they are supported.
In sum there are 5 variants of this format.

*) Zend_Date::DATETIME
*) Zend_Date::DATETIME_FULL
*) Zend_Date::DATETIME_LONG
*) Zend_Date::DATETIME_MEDIUM
*) Zend_Date::DATETIME_SHORT

As you may have mentioned these new formats are nearly equal to existing ones.
For a date we have Zend_Date::DATE_FULL and for a time representation Zend_Date::TIME_FULL.

In the background DATETIME is defined as a concation of Date and Time. But as we are in a localized environment you have to note that it depends on the locale of the date or the time part is written first and the other part afterwards.

Let’s take a look into a short example:

$date = new Zend_Date();
print $date->toString(Zend_Date::DATETIME_MEDIUM);

This will output 08.07.2009 20:30:33 within the german locale.
But you have to note that the output you will get is still dependent on your locale.

Other new features are on the road and are only waiting for response to be integrated into core.

Greetings
Thomas Weidner
I18N Team Leader, Zend Framework

Zend Framework Advisory Board Member
Zend Certified Engineer for Zend Framework

Back to top