reference/intl/messageformatter/format-message.xml
dacb2d9a9d924fd355af1abcff854571a5db4443
...
...
@@ -1,6 +1,6 @@
1
1
<?xml version="1.0" encoding="utf-8"?>
2
2
<!-- $Revision$ -->
3
-
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xml:id="messageformatter.formatmessage">
3
+
<refentry xml:id="messageformatter.formatmessage" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
4
4
<refnamediv>
5
5
<refname>MessageFormatter::formatMessage</refname>
6
6
<refname>msgfmt_format_message</refname>
...
...
@@ -12,30 +12,26 @@
12
12
<para>
13
13
&style.oop;
14
14
</para>
15
-
<methodsynopsis>
16
-
<modifier>public</modifier>
17
-
<modifier>static</modifier>
18
-
<type>string</type>
19
-
<methodname>MessageFormatter::formatMessage</methodname>
15
+
<methodsynopsis role="MessageFormatter">
16
+
<modifier>public</modifier> <modifier>static</modifier> <type class="union"><type>string</type><type>false</type></type><methodname>MessageFormatter::formatMessage</methodname>
20
17
<methodparam><type>string</type><parameter>locale</parameter></methodparam>
21
18
<methodparam><type>string</type><parameter>pattern</parameter></methodparam>
22
-
<methodparam><type>array</type><parameter>args</parameter></methodparam>
19
+
<methodparam><type>array</type><parameter>values</parameter></methodparam>
23
20
</methodsynopsis>
24
21
<para>
25
22
&style.procedural;
26
23
</para>
27
24
<methodsynopsis>
28
-
<type>string</type>
29
-
<methodname>msgfmt_format_message</methodname>
25
+
<type class="union"><type>string</type><type>false</type></type><methodname>msgfmt_format_message</methodname>
30
26
<methodparam><type>string</type><parameter>locale</parameter></methodparam>
31
27
<methodparam><type>string</type><parameter>pattern</parameter></methodparam>
32
-
<methodparam><type>array</type><parameter>args</parameter></methodparam>
28
+
<methodparam><type>array</type><parameter>values</parameter></methodparam>
33
29
</methodsynopsis>
34
30
<para>
35
31
Quick formatting function that formats the string without having to
36
32
explicitly create the formatter object. Use this function when the format
37
-
operation is done only once and does not need and parameters or state to be
38
-
kept.
33
+
operation is done only once and does not need any parameters or state to be
34
+
kept or when wanting to customize the output by providing additional context to ICU directly.
39
35
</para>
40
36
</refsect1>
41
37

...
...
@@ -56,15 +52,13 @@
56
52
<listitem>
57
53
<para>
58
54
The pattern <type>string</type> to insert things into.
59
-
The pattern uses an 'apostrophe-friendly' syntax; it is run through
60
-
<link
61
-
xlink:href="&url.icu.autoQuoteApostrophe;">umsg_autoQuoteApostrophe</link>
62
-
before being interpreted.
55
+
The pattern uses an 'apostrophe-friendly' syntax;
56
+
see <link xlink:href="&url.icu.quoting;">Quoting/Escaping</link> for details.
63
57
</para>
64
58
</listitem>
65
59
</varlistentry>
66
60
<varlistentry>
67
-
<term><parameter>args</parameter></term>
61
+
<term><parameter>values</parameter></term>
68
62
<listitem>
69
63
<para>
70
64
The <type>array</type> of values to insert into the format <type>string</type>
...
...
@@ -92,7 +86,15 @@
92
86
<?php
93
87
echo msgfmt_format_message("en_US", "{0,number,integer} monkeys on {1,number,integer} trees make {2,number} monkeys per tree\n", array(4560, 123, 4560/123));
94
88
echo msgfmt_format_message("de", "{0,number,integer} Affen auf {1,number,integer} Bäumen sind {2,number} Affen pro Baum\n", array(4560, 123, 4560/123));
95
-
?>
89
+
echo msgfmt_format_message("en", 'You finished {place, selectordinal, one {#st} two {#nd} few {#rd} other {#th}}!', ['place' => 3]), "\n";
90
+
echo msgfmt_format_message("en",
91
+
"There {apple, plural,
92
+
=0 {are no apples}
93
+
=1 {is one apple...}
94
+
other {are # apples!}
95
+
}",
96
+
['apple' => 0]
97
+
), "\n";
96
98
]]>
97
99
</programlisting>
98
100
</example>
...
...
@@ -103,7 +105,15 @@ echo msgfmt_format_message("de", "{0,number,integer} Affen auf {1,number,integer
103
105
<?php
104
106
echo MessageFormatter::formatMessage("en_US", "{0,number,integer} monkeys on {1,number,integer} trees make {2,number} monkeys per tree\n", array(4560, 123, 4560/123));
105
107
echo MessageFormatter::formatMessage("de", "{0,number,integer} Affen auf {1,number,integer} Bäumen sind {2,number} Affen pro Baum\n", array(4560, 123, 4560/123));
106
-
?>
108
+
echo MessageFormatter::formatMessage("en", 'You finished {place, selectordinal, one {#st} two {#nd} few {#rd} other {#th}}!', ['place' => 3]), "\n";
109
+
echo MessageFormatter::formatMessage("en",
110
+
"There {apple, plural,
111
+
=0 {are no apples}
112
+
=1 {is one apple...}
113
+
other {are # apples!}
114
+
}",
115
+
['apple' => 0]
116
+
), "\n";
107
117
]]>
108
118
</programlisting>
109
119
</example>
...
...
@@ -112,8 +122,28 @@ echo MessageFormatter::formatMessage("de", "{0,number,integer} Affen auf {1,numb
112
122
<![CDATA[
113
123
4,560 monkeys on 123 trees make 37.073 monkeys per tree
114
124
4.560 Affen auf 123 Bäumen sind 37,073 Affen pro Baum
125
+
You finished 3rd!
126
+
There are no apples
115
127
]]>
116
128
</screen>
129
+
<example>
130
+
<title>Instructing ICU to format currency with common and with narrow currency symbol</title>
131
+
<simpara>Requires ICU ≥ 67.</simpara>
132
+
<programlisting role="php">
133
+
<![CDATA[
134
+
<?php
135
+
echo msgfmt_format_message("cs_CZ", "{0, number, :: currency/CAD}", array(123.45));
136
+
echo msgfmt_format_message("cs_CZ", "{0, number, :: currency/CAD unit-width-narrow}", array(123.45));
137
+
]]>
138
+
</programlisting>
139
+
&example.outputs;
140
+
<screen>
141
+
<![CDATA[
142
+
123,45 CA$
143
+
123,45 $
144
+
]]>
145
+
</screen>
146
+
</example>
117
147
</refsect1>
118
148

119
149
<refsect1 role="seealso">
120
150