Commit 66832c41 authored by Klaus Weidenbach's avatar Klaus Weidenbach

Update intl library.

Update intl library from v0.4? (2014) to v0.7.4 (2016).
Use global composer autoloader now.
parent 8e4c5db7

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

......@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "50f781f18deef8573188a713376a711d",
"content-hash": "cc603d3dc499e43f840f9551039fa93c",
"packages": [
{
"name": "bshaffer/oauth2-server-php",
......@@ -62,6 +62,50 @@
],
"time": "2017-01-06T23:20:00+00:00"
},
{
"name": "commerceguys/intl",
"version": "v0.7.4",
"source": {
"type": "git",
"url": "https://github.com/commerceguys/intl.git",
"reference": "edfcfc26ed8505c4f6fcf862eb36dfda1af74b00"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/commerceguys/intl/zipball/edfcfc26ed8505c4f6fcf862eb36dfda1af74b00",
"reference": "edfcfc26ed8505c4f6fcf862eb36dfda1af74b00",
"shasum": ""
},
"require": {
"php": ">=5.4.0"
},
"require-dev": {
"mikey179/vfsstream": "1.*",
"phpunit/phpunit": "~4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "0.x-dev"
}
},
"autoload": {
"psr-4": {
"CommerceGuys\\Intl\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Bojan Zivanovic"
}
],
"description": "Internationalization library powered by CLDR data.",
"time": "2016-12-13T12:33:19+00:00"
},
{
"name": "ezyang/htmlpurifier",
"version": "v4.9.3",
......
......@@ -8,6 +8,7 @@
* language related tasks.
*/
use CommerceGuys\Intl\Language\LanguageRepository;
/**
* @brief Get the browser's submitted preferred languages.
......@@ -298,11 +299,7 @@ function detect_language($s) {
* @param string $s Language code to look up
* @param string $l (optional) In which language to return the name
* @return string with the language name, or $s if unrecognized
*
* @todo include CommerceGuys\Intl through composer like SabreDAV.
*/
require_once(__DIR__ . '/../library/intl/vendor/autoload.php');
use CommerceGuys\Intl\Language\LanguageRepository;
function get_language_name($s, $l = null) {
// get() expects the second part to be in upper case
if (strpos($s, '-') !== false) $s = substr($s, 0, 2) . strtoupper(substr($s, 2));
......
language: php
php:
- 5.4
- 5.5
- 5.6
- hhvm
install:
- composer self-update
- composer install
script:
- ./vendor/bin/phpunit -c ./phpunit.xml --coverage-text --strict
intl
=====
[![Build Status](https://travis-ci.org/commerceguys/intl.svg?branch=master)](https://travis-ci.org/commerceguys/intl)
A PHP 5.4+ internationalization library, powered by CLDR data.
Features:
- NumberFormatter, inspired by [intl](http://php.net/manual/en/class.numberformatter.php).
- Currencies
- Countries
- Languages
Coming soon: date formatting.
Why not use the intl extension?
-------------------------------
The intl extension isn't present by default on PHP installs, requiring
it can hurt software adoption.
Behind the scenes the extension relies on libicu which includes the CLDR dataset,
but depending on the OS/distribution used, could be several major CLDR releases behind.
Since the CLDR dataset is freely available in JSON form, it is possible to
reimplement the intl functionality in pure PHP code while ensuring that the
dataset is always fresh.
Having access to the CLDR dataset also makes it possible to offer additional APIs,
such as listing all currencies.
More backstory can be found in [this blog post](https://drupalcommerce.org/blog/15916/commerce-2x-stories-internationalization).
Formatting numbers
------------------
Formats numbers (decimals, percents, currency amounts) using locale-specific rules.
This ensures that the decimal and grouping separators, the position of the currency
symbol, as well as the actual symbol used match what the user is expecting.
The amounts passed for formatting should already be rounded, because the
formatter doesn't do any rounding of its own.
```php
use CommerceGuys\Intl\Currency\CurrencyRepository;
use CommerceGuys\Intl\NumberFormat\NumberFormatRepository;
use CommerceGuys\Intl\Formatter\NumberFormatter;
$currencyRepository = new CurrencyRepository;
$numberFormatRepository = new NumberFormatRepository;
$currency = $currencyRepository->get('USD');
$numberFormat = $numberFormatRepository->get('en');
$decimalFormatter = new NumberFormatter($numberFormat);
echo $decimalFormatter->format('1234.99'); // 123,456.99
$percentFormatter = new NumberFormatter($numberFormat, NumberFormatter::PERCENT);
echo $percentFormatter->format('0.75'); // 75%
$currencyFormatter = new NumberFormatter($numberFormat, NumberFormatter::CURRENCY);
echo $currencyFormatter->formatCurrency('2.99', $currency); // $2.99
// The accounting pattern shows negative numbers differently and is used
// primarily for amounts shown on invoices.
$invoiceCurrencyFormatter = new NumberFormatter($numberFormat, NumberFormatter::CURRENCY_ACCOUNTING);
echo $invoiceCurrencyFormatter->formatCurrency('-2.99', $currency); // (2.99$)
// Arabic, Arabic extended, Bengali, Devanagari digits are supported as expected.
$currency = $currencyRepository->get('USD', 'ar');
$numberFormat = $numberFormatRepository->get('ar');
$currencyFormatter = new NumberFormatter($numberFormat, NumberFormatter::CURRENCY);
echo $currencyFormatter->formatCurrency('1230.99', $currency); // US$ ١٬٢٣٠٫٩٩
// Parse formatted values into numeric values.
echo $currencyFormatter->parseCurrency('US$ ١٬٢٣٠٫٩٩', $currency); // 1230.99
```
Currencies
----------
```php
use CommerceGuys\Intl\Currency\CurrencyRepository;
// Reads the currency definitions from resources/currency.
$currencyRepository = new CurrencyRepository;
// Get the USD currency using the default locale (en).
$currency = $currencyRepository->get('USD');
echo $currency->getCurrencyCode(); // USD
echo $currency->getNumericCode(); // 840
echo $currency->getFractionDigits(); // 2
echo $currency->getName(); // US Dollar
echo $currency->getSymbol(); // $
echo $currency->getLocale(); // en
// Get the USD currency using the fr-FR locale.
$currency = $currencyRepository->get('USD', 'fr-FR');
echo $currency->getName(); // dollar des États-Unis
echo $currency->getSymbol(); // $US
echo $currency->getLocale(); // fr-FR
$allCurrencies = $currencyRepository->getAll();
```
Countries
---------
```php
use CommerceGuys\Intl\Country\CountryRepository;
// Reads the country definitions from resources/country.
$countryRepository = new CountryRepository;
// Get the US country using the default locale (en).
$country = $countryRepository->get('US');
echo $country->getCountryCode(); // US
echo $country->getTelephoneCode(); // 1
echo $country->getName(); // United States
// Get the US country using the fr-FR locale.
$country = $countryRepository->get('US', 'fr-FR');
echo $country->getName(); // États-Unis
$allCountries = $countryRepository->getAll();
```
Languages
---------
```php
use CommerceGuys\Intl\Language\LanguageRepository;
// Reads the language definitions from resources/language.
$languageRepository = new LanguageRepository;
// Get the german language using the default locale (en).
$language = $languageRepository->get('de');
echo $language->getLanguageCode(); // de
echo $language->getName(); // German
// Get the german language using the fr-FR locale.
$language = $languageRepository->get('de', 'fr-FR');
echo $language->getName(); // allemand
$allLanguages = $languageRepository->getAll();
```
Implementing the library
------------------------
While the library can be used as-is, most applications will want to store the
relevant definitions (currencies, countries, etc) in the database.
This allows for better performance while giving users the ability to modify and
expand the data.
Taking currencies as an example, a merchant frequently wants to be able to:
- Define custom currencies.
- Enable/disable existing currencies
- Modify an existing currency (changing the default number of fraction digits, for example).
This would be accomplished by using the CurrencyRepository to get all default currencies and
insert them into the database. The doctrine entity (or any similar data object) would then implement
the CurrencyInterface so that the NumberFormatter can continue to work.
Related projects
----------------