Please see PEARs API
Documentation for details on the API provided by I18Nv2.
Setting a locale
Because Un*x and Windows use different locale codes, PHPs setLocale() is not
easily portable -
I18Nv2::setLocale() attempts to
provide this portability.
With I18Nv2 you can use standard locale codes like 'en_US' on both, Linux
and Windows, though the list is far not complete yet, so if you stumble
over a not covered locale (I18Nv2::$locales in I18Nv2::_main()), just
drop a mail to the maintainer with the missing locale and its corresponding
Win32 code.
require_once 'I18Nv2.php';
foreach (array('en_US', 'de', 'fr_CN') as $locale) {
if (!$syslocale = I18Nv2::setLocale($locale)) {
echo "Locale '$locale' not available!\n";
} else {
echo "Systems locale for '$locale': '$syslocale'\n";
}
}
Retrieving locale conventions
I18Nv2 holds locale conventions returned by localeConv() stored statically,
so they are easily accessible through
I18Nv2::getInfo().
Have a look at the documentation of PHPs
localeConv() for all
available information.
require_once 'I18Nv2.php';
I18Nv2::setLocale('fr');
$dec_point = I18Nv2::getInfo('decimal_point');
echo "The decimal point for the french locale is '$dec_point'.\n";
echo "I18Nv2::getInfo() called without parameter returns all available information:\n";
print_r(I18Nv2::getInfo());
require_once 'I18Nv2.php';
// Writing a shell app that should also display nicely in a DOS box
if (I18Nv2_WIN) {
I18Nv2::autoConv('CP850');
}
// output some latin1 stuff
echo "δόφί\n";
Using I18Nv2_Locale
I18Nv2_Locale is a formatter object that provides functionality to format
dates, times, numbers and currencies in locale dependent conventions.
require_once 'I18Nv2/Country.php';
$country = &new I18Nv2_Country('de', 'iso-8859-1');
echo "German name for United States: ",
$country->getName('us'), "\n";
echo "German name for Italia: ",
$country->getName('it'), "\n";
Using I18Nv2_Country
I18Nv2 provides decorated classes for country and language lists.