@@ -103,25 +103,251 @@ The only supported attributes are `\NumberFormatter::FRACTION_DIGITS`,
103
103
The only supported rounding modes are ` \NumberFormatter::ROUND_HALFEVEN ` ,
104
104
` \NumberFormatter::ROUND_HALFDOWN ` and ` \NumberFormatter::ROUND_HALFUP ` .
105
105
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
+
106
328
Included Resource Bundles
107
329
-------------------------
108
330
109
331
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.
111
333
112
334
Languages and Scripts
113
335
~~~~~~~~~~~~~~~~~~~~~
114
336
115
337
The translations of language and script names can be found in the language
116
338
bundle.
117
339
340
+ use Symfony\Component\Intl\Intl;
341
+
342
+ \Locale::setDefault('en');
343
+
118
344
$languages = Intl::getLanguageBundle()->getLanguageNames();
119
345
// => array('ab' => 'Abkhazian', ...)
120
346
121
347
$language = Intl::getLanguageBundle()->getLanguageName('de');
122
348
// => 'German'
123
349
124
- $language = Intl::getLanguageBundle()->getLanguageName('de', 'AT);
350
+ $language = Intl::getLanguageBundle()->getLanguageName('de', 'AT' );
125
351
// => 'Austrian German'
126
352
127
353
$scripts = Intl::getLanguageBundle()->getScriptNames();
@@ -130,41 +356,71 @@ bundle.
130
356
$script = Intl::getLanguageBundle()->getScriptName('Hans');
131
357
// => 'Simplified'
132
358
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
+
133
365
Countries
134
366
~~~~~~~~~
135
367
136
368
The translations of country names can be found in the region bundle.
137
369
370
+ use Symfony\Component\Intl\Intl;
371
+
372
+ \Locale::setDefault('en');
373
+
138
374
$countries = Intl::getRegionBundle()->getCountryNames();
139
375
// => array('AF' => 'Afghanistan', ...)
140
376
141
377
$country = Intl::getRegionBundle()->getCountryName('GB');
142
378
// => 'United Kingdom'
143
379
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
+
144
386
Locales
145
387
~~~~~~~
146
388
147
389
The translations of locale names can be found in the locale bundle.
148
390
391
+ use Symfony\Component\Intl\Intl;
392
+
393
+ \Locale::setDefault('en');
394
+
149
395
$locales = Intl::getLocaleBundle()->getLocaleNames();
150
396
// => array('af' => 'Afrikaans', ...)
151
397
152
398
$locale = Intl::getLocaleBundle()->getLocaleName('zh_Hans_MO');
153
399
// => 'Chinese (Simplified, Macau SAR China)'
154
400
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
+
155
407
Currencies
156
408
~~~~~~~~~~
157
409
158
410
The translations of currency names and other currency-related information can
159
411
be found in the currency bundle.
160
412
413
+ use Symfony\Component\Intl\Intl;
414
+
415
+ \Locale::setDefault('en');
416
+
161
417
$currencies = Intl::getCurrencyBundle()->getCurrencyNames();
162
418
// => array('AFN' => 'Afghan Afghani', ...)
163
419
164
- $currency = Intl::getCurrencyBundle()->getCurrencyNames ('INR');
420
+ $currency = Intl::getCurrencyBundle()->getCurrencyName ('INR');
165
421
// => 'Indian Rupee'
166
422
167
- $symbol = Intl::getCurrencyBundle()->getCurrencyNames ('INR');
423
+ $symbol = Intl::getCurrencyBundle()->getCurrencySymbol ('INR');
168
424
// => '₹'
169
425
170
426
$fractionDigits = Intl::getCurrencyBundle()->getFractionDigits('INR');
@@ -173,6 +429,13 @@ be found in the currency bundle.
173
429
$roundingIncrement = Intl::getCurrencyBundle()->getRoundingIncrement('INR');
174
430
// => 0
175
431
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
+
176
439
Resources
177
440
---------
178
441
0 commit comments