This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/Intl
2013-04-05 10:11:14 +02:00
..
Collator [Intl] Refactored Locale component into two new components Icu and Intl 2013-04-05 10:11:14 +02:00
DateFormatter [Intl] Refactored Locale component into two new components Icu and Intl 2013-04-05 10:11:14 +02:00
Exception [Intl] Refactored Locale component into two new components Icu and Intl 2013-04-05 10:11:14 +02:00
Globals [Intl] Refactored Locale component into two new components Icu and Intl 2013-04-05 10:11:14 +02:00
Locale [Intl] Refactored Locale component into two new components Icu and Intl 2013-04-05 10:11:14 +02:00
NumberFormatter [Intl] Refactored Locale component into two new components Icu and Intl 2013-04-05 10:11:14 +02:00
ResourceBundle [Intl] Refactored Locale component into two new components Icu and Intl 2013-04-05 10:11:14 +02:00
Resources [Intl] Refactored Locale component into two new components Icu and Intl 2013-04-05 10:11:14 +02:00
Tests [Intl] Refactored Locale component into two new components Icu and Intl 2013-04-05 10:11:14 +02:00
Util [Intl] Refactored Locale component into two new components Icu and Intl 2013-04-05 10:11:14 +02:00
.gitignore [Intl] Refactored Locale component into two new components Icu and Intl 2013-04-05 10:11:14 +02:00
composer.json [Intl] Refactored Locale component into two new components Icu and Intl 2013-04-05 10:11:14 +02:00
CONTRIBUTING.md [Intl] Refactored Locale component into two new components Icu and Intl 2013-04-05 10:11:14 +02:00
Intl.php [Intl] Refactored Locale component into two new components Icu and Intl 2013-04-05 10:11:14 +02:00
LICENSE [Intl] Refactored Locale component into two new components Icu and Intl 2013-04-05 10:11:14 +02:00
phpunit.xml.dist [Intl] Refactored Locale component into two new components Icu and Intl 2013-04-05 10:11:14 +02:00
README.md [Intl] Refactored Locale component into two new components Icu and Intl 2013-04-05 10:11:14 +02:00

Intl Component

A PHP replacement layer for the C intl extension that includes additional data from the ICU library.

The replacement layer is limited to the locale "en". If you want to use other locales, you should [install the intl extension] [10] instead.

Installation

You can install the component in two different ways:

If you install the component via Composer, the following classes and functions of the intl extension will be automatically provided if the intl extension is not loaded:

  • [\Locale] [2]
  • [\NumberFormatter] [3]
  • [\IntlDateFormatter] [4]
  • [\Collator] [5]
  • [intl_is_failure()] [6]
  • [intl_get_error_code()] [7]
  • [intl_get_error_message()] [8]
  • [intl_error_name()] [9]

If you don't use Composer but the Symfony ClassLoader component, you need to load them manually by adding the following lines to your autoload code:

if (!function_exists('intl_is_failure')) {
    require '/path/to/Icu/Resources/stubs/functions.php';

    $loader->registerPrefixFallback('/path/to/Icu/Resources/stubs');
}

Stubbed Classes

The stubbed classes of the intl extension are limited to the locale "en" and will throw an exception if you try to use a different locale. For using other locales, [install the intl extension] [10] instead.

Locale

