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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gcc-4.5.1/] [libstdc++-v3/] [doc/] [xml/] [manual/] [messages.xml] - Blame information for rev 847

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

Line No. Rev Author Line
1 424 jeremybenn
2
3
 
4
5
  
6
    
7
      ISO C++
8
    
9
    
10
      messages
11
    
12
  
13
14
 
15
messages
16
 
17
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
22
 
23
24
Requirements
25
 
26
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
const char* c = "please" to a German-localized "bitte"
32
during program execution.
33
34
 
35
36
37
22.2.7.1 - Template class messages [lib.locale.messages]
38
39
40
 
41
42
This class has three public member functions, which directly
43
correspond to three protected virtual member functions.
44
45
 
46
47
The public member functions are:
48
49
 
50
51
catalog open(const string&, const locale&) const
52
53
 
54
55
string_type get(catalog, int, int, const string_type&) const
56
57
 
58
59
void close(catalog) const
60
61
 
62
63
While the virtual functions are:
64
65
 
66
67
catalog do_open(const string&, const locale&) const
68
69
70
71
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
78
79
80
 
81
82
string_type do_get(catalog, int, int, const string_type&) const
83
84
85
86
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
92
93
94
 
95
96
void do_close(catalog) const
97
98
99
100
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
105
106
107
 
108
 
109
110
 
111
112
Design
113
 
114
115
A couple of notes on the standard.
116
117
 
118
119
First, why is messages_base::catalog specified as a typedef
120
to int? This makes sense for implementations that use
121
catopen, but not for others. Fortunately, it's not heavily
122
used and so only a minor irritant.
123
124
 
125
126
Second, by making the member functions const, 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
131
 
132
133
The 'open' member function in particular seems to be oddly
134
designed. The signature seems quite peculiar. Why specify a const
135
string&  argument, for instance, instead of just const
136
char*? Or, why specify a const locale& 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
143
 
144
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
150
 
151
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
157
 
158
159
 
160
161
Implementation
162
 
163
  
164
  Models
165
  
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
  
174
 
175
  
176
    Three different mechanisms have been provided, selectable via
177
    configure flags:
178
  
179
 
180
181
   
182
     
183
       generic
184
     
185
     
186
       This model does very little, and is what is used by default.
187
     
188
   
189
 
190
   
191
     
192
       gnu
193
     
194
     
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 textdomain, bindtextdomain, gettext 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
     
203
   
204
 
205
   
206
     
207
       ieee_1003.1-200x
208
     
209
     
210
       This is a complete, though untested, implementation based on
211
       the IEEE standard. The functions catopen, catgets,
212
       catclose are used to retrieve locale-specific messages
213
       given the appropriate message catalogs that have been
214
       constructed for their use. Note, the script 
215
       po2msg.sed that is part of the gettext distribution can
216
       convert gettext catalogs into catalogs that
217
       catopen can use.
218
   
219
   
220
221
 
222
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
228
 
229
  
230
 
231
  
232
  The GNU Model
233
 
234
  
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
    LC_MESSAGES mask: LC_CTYPE is also
240
    necessary. To avoid any unpleasantness, all bits of the "C" mask
241
    (i.e. LC_ALL) are set before retrieving messages.
242
  
243
 
244
  
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
  
249
 
250
251
   
252
     
253
       Make a source file with the required string literals that need
254
       to be translated. See intl/string_literals.cc for
255
       an example.
256
     
257
   
258
 
259
   
260
     
261
       Make initial catalog (see "4 Making the PO Template File" from
262
       the gettext docs).
263
   
264
    xgettext --c++ --debug string_literals.cc -o libstdc++.pot 
265
   
266
   
267
 
268
   
269
     Make language and country-specific locale catalogs.
270
   
271
   cp libstdc++.pot fr_FR.po
272
   
273
   
274
   cp libstdc++.pot de_DE.po
275
   
276
   
277
 
278
   
279
     
280
       Edit localized catalogs in emacs so that strings are
281
       translated.
282
     
283
   
284
   emacs fr_FR.po
285
   
286
   
287
 
288
   
289
     Make the binary mo files.
290
   
291
   msgfmt fr_FR.po -o fr_FR.mo
292
   
293
   
294
   msgfmt de_DE.po -o de_DE.mo
295
   
296
   
297
 
298
   
299
     Copy the binary files into the correct directory structure.
300
   
301
   cp fr_FR.mo (dir)/fr_FR/LC_MESSAGES/libstdc++.mo
302
   
303
   
304
   cp de_DE.mo (dir)/de_DE/LC_MESSAGES/libstdc++.mo
305
   
306
   
307
 
