See the supported countries and locales for a full list of what the package includes.
To work with countries, use the factory method:
use AppLocalize\Localization;
use AppLocalize\Localization\Country\CountryES;
$countries = Localization::createCountries();
// Get a country by its two-letter ISO code
$germany = $countries->getByISO('de');
// Every country has a constant for its ISO code
$spain = $countries->getByISO(CountryES::ISO_CODE);
// Or use the predefined list via choose()
$france = $countries->choose()->fr();To work with currencies, use the factory method:
use AppLocalize\Localization;
use AppLocalize\Localization\Currency\CurrencyEUR;
$currencies = Localization::createCurrencies();
// Get a currency by its three-letter ISO code
$dollar = $currencies->getByISO('USD');
// Every currency has a constant for its ISO code
$euro = $currencies->getByISO(CurrencyEUR::ISO_CODE);
// Or use the predefined list via choose()
$pound = $currencies->choose()->gbp();A currency retrieved from a country offers formatting adjusted to that country's conventions:
use AppLocalize\Localization;
$eurDE = Localization::createCountries()
->choose()
->de()
->getCurrency();
echo $eurDE->makeReadable(1445.42);Output:
1.445,42 €
All supported countries have a time zone associated with them:
use AppLocalize\Localization;
$timeZone = Localization::createCountries()
->choose()
->de()
->getTimezone();
echo $timeZone->getID(); // Europe/Berlin
echo $timeZone->getZoneLabel(); // Europe
echo $timeZone->getLocationLabel(); // Berlin
echo $timeZone->getLabel(); // Europa/Berlin (in the de_DE locale)For countries with multiple time zones, a historically established project default is returned:
| Country | Default time zone |
|---|---|
| US | US/Eastern |
| CA | America/Vancouver |