]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libstdc++-v3/contrib/libstdc++-v3-4.3.3/doc/xml/manual/messages.xml
update
[l4.git] / l4 / pkg / libstdc++-v3 / contrib / libstdc++-v3-4.3.3 / doc / xml / manual / messages.xml
1 <sect1 id="manual.localization.facet.messages" xreflabel="messages">
2 <?dbhtml filename="messages.html"?>
3  
4 <sect1info>
5   <keywordset>
6     <keyword>
7       ISO C++
8     </keyword>
9     <keyword>
10       messages
11     </keyword>
12   </keywordset>
13 </sect1info>
14
15 <title>messages</title>
16
17 <para>
18 The std::messages facet implements message retrieval functionality
19 equivalent to Java's java.text.MessageFormat .using either GNU gettext
20 or IEEE 1003.1-200 functions.
21 </para>
22
23 <sect2 id="facet.messages.req" xreflabel="facet.messages.req">
24 <title>Requirements</title>
25
26 <para>
27 The std::messages facet is probably the most vaguely defined facet in
28 the standard library. It's assumed that this facility was built into
29 the standard library in order to convert string literals from one
30 locale to the other. For instance, converting the "C" locale's
31 <code>const char* c = "please"</code> to a German-localized <code>"bitte"</code>
32 during program execution.
33 </para>
34
35 <blockquote>
36 <para>
37 22.2.7.1 - Template class messages [lib.locale.messages]
38 </para>
39 </blockquote>
40
41 <para>
42 This class has three public member functions, which directly
43 correspond to three protected virtual member functions. 
44 </para>
45
46 <para>
47 The public member functions are:
48 </para>
49
50 <para>
51 <code>catalog open(const string&amp;, const locale&amp;) const</code>
52 </para>
53
54 <para>
55 <code>string_type get(catalog, int, int, const string_type&amp;) const</code>
56 </para>
57
58 <para>
59 <code>void close(catalog) const</code>
60 </para>
61
62 <para>
63 While the virtual functions are:
64 </para>
65
66 <para>
67 <code>catalog do_open(const string&amp;, const locale&amp;) const</code>
68 </para>
69 <blockquote>
70 <para>
71 <emphasis>
72 -1- Returns: A value that may be passed to get() to retrieve a
73 message, from the message catalog identified by the string name
74 according to an implementation-defined mapping. The result can be used
75 until it is passed to close().  Returns a value less than 0 if no such
76 catalog can be opened.
77 </emphasis>
78 </para>
79 </blockquote>
80
81 <para>
82 <code>string_type do_get(catalog, int, int, const string_type&amp;) const</code>
83 </para>
84 <blockquote>
85 <para>
86 <emphasis>
87 -3- Requires: A catalog cat obtained from open() and not yet closed. 
88 -4- Returns: A message identified by arguments set, msgid, and dfault,
89 according to an implementation-defined mapping. If no such message can
90 be found, returns dfault.
91 </emphasis>
92 </para>
93 </blockquote>
94
95 <para>
96 <code>void do_close(catalog) const</code>
97 </para>
98 <blockquote>
99 <para>
100 <emphasis>
101 -5- Requires: A catalog cat obtained from open() and not yet closed. 
102 -6- Effects: Releases unspecified resources associated with cat. 
103 -7- Notes: The limit on such resources, if any, is implementation-defined. 
104 </emphasis>
105 </para>
106 </blockquote>
107
108
109 </sect2>
110
111 <sect2 id="facet.messages.design" xreflabel="facet.messages.design">
112 <title>Design</title>
113
114 <para>
115 A couple of notes on the standard. 
116 </para>
117
118 <para>
119 First, why is <code>messages_base::catalog</code> specified as a typedef
120 to int? This makes sense for implementations that use
121 <code>catopen</code>, but not for others. Fortunately, it's not heavily
122 used and so only a minor irritant. 
123 </para>
124
125 <para>
126 Second, by making the member functions <code>const</code>, it is
127 impossible to save state in them. Thus, storing away information used
128 in the 'open' member function for use in 'get' is impossible. This is
129 unfortunate.
130 </para>
131
132 <para>
133 The 'open' member function in particular seems to be oddly
134 designed. The signature seems quite peculiar. Why specify a <code>const
135 string&amp; </code> argument, for instance, instead of just <code>const
136 char*</code>? Or, why specify a <code>const locale&amp;</code> argument that is
137 to be used in the 'get' member function? How, exactly, is this locale
138 argument useful? What was the intent? It might make sense if a locale
139 argument was associated with a given default message string in the
140 'open' member function, for instance. Quite murky and unclear, on
141 reflection.
142 </para>
143
144 <para>
145 Lastly, it seems odd that messages, which explicitly require code
146 conversion, don't use the codecvt facet. Because the messages facet
147 has only one template parameter, it is assumed that ctype, and not
148 codecvt, is to be used to convert between character sets. 
149 </para>
150
151 <para>
152 It is implicitly assumed that the locale for the default message
153 string in 'get' is in the "C" locale. Thus, all source code is assumed
154 to be written in English, so translations are always from "en_US" to
155 other, explicitly named locales.
156 </para>
157
158 </sect2>
159
160 <sect2 id="facet.messages.impl" xreflabel="facet.messages.impl">
161 <title>Implementation</title>
162
163   <sect3 id="messages.impl.models" xreflabel="messages.impl.models">
164   <title>Models</title>
165   <para>
166     This is a relatively simple class, on the face of it. The standard
167     specifies very little in concrete terms, so generic
168     implementations that are conforming yet do very little are the
169     norm. Adding functionality that would be useful to programmers and
170     comparable to Java's java.text.MessageFormat takes a bit of work,
171     and is highly dependent on the capabilities of the underlying
172     operating system.
173   </para>
174
175   <para>
176     Three different mechanisms have been provided, selectable via
177     configure flags:
178   </para>
179
180 <itemizedlist>
181    <listitem>
182      <para>
183        generic
184      </para>
185      <para>
186        This model does very little, and is what is used by default.   
187      </para>
188    </listitem>
189
190    <listitem>
191      <para> 
192        gnu
193      </para>
194      <para>
195        The gnu model is complete and fully tested. It's based on the
196        GNU gettext package, which is part of glibc. It uses the
197        functions <code>textdomain, bindtextdomain, gettext</code> to
198        implement full functionality. Creating message catalogs is a
199        relatively straight-forward process and is lightly documented
200        below, and fully documented in gettext's distributed
201        documentation.
202      </para>
203    </listitem>
204
205    <listitem>
206      <para> 
207        ieee_1003.1-200x
208      </para>
209      <para>
210        This is a complete, though untested, implementation based on
211        the IEEE standard. The functions <code>catopen, catgets,
212        catclose</code> are used to retrieve locale-specific messages
213        given the appropriate message catalogs that have been
214        constructed for their use. Note, the script <code>
215        po2msg.sed</code> that is part of the gettext distribution can
216        convert gettext catalogs into catalogs that
217        <code>catopen</code> can use.
218    </para>
219    </listitem>
220 </itemizedlist>
221
222 <para>
223 A new, standards-conformant non-virtual member function signature was
224 added for 'open' so that a directory could be specified with a given
225 message catalog. This simplifies calling conventions for the gnu
226 model.
227 </para>
228
229   </sect3>
230
231   <sect3 id="messages.impl.gnu" xreflabel="messages.impl.gnu">
232   <title>The GNU Model</title>
233
234   <para>
235     The messages facet, because it is retrieving and converting
236     between characters sets, depends on the ctype and perhaps the
237     codecvt facet in a given locale. In addition, underlying "C"
238     library locale support is necessary for more than just the
239     <code>LC_MESSAGES</code> mask: <code>LC_CTYPE</code> is also
240     necessary. To avoid any unpleasantness, all bits of the "C" mask
241     (i.e. <code>LC_ALL</code>) are set before retrieving messages.
242   </para>
243
244   <para>
245     Making the message catalogs can be initially tricky, but become
246     quite simple with practice. For complete info, see the gettext
247     documentation. Here's an idea of what is required:
248   </para>
249
250 <itemizedlist>
251    <listitem>
252      <para>
253        Make a source file with the required string literals that need
254        to be translated. See <code>intl/string_literals.cc</code> for
255        an example.
256      </para>
257    </listitem>
258
259    <listitem>
260      <para> 
261        Make initial catalog (see "4 Making the PO Template File" from
262        the gettext docs).</para>
263    <para>
264    <code> xgettext --c++ --debug string_literals.cc -o libstdc++.pot </code>
265    </para>
266    </listitem>
267    
268    <listitem>
269      <para>Make language and country-specific locale catalogs.</para>
270    <para>
271    <code>cp libstdc++.pot fr_FR.po</code>
272    </para>
273    <para>
274    <code>cp libstdc++.pot de_DE.po</code>
275    </para>
276    </listitem>
277
278    <listitem>
279      <para>
280        Edit localized catalogs in emacs so that strings are
281        translated.
282      </para>
283    <para>
284    <code>emacs fr_FR.po</code>
285    </para>
286    </listitem>
287    
288    <listitem>
289      <para>Make the binary mo files.</para>
290    <para>
291    <code>msgfmt fr_FR.po -o fr_FR.mo</code>
292    </para>
293    <para>
294    <code>msgfmt de_DE.po -o de_DE.mo</code>
295    </para>
296    </listitem>
297
298    <listitem>
299      <para>Copy the binary files into the correct directory structure.</para>
300    <para>
301    <code>cp fr_FR.mo (dir)/fr_FR/LC_MESSAGES/libstdc++.mo</code>
302    </para>
303    <para>
304    <code>cp de_DE.mo (dir)/de_DE/LC_MESSAGES/libstdc++.mo</code>
305    </para>
306    </listitem>
307
308    <listitem>
309      <para>Use the new message catalogs.</para>
310    <para>
311    <code>locale loc_de("de_DE");</code>
312    </para>
313    <para>
314    <code>
315    use_facet&lt;messages&lt;char&gt; &gt;(loc_de).open("libstdc++", locale(), dir);
316    </code>
317    </para>
318    </listitem>
319 </itemizedlist>
320
321   </sect3>
322 </sect2>
323
324 <sect2 id="facet.messages.use" xreflabel="facet.messages.use">
325 <title>Use</title>
326  <para>
327    A simple example using the GNU model of message conversion.
328  </para>
329
330 <programlisting>
331 #include &lt;iostream&gt;
332 #include &lt;locale&gt;
333 using namespace std;
334
335 void test01()
336 {
337   typedef messages&lt;char&gt;::catalog catalog;
338   const char* dir =
339   "/mnt/egcs/build/i686-pc-linux-gnu/libstdc++/po/share/locale";  
340   const locale loc_de("de_DE");
341   const messages&lt;char&gt;&amp; mssg_de = use_facet&lt;messages&lt;char&gt; &gt;(loc_de); 
342
343   catalog cat_de = mssg_de.open("libstdc++", loc_de, dir);
344   string s01 = mssg_de.get(cat_de, 0, 0, "please");
345   string s02 = mssg_de.get(cat_de, 0, 0, "thank you");
346   cout &lt;&lt; "please in german:" &lt;&lt; s01 &lt;&lt; '\n';
347   cout &lt;&lt; "thank you in german:" &lt;&lt; s02 &lt;&lt; '\n';
348   mssg_de.close(cat_de);
349 }
350 </programlisting>
351
352 </sect2>
353
354 <sect2 id="facet.messages.future" xreflabel="facet.messages.future">
355 <title>Future</title>
356
357 <itemizedlist>
358 <listitem>
359   <para>
360     Things that are sketchy, or remain unimplemented:
361   </para>
362    <itemizedlist>
363       <listitem>
364         <para>
365           _M_convert_from_char, _M_convert_to_char are in flux,
366           depending on how the library ends up doing character set
367           conversions. It might not be possible to do a real character
368           set based conversion, due to the fact that the template
369           parameter for messages is not enough to instantiate the
370           codecvt facet (1 supplied, need at least 2 but would prefer
371           3).
372         </para>
373       </listitem>
374
375       <listitem>
376         <para> 
377           There are issues with gettext needing the global locale set
378           to extract a message. This dependence on the global locale
379           makes the current "gnu" model non MT-safe. Future versions
380           of glibc, i.e. glibc 2.3.x will fix this, and the C++ library
381           bits are already in place.
382         </para>
383       </listitem>
384    </itemizedlist>
385 </listitem>
386
387 <listitem>
388   <para>  
389     Development versions of the GNU "C" library, glibc 2.3 will allow
390     a more efficient, MT implementation of std::messages, and will
391     allow the removal of the _M_name_messages data member. If this is
392     done, it will change the library ABI. The C++ parts to support
393     glibc 2.3 have already been coded, but are not in use: once this
394     version of the "C" library is released, the marked parts of the
395     messages implementation can be switched over to the new "C"
396     library functionality.
397   </para>
398 </listitem>
399 <listitem>
400   <para>
401     At some point in the near future, std::numpunct will probably use
402     std::messages facilities to implement truename/falsename
403     correctly. This is currently not done, but entries in
404     libstdc++.pot have already been made for "true" and "false" string
405     literals, so all that remains is the std::numpunct coding and the
406     configure/make hassles to make the installed library search its
407     own catalog. Currently the libstdc++.mo catalog is only searched
408     for the testsuite cases involving messages members.
409   </para>
410 </listitem>
411
412 <listitem>
413   <para> The following member functions:</para>
414
415    <para>
416    <code>
417         catalog 
418         open(const basic_string&lt;char&gt;&amp; __s, const locale&amp; __loc) const
419    </code>
420    </para>
421
422    <para>
423    <code>
424    catalog 
425    open(const basic_string&lt;char&gt;&amp;, const locale&amp;, const char*) const;
426    </code>
427    </para>
428
429    <para>
430    Don't actually return a "value less than 0 if no such catalog
431    can be opened" as required by the standard in the "gnu"
432    model. As of this writing, it is unknown how to query to see
433    if a specified message catalog exists using the gettext
434    package.
435    </para>
436 </listitem>
437 </itemizedlist>
438
439 </sect2>
440
441 <bibliography id="facet.messages.biblio" xreflabel="facet.messages.biblio">
442 <title>Bibliography</title>
443
444   <biblioentry>
445     <title>
446       The GNU C Library
447     </title>
448
449     <author>
450       <surname>McGrath</surname>
451       <firstname>Roland</firstname>
452     </author>
453     <author>
454       <surname>Drepper</surname>
455       <firstname>Ulrich</firstname>
456     </author>
457
458     <copyright>
459       <year>2007</year>
460       <holder>FSF</holder>
461     </copyright>
462     <pagenums>Chapters 6 Character Set Handling, and 7 Locales and Internationalization
463     </pagenums>
464
465   </biblioentry> 
466
467   <biblioentry>
468     <title>
469       Correspondence
470     </title>
471
472     <author>
473       <surname>Drepper</surname>
474       <firstname>Ulrich</firstname>
475     </author>
476
477     <copyright>
478       <year>2002</year>
479       <holder></holder>
480     </copyright>
481   </biblioentry> 
482
483   <biblioentry>
484     <title>
485       ISO/IEC 14882:1998 Programming languages - C++
486     </title>
487
488     <copyright>
489       <year>1998</year>
490       <holder>ISO</holder>
491     </copyright>
492   </biblioentry> 
493
494   <biblioentry>
495     <title>
496       ISO/IEC 9899:1999 Programming languages - C
497     </title>
498
499     <copyright>
500       <year>1999</year>
501       <holder>ISO</holder>
502     </copyright>
503   </biblioentry> 
504
505   <biblioentry>
506     <title>
507       System Interface Definitions, Issue 6 (IEEE Std. 1003.1-200x)
508     </title>
509
510     <copyright>
511       <year>1999</year>
512       <holder>
513       The Open Group/The Institute of Electrical and Electronics Engineers, Inc.</holder>
514     </copyright>
515
516     <biblioid>
517       <ulink url="http://www.opennc.org/austin/docreg.html">
518       </ulink>
519     </biblioid>
520
521   </biblioentry> 
522
523   <biblioentry>
524     <title>
525       The C++ Programming Language, Special Edition
526     </title>
527     
528     <author>
529       <surname>Stroustrup</surname>
530       <firstname>Bjarne</firstname>
531     </author>
532
533     <copyright>
534       <year>2000</year>
535       <holder>Addison Wesley, Inc.</holder>
536     </copyright>
537     <pagenums>Appendix D</pagenums>
538
539     <publisher>
540       <publishername>
541         Addison Wesley
542       </publishername>
543     </publisher>
544
545   </biblioentry> 
546
547
548   <biblioentry>
549     <title>
550       Standard C++ IOStreams and Locales
551     </title>
552     <subtitle>
553       Advanced Programmer's Guide and Reference
554     </subtitle>
555     
556     <author>
557       <surname>Langer</surname>
558       <firstname>Angelika</firstname>
559     </author>
560
561     <author>
562       <surname>Kreft</surname>
563       <firstname>Klaus</firstname>
564     </author>
565
566     <copyright>
567       <year>2000</year>
568       <holder>Addison Wesley Longman, Inc.</holder>
569     </copyright>
570
571     <publisher>
572       <publishername>
573         Addison Wesley Longman
574       </publishername>
575     </publisher>
576
577   </biblioentry> 
578
579   <biblioentry>
580     <title>
581       Java 2 Platform, Standard Edition, v 1.3.1 API Specification
582     </title>
583     <pagenums>java.util.Properties, java.text.MessageFormat,
584 java.util.Locale, java.util.ResourceBundle</pagenums>
585     <biblioid>
586       <ulink url="http://java.sun.com/j2se/1.3/docs/api">
587       </ulink>
588     </biblioid>
589   </biblioentry> 
590
591   <biblioentry>
592     <title>
593        GNU gettext tools, version 0.10.38, Native Language Support
594 Library and Tools.
595     </title>
596     <biblioid>
597       <ulink url="http://sources.redhat.com/gettext">
598       </ulink>
599     </biblioid>
600   </biblioentry> 
601
602 </bibliography>
603
604 </sect1>