308
   
309
     Use the new message catalogs.
310
   
311
   locale loc_de("de_DE");
312
   
313
   
314
   
315
   use_facet<messages<char> >(loc_de).open("libstdc++", locale(), dir);
316
   
317
   
318
   
319
320
 
321
  
322
323
 
324
325
Use
326
 
327
   A simple example using the GNU model of message conversion.
328
 
329
 
330
331
#include <iostream>
332
#include <locale>
333
using namespace std;
334
 
335
void test01()
336
{
337
  typedef messages<char>::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<char>& mssg_de = use_facet<messages<char> >(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 << "please in german:" << s01 << '\n';
347
  cout << "thank you in german:" << s02 << '\n';
348
  mssg_de.close(cat_de);
349
}
350
351
 
352
353
 
354
355
Future
356
 
357
358
359
  
360
    Things that are sketchy, or remain unimplemented:
361
  
362
   
363
      
364
        
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
        
373
      
374
 
375
      
376
        
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
        
383
      
384
   
385
386
 
387
388
  
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
  
398
399
400
  
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
  
410
411
 
412
413
   The following member functions:
414
 
415
   
416
   
417
        catalog
418
        open(const basic_string<char>& __s, const locale& __loc) const
419
   
420
   
421
 
422
   
423
   
424
   catalog
425
   open(const basic_string<char>&, const locale&, const char*) const;
426
   
427
   
428
 
429
   
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
   
436
437
438
 
439
440
 
441
442
Bibliography
443
 
444
  
445
    </code></pre></td>
      </tr>
      <tr valign="middle">
         <td>446</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>      The GNU C Library</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>447</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>    
448
    
449
      McGrath
450
      Roland
451
    
452
    
453
      Drepper
454
      Ulrich
455
    
456
    
457
      2007
458
      FSF
459
    
460
    Chapters 6 Character Set Handling, and 7 Locales and Internationalization
461
    
462
  
463
 
464
  
465
    </code></pre></td>
      </tr>
      <tr valign="middle">
         <td>466</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>      Correspondence</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>467</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>    
468
    
469
      Drepper
470
      Ulrich
471
    
472
    
473
      2002
474
      
475
    
476
  
477
 
478
  
479
    </code></pre></td>
      </tr>
      <tr valign="middle">
         <td>480</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>      ISO/IEC 14882:1998 Programming languages - C++</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>481</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>    
482
    
483
      1998
484
      ISO
485
    
486
  
487
 
488
  
489
    </code></pre></td>
      </tr>
      <tr valign="middle">
         <td>490</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>      ISO/IEC 9899:1999 Programming languages - C</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>491</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>    
492
 
493
    
494
      1999
495
      ISO
496
    
497
  
498
 
499
  
500
    
501
      
502
        
503
          System Interface Definitions, Issue 7 (IEEE Std. 1003.1-2008)
504
        
505
      
506
    
507
    
508
      2008
509
      
510
        The Open Group/The Institute of Electrical and Electronics
511
        Engineers, Inc.
512
      
513
    
514
  
515
 
516
  
517
    </code></pre></td>
      </tr>
      <tr valign="middle">
         <td>518</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>      The C++ Programming Language, Special Edition</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>519</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>    
520
    
521
      Stroustrup
522
      Bjarne
523
    
524
    
525
      2000
526
      Addison Wesley, Inc.
527
    
528
    Appendix D
529
    
530
      
531
        Addison Wesley
532
      
533
    
534
  
535
 
536
  
537
    </code></pre></td>
      </tr>
      <tr valign="middle">
         <td>538</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>      Standard C++ IOStreams and Locales</code></pre></td>
      </tr>
      <tr valign="middle">
         <td>539</td>
         <td></td>
         <td></td>
         <td class="code"><pre><code>    
540
    
541
      Advanced Programmer's Guide and Reference
542
    
543
    
544
      Langer
545
      Angelika
546
    
547
    
548
      Kreft
549
      Klaus
550
    
551
    
552
      2000
553
      Addison Wesley Longman, Inc.
554
    
555
    
556
      
557
        Addison Wesley Longman
558
      
559
    
560
  
561
 
562
  
563
    
564
      
565
        
566
          API Specifications, Java Platform
567
        
568
      
569
    
570
    java.util.Properties, java.text.MessageFormat,
571
java.util.Locale, java.util.ResourceBundle
572
    
573
  
574
 
575
  
576
    
577
      
578
        
579
          GNU gettext tools, version 0.10.38, Native Language Support
580
Library and Tools.
581
        
582
      
583
    
584
  
585
 
586
587
 
588

powered by: WebSVN 2.1.0

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