Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cce4b51

Browse files
committed
Added a sidebar about potential deployment problems with ICU
1 parent 64da9d7 commit cce4b51

File tree

1 file changed

+114
-18
lines changed

1 file changed

+114
-18
lines changed

components/intl.rst

+114-18
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@
55
The Intl Component
66
==================
77

8-
A PHP replacement layer for the C `intl extension`_ that includes additional
9-
data from the ICU library.
8+
A PHP replacement layer for the C `intl extension`_ that also provides
9+
access to the localization data of the `ICU library`_.
1010

11-
.. note::
11+
.. versionadded:: 2.3
12+
13+
The Intl component was added in Symfony 2.3. In earlier versions of Symfony,
14+
you should use the Locale component instead.
15+
16+
.. caution::
1217

1318
The replacement layer is limited to the locale "en". If you want to use
1419
other locales, you should `install the intl extension`_ instead.
@@ -55,17 +60,98 @@ expose them manually by adding the following lines to your autoload code::
5560
$loader->registerPrefixFallback('/path/to/Icu/Resources/stubs');
5661
}
5762

58-
.. note::
63+
.. sidebar:: ICU and Deployment Problems
64+
65+
The intl extension internally uses the `ICU library`_ to obtain localization
66+
data such as number formats in different languages, country names and more.
67+
To make this data accessible to userland PHP libraries, Symfony2 ships a copy
68+
in the `ICU component`_.
69+
70+
Depending on the ICU version compiled with your intl extension, a matching
71+
version of that component needs to be installed. Sounds complicated, but usually
72+
Composer does this for you automatically:
73+
74+
* 1.0.*: when the intl extension is not available
75+
* 1.1.*: when intl is compiled with ICU 4.0 or higher
76+
* 1.2.*: when intl is compiled with ICU 4.4 or higher
77+
78+
These versions are important when you deploy your application to a **server with
79+
a lower ICU version** than your development machines, because deployment will
80+
fail if
81+
82+
* the development machines are compiled with ICU 4.4 or higher, but the
83+
server is compiled with a lower ICU version than 4.4;
84+
* the intl extension is available on the development machines but not on
85+
the server.
86+
87+
For example, consider that your development machines ship ICU 4.8 and the server
88+
ICU 4.2. When you run ``php composer.phar update`` on the development machine, version
89+
1.2.* of the ICU component will be installed. But after deploying the
90+
application, ``php composer.phar install`` will fail with the following error:
91+
92+
.. code-block:: bash
93+
94+
$ php composer.phar install
95+
Loading composer repositories with package information
96+
Installing dependencies from lock file
97+
Your requirements could not be resolved to an installable set of packages.
98+
99+
Problem 1
100+
- symfony/icu 1.2.x requires lib-icu >=4.4 -> the requested linked
101+
library icu has the wrong version installed or is missing from your
102+
system, make sure to have the extension providing it.
103+
104+
The error tells you that the requested version of the ICU component, version
105+
1.2, is not compatible with PHP's ICU version 4.2.
106+
107+
One solution to this problem is to run ``php composer.phar update`` instead of
108+
``php composer.phar install``. It is highly recommended **not** to do this. The
109+
``update`` command will install the latest versions of each Composer dependency
110+
to your production server and potentially break the application.
111+
112+
A better solution is to fix your composer.json to the version required by the
113+
production server. First, determine the ICU version on the server:
114+
115+
.. code-block:: bash
116+
117+
$ php -i | grep ICU
118+
ICU version => 4.2.1
119+
120+
Then fix the ICU component in your composer.json file to a matching version:
121+
122+
.. code-block:: json
123+
124+
"require: {
125+
"symfony/icu": "1.1.*"
126+
}
127+
128+
Set the version to
129+
130+
* "1.0.*" if the server does not have the intl extension installed;
131+
* "1.1.*" if the server is compiled with ICU 4.2 or lower.
132+
133+
Finally, run ``php composer.phar update symfony/icu`` on your development machine, test
134+
extensively and deploy again. The installation of the dependencies will now
135+
succeed.
59136

