@@ -81,8 +81,8 @@ echo $formatphp->formatMessage([
8181
8282### Formatting Numbers and Currency
8383
84- You may use the methods ` formatNumber() ` and ` formatCurrency() ` for format
85- numbers and currency, according to the locale.
84+ You may use the methods ` formatNumber() ` and ` formatCurrency() ` to format
85+ numbers and currency according to the locale.
8686
8787``` php
8888use FormatPHP\Config;
@@ -366,6 +366,65 @@ Additional options include:
366366 You may use the zone names of the [ IANA time zone database] ( https://www.iana.org/time-zones ) ,
367367 such as "Asia/Shanghai", "Asia/Kolkata", "America/New_York".
368368
369+ ### Formatting Display Names of Languages, Regions, Currency, and More
370+
371+ You may use the method ` formatDisplayName() ` to format the display names of
372+ languages, regions, currency, and more. This returns a locale-appropriate,
373+ translated string for the type requested.
374+
375+ ``` php
376+ use FormatPHP\Config;
377+ use FormatPHP\FormatPHP;
378+ use FormatPHP\Intl;
379+
380+ $config = new Config(new Intl\Locale('en-US'));
381+ $formatphp = new FormatPHP($config);
382+
383+ echo $formatphp->formatDisplayName('zh-Hans-SG', new Intl\DisplayNamesOptions([
384+ 'type' => 'language',
385+ ])); // e.g., "Chinese (Simplified, Singapore)"
386+
387+ echo $formatphp->formatDisplayName('Deva', new Intl\DisplayNamesOptions([
388+ 'type' => 'script',
389+ ])); // e.g., "Devanagari"
390+
391+ echo $formatphp->formatDisplayName('CNY', new Intl\DisplayNamesOptions([
392+ 'type' => 'currency',
393+ ])); // e.g., "Chinese yuan"
394+
395+ echo $formatphp->formatDisplayName('CNY', new Intl\DisplayNamesOptions([
396+ 'type' => 'currency',
397+ 'style' => 'narrow',
398+ ])); // e.g., "¥"
399+
400+ echo $formatphp->formatDisplayName('UN', new Intl\DisplayNamesOptions([
401+ 'type' => 'region',
402+ ])); // e.g., "United Nations"
403+ ```
404+
405+ #### Using Intl\DisplayNamesOptions with formatDisplayName()
406+
407+ When formatting display names, you must provide a ` DisplayNamesOptions ` instance
408+ with at least a ` type ` defined.
409+
410+ * ` type ` : The type of data for which we wish to format a display name. This
411+ currently supports ` currency ` , ` language ` , ` region ` , and ` script ` . While
412+ [ ECMA-402] ( https://tc39.es/ecma402/#sec-intl-displaynames-constructor ) defines
413+ ` calendar ` and ` dateTimeField ` as additional types, these types are not
414+ implemented in Node.js or in any browsers. In fact, if set, the
415+ implementations throw exceptions, so this FormatPHP follows the same
416+ pattern.
417+ * ` fallback ` : The fallback strategy to use. If we are unable to format a display
418+ name, we will return the same code provided if ` fallback ` is set to ` code. ` If
419+ ` fallback ` is ` none ` , then we return ` null ` . The default ` fallback ` is ` code ` .
420+ * ` style ` : The formatting style to use: ` long ` , ` short ` , or ` narrow ` . This
421+ currently only affects the display name when ` type ` is ` currency ` , and the
422+ default is ` long ` .
423+ * ` languageDisplay ` : This is a suggestion for displaying the language according
424+ to the locale's dialect or standard representation. In JavaScript, this
425+ defaults to ` dialect ` . For now, PHP supports only the ` standard `
426+ representation, so ` dialect ` has no effect.
427+
369428### Rich Text Formatting (Use of Tags in Messages)
370429
371430While the ICU message syntax does not prohibit the use of HTML tags in formatted
0 commit comments