
The Zend Framework is making great strides toward version 0.7.
Much to my delight, this release placed particular emphasis on the i18n and l10n components.
Zend_Date, Zend_Measure and Zend_Locale are now new additions to the core. I tried out the new components, and here are a few examples:
Zend_Locale
Displaying the languages configured in the browser
$locale = new Zend_Locale(); $array = $locale->getBrowser();
array(4) {
["de_DE"] => float(1)
["de"] => float(0.8)
["en_US"] => float(0.5)
["en"] => float(0.3)
}
Listing all languages in German
$locale = new Zend_Locale('de_DE'); $array = $locale->getLanguageList();
Yes/No for dialogs
$locale = new Zend_Locale('de_DE'); $array = $locale->getQuestion();
array(4) {
["yes"] => string(2) "ja"
["yesabbr"] => string(1) "j"
["no"] => string(4) "nein"
["noabbr"] => string(1) "n"
}
Zend_Date
Displaying a localized date
$date = new Zend_Date('2006-12-31', Zend_Date::DATE_MEDIUM); echo $date->get(Zend_Date::DATE_FULL, $locale);
Output:
Sonntag, 31. Dezember 2006
Date -> adding, subtracting
$date = new Zend_Date('2006-12-31', Zend_Date::ISO_8601); $date->add(1, Zend_Date::DAY); echo $date->get(Zend_Date::DATE_FULL, $locale);
Output:
Montag, 1. Januar 2007
$date = new Zend_Date('2006-12-31', Zend_Date::ISO_8601); $date->add(1, Zend_Date::DAY); echo $date->get(Zend_Date::DATE_FULL, $locale);
Output:
Montag, 1. Januar 2007
$date = new Zend_Date('2007-03-01', Zend_Date::ISO_8601); $date->subDay(1); echo $date->get(Zend_Date::DATE_FULL, $locale);
Output:
Mittwoch, 28. Februar 2007
Zend_Measure
Converting 1000 meters to miles
$unit = new Zend_Measure(1000, Zend_Measure::LENGTH); echo $unit->convertTo(Zend_Measure_Length::MILE);
Output:
0.621371192237 mi
Conclusion:
The new components are impressive. Many tasks for which we repeatedly developed our own solutions, or simply hardcoded values, can now be implemented elegantly. A select box for choosing a country or language springs to mind. Dialogs can now easily be programmed in a "language-neutral" way, too.
The Zend_Date component finally fills the gaps that PHP's date and time functions could not cover, and provides enough abstraction.
We can also look forward to the upcoming Zend_Translate component for displaying translated text, and Zend_TimeSync.