OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libstdc++-v3/] [doc/] [xml/] [manual/] [messages.xml] - Blame information for rev 866

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.