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

Skip to content

Commit 21323ba

Browse files
committed
[Intl] Updated the README file
1 parent 209a9cb commit 21323ba

File tree

5 files changed

+282
-18
lines changed

5 files changed

+282
-18
lines changed

src/Symfony/Component/Intl/Intl.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use Symfony\Component\Icu\IcuRegionBundle;
1919
use Symfony\Component\Intl\Exception\InvalidArgumentException;
2020
use Symfony\Component\Intl\ResourceBundle\Reader\BinaryBundleReader;
21-
use Symfony\Component\Intl\ResourceBundle\Reader\BufferedReader;
21+
use Symfony\Component\Intl\ResourceBundle\Reader\BufferedBundleReader;
2222
use Symfony\Component\Intl\ResourceBundle\Reader\PhpBundleReader;
2323
use Symfony\Component\Intl\ResourceBundle\Reader\StructuredBundleReader;
2424
use Symfony\Component\Intl\ResourceBundle\Stub\StubCurrencyBundle;
@@ -301,7 +301,7 @@ public static function getIcuStubVersion()
301301
private static function getPhpReader()
302302
{
303303
if (null === self::$phpReader) {
304-
self::$phpReader = new StructuredBundleReader(new BufferedReader(
304+
self::$phpReader = new StructuredBundleReader(new BufferedBundleReader(
305305
new PhpBundleReader(),
306306
self::BUFFER_SIZE
307307
));
@@ -318,7 +318,7 @@ private static function getPhpReader()
318318
private static function getBinaryReader()
319319
{
320320
if (null === self::$binaryReader) {
321-
self::$binaryReader = new StructuredBundleReader(new BufferedReader(
321+
self::$binaryReader = new StructuredBundleReader(new BufferedBundleReader(
322322
new BinaryBundleReader(),
323323
self::BUFFER_SIZE
324324
));

src/Symfony/Component/Intl/README.md

Lines changed: 267 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,25 +103,251 @@ The only supported attributes are `\NumberFormatter::FRACTION_DIGITS`,
103103
The only supported rounding modes are `\NumberFormatter::ROUND_HALFEVEN`,
104104
`\NumberFormatter::ROUND_HALFDOWN` and `\NumberFormatter::ROUND_HALFUP`.
105105

106+
### IntlDateFormatter
107+
108+
Dates can be formatted with the [`\IntlDateFormatter`] [4] class. The following
109+
methods are supported. All other methods are not supported and will throw an
110+
exception when used.
111+
112+
##### __construct($locale, $datetype, $timetype, $timezone = null, $calendar = \IntlDateFormatter::GREGORIAN, $pattern = null)
113+
114+
The only supported locale is "en". The parameter `$calendar` can only be
115+
`\IntlDateFormatter::GREGORIAN`.
116+
117+
##### ::create($locale, $datetype, $timetype, $timezone = null, $calendar = self::GREGORIAN, $pattern = null)
118+
119+
See `__construct()`.
120+
121+
##### format($timestamp)
122+
123+
Fully supported.
124+
125+
##### getCalendar()
126+
127+
Fully supported.
128+
129+
##### getDateType()
130+
131+
Fully supported.
132+
133+
##### getErrorCode()
134+
135+
Fully supported.
136+
137+
##### getErrorMessage()
138+
139+
Fully supported.
140+
141+
##### getLocale($type = StubLocale::ACTUAL_LOCALE)
142+
143+
The parameter `$type` is ignored.
144+
145+
##### getPattern()
146+
147+
Fully supported.
148+
149+
##### getTimeType()
150+
151+
Fully supported.
152+
153+
##### getTimeZoneId()
154+
155+
Fully supported.
156+
157+
##### isLenient()
158+
159+
Always returns `false`.
160+
161+
##### parse($value, &$position = null)
162+
163+
The parameter `$position` must always be `null`.
164+
165+
##### setLenient($lenient)
166+
167+
Only accepts `false`.
168+
169+
##### setPattern($pattern)
170+
171+
Fully supported.
172+
173+
##### setTimeZoneId($timeZoneId)
174+
175+
Fully supported.
176+
177+
##### setTimeZone($timeZone)
178+
179+
Fully supported.
180+
181+
### Collator
182+
183+
Localized strings can be sorted with the [`\Collator`] [5] class. The following
184+
methods are supported. All other methods are not supported and will throw an
185+
exception when used.
186+
187+
##### __construct($locale)
188+
189+
The only supported locale is "en".
190+
191+
##### create($locale)
192+
193+
See `__construct()`.
194+
195+
##### asort(&$array, $sortFlag = self::SORT_REGULAR)
196+
197+
Fully supported.
198+
199+
##### getErrorCode()
200+
201+
Fully supported.
202+
203+
##### getErrorMessage()
204+
205+
Fully supported.
206+
207+
##### getLocale($type = StubLocale::ACTUAL_LOCALE)
208+
209+
The parameter `$type` is ignored.
210+
211+
### ResourceBundle
212+
213+
The `\ResourceBundle` class is not and will not be supported. Instead, this
214+
component ships a set of readers and writers for reading and writing arrays
215+
(or array-like objects) from/to resource bundle files. The following classes
216+
are supported:
217+
218+
##### TextBundleWriter
219+
220+
Writes a resource bundle to a .txt file. These text files can be converted to
221+
binary .res files using the `BundleCompiler` class.
222+
223+
use Symfony\Component\Intl\ResourceBundle\Writer\TextBundleWriter;
224+
use Symfony\Component\Intl\ResourceBundle\Compiler\BundleCompiler;
225+
226+
$writer = new TextBundleWriter();
227+
$writer->write('/path/to/bundle', 'en', array(
228+
'Data' => array(
229+
'entry1',
230+
'entry2',
231+
...
232+
),
233+
));
234+
235+
$compiler = new BundleCompiler();
236+
$compiler->compile('/path/to/bundle', '/path/to/binary/bundle');
237+
238+
The command "genrb" must be available for the `BundleCompiler` to work. If the
239+
command is located in a non-standard location, you can pass its path to the
240+
constructor of the `BundleCompiler`.
241+
242+
##### PhpBundleWriter
243+
244+
Writes a resource bundle to a .php file.
245+
246+
use Symfony\Component\Intl\ResourceBundle\Writer\PhpBundleWriter;
247+
248+
$writer = new PhpBundleWriter();
249+
$writer->write('/path/to/bundle', 'en', array(
250+
'Data' => array(
251+
'entry1',
252+
'entry2',
253+
...
254+
),
255+
));
256+
257+
##### BinaryBundleReader
258+
259+
Reads binary resource bundle files and returns an array or an array-like object.
260+
This class currently only works with the intl extension installed.
261+
262+
use Symfony\Component\Intl\ResourceBundle\Reader\BinaryBundleReader;
263+
264+
$reader = new BinaryBundleReader();
265+
$data = $reader->read('/path/to/bundle', 'en');
266+
267+
echo $data['Data']['entry1'];
268+
269+
##### PhpBundleReader
270+
271+
Reads resource bundles from .php files and returns an array or an array-like
272+
object.
273+
274+
use Symfony\Component\Intl\ResourceBundle\Reader\PhpBundleReader;
275+
276+
$reader = new PhpBundleReader();
277+
$data = $reader->read('/path/to/bundle', 'en');
278+
279+
echo $data['Data']['entry1'];
280+
281+
##### BufferedBundleReader
282+
283+
Wraps another reader, but keeps the last N reads in a buffer, where N is a
284+
buffer size passed to the constructor.
285+
286+
use Symfony\Component\Intl\ResourceBundle\Reader\BinaryBundleReader;
287+
use Symfony\Component\Intl\ResourceBundle\Reader\BufferedBundleReader;
288+
289+
$reader = new BufferedBundleReader(new BinaryBundleReader(), 10);
290+
291+
// actually reads the file
292+
$data = $reader->read('/path/to/bundle', 'en');
293+
294+
// returns data from the buffer
295+
$data = $reader->read('/path/to/bundle', 'en');
296+
297+
// actually reads the file
298+
$data = $reader->read('/path/to/bundle', 'fr');
299+
300+
##### StructuredBundleReader
301+
302+
Wraps another reader and offers a `readEntry()` method for reading an entry
303+
of the resource bundle without having to worry whether array keys are set or
304+
not. If a path cannot be resolved, `null` is returned.
305+
306+
use Symfony\Component\Intl\ResourceBundle\Reader\BinaryBundleReader;
307+
use Symfony\Component\Intl\ResourceBundle\Reader\StructuredBundleReader;
308+
309+
$reader = new StructuredBundleReader(new BinaryBundleReader());
310+
311+
$data = $reader->read('/path/to/bundle', 'en');
312+
313+
// Produces an error if the key "Data" does not exist
314+
echo $data['Data']['entry1'];
315+
316+
// Returns null if the key "Data" does not exist
317+
echo $reader->readEntry('/path/to/bundle', 'en', array('Data', 'entry1'));
318+
319+
Additionally, the `readEntry()` method resolves fallback locales. For example,
320+
the fallback locale of "en_GB" is "en". For single-valued entries (strings,
321+
numbers etc.), the entry will be read from the fallback locale if it cannot be
322+
found in the more specific locale. For multi-valued entries (arrays), the
323+
values of the more specific and the fallback locale will be merged. In order
324+
to suppress this behavior, the last parameter `$fallback` can be set to `false`.
325+
326+
echo $reader->readEntry('/path/to/bundle', 'en', array('Data', 'entry1'), false);
327+
106328
Included Resource Bundles
107329
-------------------------
108330

109331
The ICU data is located in several "resource bundles". You can access a PHP
110-
wrapper of these bundles through the static Intl class.
332+
wrapper of these bundles through the static `Intl` class.
111333

112334
Languages and Scripts
113335
~~~~~~~~~~~~~~~~~~~~~
114336
115337
The translations of language and script names can be found in the language
116338
bundle.
117339
340+
use Symfony\Component\Intl\Intl;
341+
342+
\Locale::setDefault('en');
343+
118344
$languages = Intl::getLanguageBundle()->getLanguageNames();
119345
// => array('ab' => 'Abkhazian', ...)
120346
121347
$language = Intl::getLanguageBundle()->getLanguageName('de');
122348
// => 'German'
123349
124-
$language = Intl::getLanguageBundle()->getLanguageName('de', 'AT);
350+
$language = Intl::getLanguageBundle()->getLanguageName('de', 'AT');
125351
// => 'Austrian German'
126352
127353
$scripts = Intl::getLanguageBundle()->getScriptNames();
@@ -130,41 +356,71 @@ bundle.
130356
$script = Intl::getLanguageBundle()->getScriptName('Hans');
131357
// => 'Simplified'
132358
359+
All methods accept the translation locale as last, optional parameter, which
360+
defaults to the current default locale.
361+
362+
$languages = Intl::getLanguageBundle()->getLanguageNames('de');
363+
// => array('ab' => 'Abchasisch', ...)
364+
133365
Countries
134366
~~~~~~~~~
135367
136368
The translations of country names can be found in the region bundle.
137369
370+
use Symfony\Component\Intl\Intl;
371+
372+
\Locale::setDefault('en');
373+
138374
$countries = Intl::getRegionBundle()->getCountryNames();
139375
// => array('AF' => 'Afghanistan', ...)
140376
141377
$country = Intl::getRegionBundle()->getCountryName('GB');
142378
// => 'United Kingdom'
143379
380+
All methods accept the translation locale as last, optional parameter, which
381+
defaults to the current default locale.
382+
383+
$countries = Intl::getRegionBundle()->getCountryNames('de');
384+
// => array('AF' => 'Afghanistan', ...)
385+
144386
Locales
145387
~~~~~~~
146388
147389
The translations of locale names can be found in the locale bundle.
148390
391+
use Symfony\Component\Intl\Intl;
392+
393+
\Locale::setDefault('en');
394+
149395
$locales = Intl::getLocaleBundle()->getLocaleNames();
150396
// => array('af' => 'Afrikaans', ...)
151397
152398
$locale = Intl::getLocaleBundle()->getLocaleName('zh_Hans_MO');
153399
// => 'Chinese (Simplified, Macau SAR China)'
154400
401+
All methods accept the translation locale as last, optional parameter, which
402+
defaults to the current default locale.
403+
404+
$locales = Intl::getLocaleBundle()->getLocaleNames('de');
405+
// => array('af' => 'Afrikaans', ...)
406+
155407
Currencies
156408
~~~~~~~~~~
157409
158410
The translations of currency names and other currency-related information can
159411
be found in the currency bundle.
160412
413+
use Symfony\Component\Intl\Intl;
414+
415+
\Locale::setDefault('en');
416+
161417
$currencies = Intl::getCurrencyBundle()->getCurrencyNames();
162418
// => array('AFN' => 'Afghan Afghani', ...)
163419
164-
$currency = Intl::getCurrencyBundle()->getCurrencyNames('INR');
420+
$currency = Intl::getCurrencyBundle()->getCurrencyName('INR');
165421
// => 'Indian Rupee'
166422
167-
$symbol = Intl::getCurrencyBundle()->getCurrencyNames('INR');
423+
$symbol = Intl::getCurrencyBundle()->getCurrencySymbol('INR');
168424
// => '₹'
169425
170426
$fractionDigits = Intl::getCurrencyBundle()->getFractionDigits('INR');
@@ -173,6 +429,13 @@ be found in the currency bundle.
173429
$roundingIncrement = Intl::getCurrencyBundle()->getRoundingIncrement('INR');
174430
// => 0
175431
432+
All methods (except for `getFractionDigits()` and `getRoundingIncrement()`)
433+
accept the translation locale as last, optional parameter, which defaults to the
434+
current default locale.
435+
436+
$currencies = Intl::getCurrencyBundle()->getCurrencyNames('de');
437+
// => array('AFN' => 'Afghanische Afghani', ...)
438+
176439
Resources
177440
---------
178441

src/Symfony/Component/Intl/ResourceBundle/Reader/BufferedReader.php renamed to src/Symfony/Component/Intl/ResourceBundle/Reader/BufferedBundleReader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
/**
1717
* @author Bernhard Schussek <[email protected]>
1818
*/
19-
class BufferedReader implements BundleReaderInterface
19+
class BufferedBundleReader implements BundleReaderInterface
2020
{
2121
/**
2222
* @var BundleReaderInterface

src/Symfony/Component/Intl/ResourceBundle/Reader/StructuredBundleReader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ public function getLocales($path)
5656
/**
5757
* {@inheritdoc}
5858
*/
59-
public function readEntry($path, $locale, array $indices, $mergeFallback = true)
59+
public function readEntry($path, $locale, array $indices, $fallback = true)
6060
{
6161
$data = $this->reader->read($path, $locale);
6262

6363
$entry = RecursiveArrayAccess::get($data, $indices);
6464
$multivalued = is_array($entry) || $entry instanceof \Traversable;
6565

66-
if (!($mergeFallback && (null === $entry || $multivalued))) {
66+
if (!($fallback && (null === $entry || $multivalued))) {
6767
return $entry;
6868
}
6969

0 commit comments

Comments
 (0)