60-
The stub implementation only supports the locale ``en``.
61137

62138
Writing and Reading Resource Bundles
63139
------------------------------------
64140

65-
The :phpclass:`ResourceBundle` class is not and will not be supported. Instead,
66-
this component ships a set of readers and writers for reading and writing arrays
67-
(or array-like objects) from/to resource bundle files. The following classes
68-
are supported:
141+
The :phpclass:`ResourceBundle` class is currently by this component. Instead,
142+
it includes a set of readers and writers for reading and writing arrays (or
143+
array-like objects) from/to resource bundle files. The following classes are
144+
supported:
145+
146+
* `TextBundleWriter`_
147+
* `PhpBundleWriter`_
148+
* `BinaryBundleReader`_
149+
* `PhpBundleReader`_
150+
* `BufferedBundleReader`_
151+
* `StructuredBundleReader`_
152+
153+
Continue reading if you are interested in how to use these classes. Otherwise
154+
skip this section and jump to `Accessing ICU Data`_.
69155

70156
TextBundleWriter
71157
~~~~~~~~~~~~~~~~
@@ -192,15 +278,21 @@ locale will be merged. In order to suppress this behavior, the last parameter
192278

193279
echo $reader->readEntry('/path/to/bundle', 'en', array('Data', 'entry1'), false);
194280

195-
Provided Resource Bundles
196-
-------------------------
281+
Accessing ICU Data
282+
------------------
197283

198284
The ICU data is located in several "resource bundles". You can access a PHP
199285
wrapper of these bundles through the static
200-
:class:`Symfony\\Component\\Intl\\Intl` class.
286+
:class:`Symfony\\Component\\Intl\\Intl` class. At the moment, the following
287+
data is supported:
288+
289+
* `Language and Script Names`_
290+
* `Country Names`_
291+
* `Locales`_
292+
* `Currencies`_
201293

202-
Languages and Scripts
203-
~~~~~~~~~~~~~~~~~~~~~
294+
Language and Script Names
295+
~~~~~~~~~~~~~~~~~~~~~~~~~
204296

205297
The translations of language and script names can be found in the language
206298
bundle::
@@ -230,8 +322,8 @@ defaults to the current default locale::
230322
$languages = Intl::getLanguageBundle()->getLanguageNames('de');
231323
// => array('ab' => 'Abchasisch', ...)
232324

233-
Countries
234-
~~~~~~~~~
325+
Country Names
326+
~~~~~~~~~~~~~
235327

236328
The translations of country names can be found in the region bundle::
237329

@@ -300,13 +392,17 @@ be found in the currency bundle::
300392
All methods (except for
301393
:method:`Symfony\\Component\\Intl\\ResourceBundle\\CurrencyBundleInterface::getFractionDigits`
302394
and
303-
:method:`Symfony\\Component\\Intl\\ResourceBundle\\CurrencyBundleInterface::getRoundingIncrement()`)
395+
:method:`Symfony\\Component\\Intl\\ResourceBundle\\CurrencyBundleInterface::getRoundingIncrement`)
304396
accept the translation locale as last, optional parameter, which defaults to the
305397
current default locale::
306398

307399
$currencies = Intl::getCurrencyBundle()->getCurrencyNames('de');
308400
// => array('AFN' => 'Afghanische Afghani', ...)
309401

310-
.. _Packagist: https://packagist.org/packages/symfony/locale
402+
That's all you need to know for now. Have fun at coding!
403+
404+
.. _Packagist: https://packagist.org/packages/symfony/intl
405+
.. _ICU component: https://packagist.org/packages/symfony/icu
311406
.. _intl extension: http://www.php.net/manual/en/book.intl.php
312407
.. _install the intl extension: http://www.php.net/manual/en/intl.setup.php
408+
.. _ICU library: http://site.icu-project.org/

0 commit comments

Comments
 (0)