The only method supported in the [´\Locale] [2] class is getDefault()` and will always return "en". All other methods will throw an exception when used.

NumberFormatter

Numbers can be formatted with the [\NumberFormatter] [3] class. The following methods are supported. All other methods are not supported and will throw an exception when used.

__construct($locale = 'en', $style = null, $pattern = null)

The only supported locale is "en". The supported styles are \NumberFormatter::DECIMAL and \NumberFormatter::CURRENCY. The argument $pattern may not be used.

::create($locale = 'en', $style = null, $pattern = null)

See __construct().

formatCurrency($value, $currency)

Fully supported.

format($value, $type = \NumberFormatter::TYPE_DEFAULT)

Only type \NumberFormatter::TYPE_DEFAULT is supported.

getAttribute($attr)

Fully supported.

getErrorCode()

Fully supported.

getErrorMessage()

Fully supported.

getLocale($type = \Locale::ACTUAL_LOCALE)

The parameter $type is ignored.

parse($value, $type = \NumberFormatter::TYPE_DOUBLE, &$position = null)

The supported types are \NumberFormatter::TYPE_DOUBLE, \NumberFormatter::TYPE_INT32 and \NumberFormatter::TYPE_INT64. The parameter $position must always be null.

setAttribute($attr, $value)

The only supported attributes are \NumberFormatter::FRACTION_DIGITS, \NumberFormatter::GROUPING_USED and \NumberFormatter::ROUNDING_MODE.

The only supported rounding modes are \NumberFormatter::ROUND_HALFEVEN, \NumberFormatter::ROUND_HALFDOWN and \NumberFormatter::ROUND_HALFUP.

Included Resource Bundles

The ICU data is located in several "resource bundles". You can access a PHP wrapper of these bundles through the static Intl class.

Languages and Scripts


The translations of language and script names can be found in the language
bundle.

    $languages = Intl::getLanguageBundle()->getLanguageNames('en');
    // => array('ab' => 'Abkhazian', ...)

    $language = Intl::getLanguageBundle()->getLanguageName('en', 'de');
    // => 'German'

    $language = Intl::getLanguageBundle()->getLanguageName('en', 'de', 'AT);
    // => 'Austrian German'

    $scripts = Intl::getLanguageBundle()->getScriptNames('en');
    // => array('Arab' => 'Arabic', ...)

    $script = Intl::getLanguageBundle()->getScriptName('en', 'Hans');
    // => 'Simplified'

Countries
~~~~~~~~~

The translations of country names can be found in the region bundle.

    $countries = Intl::getRegionBundle()->getCountryNames('en');
    // => array('AF' => 'Afghanistan', ...)

    $country = Intl::getRegionBundle()->getCountryName('en', 'GB');
    // => 'United Kingdom'

Locales
~~~~~~~

The translations of locale names can be found in the locale bundle.

    $locales = Intl::getLocaleBundle()->getLocaleNames('en');
    // => array('af' => 'Afrikaans', ...)

    $locale = Intl::getLocaleBundle()->getLocaleName('en', 'zh_Hans_MO');
    // => 'Chinese (Simplified, Macau SAR China)'

Currencies
~~~~~~~~~~

The translations of currency names and other currency-related information can
be found in the currency bundle.

    $currencies = Intl::getCurrencyBundle()->getCurrencyNames('en');
    // => array('AFN' => 'Afghan Afghani', ...)

    $currency = Intl::getCurrencyBundle()->getCurrencyNames('en', 'INR');
    // => 'Indian Rupee'

    $symbol = Intl::getCurrencyBundle()->getCurrencyNames('en', 'INR');
    // => '₹'

    $fractionDigits = Intl::getCurrencyBundle()->getFractionDigits('INR');
    // => 2

    $roundingIncrement = Intl::getCurrencyBundle()->getRoundingIncrement('INR');
    // => 0

Resources
---------

You can run the unit tests with the following command:

    $ cd path/to/Symfony/Component/Intl/
    $ composer.phar install --dev
    $ phpunit

[0]: /components/using_components
[1]: https://packagist.org/packages/symfony/intl
[2]: http://www.php.net/manual/en/class.locale.php
[3]: http://www.php.net/manual/en/class.numberformatter.php
[4]: http://www.php.net/manual/en/class.intldateformatter.php
[5]: http://www.php.net/manual/en/class.collator.php
[6]: http://www.php.net/manual/en/function.intl-error-name.php
[7]: http://www.php.net/manual/en/function.intl-get-error-code.php
[8]: http://www.php.net/manual/en/function.intl-get-error-message.php
[9]: http://www.php.net/manual/en/function.intl-is-failure.php
[10]: http://www.php.net/manual/en/intl.setup.php