File: classWt_1_1WMessageResourceBundle.html

package info (click to toggle)
witty 3.1.2-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 45,512 kB
  • ctags: 35,832
  • sloc: cpp: 69,469; ansic: 66,945; xml: 4,383; sh: 594; perl: 108; makefile: 106
file content (222 lines) | stat: -rw-r--r-- 14,139 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>Wt: Wt::WMessageResourceBundle Class Reference</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.6 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="annotated.html"><span>Class&nbsp;List</span></a></li>
      <li><a href="hierarchy.html"><span>Class&nbsp;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&nbsp;Members</span></a></li>
    </ul>
  </div>
  <div class="navpath"><a class="el" href="namespaceWt.html">Wt</a>::<a class="el" href="classWt_1_1WMessageResourceBundle.html">WMessageResourceBundle</a>
  </div>
</div>
<div class="contents">
<h1>Wt::WMessageResourceBundle Class Reference</h1><!-- doxytag: class="Wt::WMessageResourceBundle" --><!-- doxytag: inherits="Wt::WLocalizedStrings" -->Support for localized strings using XML files.  
<a href="#_details">More...</a>
<p>
<code>#include &lt;Wt/WMessageResourceBundle&gt;</code>
<p>
<div class="dynheader">
Inheritance diagram for Wt::WMessageResourceBundle:</div>
<div class="dynsection">
<p><center><img src="classWt_1_1WMessageResourceBundle__inherit__graph.png" border="0" usemap="#Wt_1_1WMessageResourceBundle__inherit__map" alt="Inheritance graph"></center>
<map name="Wt_1_1WMessageResourceBundle__inherit__map">
<area shape="rect" href="classWt_1_1WLocalizedStrings.html" title="An abstract class that provides support for localized strings." alt="" coords="32,5,184,32"></map>
<center><font size="2">[<a href="graph_legend.html">legend</a>]</font></center></div>

<p>
<a href="classWt_1_1WMessageResourceBundle-members.html">List of all members.</a><table border="0" cellpadding="0" cellspacing="0">
<tr><td></td></tr>
<tr><td colspan="2"><br><h2>Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="anchor" name="ecfe527e2123bf7793d926f71dc2ed23"></a><!-- doxytag: member="Wt::WMessageResourceBundle::WMessageResourceBundle" ref="ecfe527e2123bf7793d926f71dc2ed23" args="()" -->
&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1WMessageResourceBundle.html#ecfe527e2123bf7793d926f71dc2ed23">WMessageResourceBundle</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Creates a message resource bundle. <br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1WMessageResourceBundle.html#01368946b2a2aaceab3a64cddb1cb1e2">use</a> (const std::string &amp;path, bool loadInMemory=true)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Adds a (series) of message resource files to be used.  <a href="#01368946b2a2aaceab3a64cddb1cb1e2"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1WMessageResourceBundle.html#8dd275eff8f823ee58a1e673a79b71e7">refresh</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Rereads the message resources.  <a href="#8dd275eff8f823ee58a1e673a79b71e7"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1WMessageResourceBundle.html#5e6c391a95229691fcae8c058c637b7b">hibernate</a> ()</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Purges memory resources, if possible.  <a href="#5e6c391a95229691fcae8c058c637b7b"></a><br></td></tr>
<tr><td class="memItemLeft" nowrap align="right" valign="top">virtual bool&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classWt_1_1WMessageResourceBundle.html#22878a466da85139384133f01c7fec77">resolveKey</a> (const std::string &amp;key, std::string &amp;result)</td></tr>

<tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Resolves a key in the current locale.  <a href="#22878a466da85139384133f01c7fec77"></a><br></td></tr>
</table>
<hr><a name="_details"></a><h2>Detailed Description</h2>
Support for localized strings using XML files. 
<p>
The resource bundle manages a number of resource files, which allow the developer to conceptually manage its messages in a number of libraries.<p>
For example, a <a class="el" href="classWt_1_1WApplication.html" title="Represents an application instance for a single session.">WApplication</a> may have a generic message library, that is shared with many other libraries, with re-occurring messages (such as 'welcome', 'add to shopping cart', and 'pay'), and a specific message library for specific messages.<p>
Usage example:<p>
XML file "general.xml": <div class="fragment"><pre class="fragment"> &lt;?xml version=<span class="stringliteral">"1.0"</span> encoding=<span class="stringliteral">"UTF-8"</span>?&gt;
 &lt;messages&gt;
   &lt;message <span class="keywordtype">id</span>=<span class="stringliteral">'welcome-text'</span>&gt;
     Welcome dear visiter, {1} of the WFooBar magic website !
   &lt;/message&gt;
   &lt;message <span class="keywordtype">id</span>=<span class="stringliteral">'company-policy'</span>&gt;
     The company policy is to &lt;b&gt;please our share-holders&lt;/b&gt;.
   &lt;/message&gt;
 &lt;/messages&gt;
</pre></div><p>
Use this resource bundle in your program: <div class="fragment"><pre class="fragment"> <span class="comment">// load the message resource bundle</span>
 <a class="code" href="classWt_1_1WApplication.html" title="Represents an application instance for a single session.">Wt::WApplication</a> *app = <a class="code" href="classWt_1_1WApplication.html#38d922da0a0d83395519f3eaab85d0f6" title="Returns the current application instance.">Wt::WApplication::instance</a>();
 app-&gt;<a class="code" href="classWt_1_1WApplication.html#5386565e35a58c94ccbbfab48f2212a4" title="Returns the message resource bundle.">messageResourceBundle</a>().use(<span class="stringliteral">"general"</span>);

 <span class="comment">// resolve a string using the resource bundle</span>
 <a class="code" href="classWt_1_1WText.html" title="A widget that renders (XHTML) text.">Wt::WText</a> *welcome = <span class="keyword">new</span> <a class="code" href="classWt_1_1WText.html" title="A widget that renders (XHTML) text.">Wt::WText</a>(tr(<span class="stringliteral">"welcome-visitor"</span>).arg(<span class="stringliteral">"Bart"</span>));
</pre></div> <hr><h2>Member Function Documentation</h2>
<a class="anchor" name="01368946b2a2aaceab3a64cddb1cb1e2"></a><!-- doxytag: member="Wt::WMessageResourceBundle::use" ref="01368946b2a2aaceab3a64cddb1cb1e2" args="(const std::string &amp;path, bool loadInMemory=true)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Wt::WMessageResourceBundle::use           </td>
          <td>(</td>
          <td class="paramtype">const std::string &amp;&nbsp;</td>
          <td class="paramname"> <em>path</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">bool&nbsp;</td>
          <td class="paramname"> <em>loadInMemory</em> = <code>true</code></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Adds a (series) of message resource files to be used. 
<p>
The <code>path</code> is not a URI, and relative paths will be resolved with respect to the working directory of the server. The XML files do not need to be deployed in the web server's docroot.<p>
When you give as <code>path:</code> /path/to/name, then the following message resource files will be used:<ul>
<li>/path/to/name.xml (default, English)</li><li>/path/to/name_nl.xml (for Dutch)</li><li>/path/to/name_fr.xml (for French)</li><li>etc...</li></ul>
<p>
The message file that is used depends on the application's locale.<p>
A Message resource file must be formatted as follows: <div class="fragment"><pre class="fragment">     &lt;?xml version=<span class="stringliteral">"1.0"</span> encoding=<span class="stringliteral">"UTF-8"</span>?&gt;
     &lt;messages&gt;
       &lt;message <span class="keywordtype">id</span>=<span class="stringliteral">'welcome-text'</span>&gt;
         Welcome dear visiter, {1} of the WFooBar magic website !
       &lt;/message&gt;
       &lt;message <span class="keywordtype">id</span>=<span class="stringliteral">'company-policy'</span>&gt;
         The company policy is to &lt;b&gt;please our share-holders&lt;/b&gt;.
       &lt;/message&gt;
     &lt;/messages&gt;
</pre></div><p>
The encodings supported are ASCII, UTF-8 (recommended) or UTF-16.<p>
To refer the two messages defined in this resource file, use <a class="el" href="classWt_1_1WString.html#0afc7dc0f9897456d71b569a86ca26c1" title="Creates a localized string from a key.">WString::tr</a>("welcome-text").<a class="el" href="classWt_1_1WString.html#1c3d0d7790282777ce13edececfe0095">arg</a>(userName) or <a class="el" href="classWt_1_1WWidget.html#a651f107ec7cf080faef6c435705fc44" title="Short hand for WString::tr().">WWidget::tr</a>("company-policy").<p>
<dl class="see" compact><dt><b>See also:</b></dt><dd><a class="el" href="classWt_1_1WApplication.html#6e782f1f38a6f56e2024aab1a917a80b" title="Returns the current locale.">WApplication::locale()</a>, <a class="el" href="classWt_1_1WString.html#0afc7dc0f9897456d71b569a86ca26c1" title="Creates a localized string from a key.">WString::tr()</a>, <a class="el" href="classWt_1_1WWidget.html#a651f107ec7cf080faef6c435705fc44" title="Short hand for WString::tr().">WWidget::tr()</a> </dd></dl>

</div>
</div><p>
<a class="anchor" name="8dd275eff8f823ee58a1e673a79b71e7"></a><!-- doxytag: member="Wt::WMessageResourceBundle::refresh" ref="8dd275eff8f823ee58a1e673a79b71e7" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Wt::WMessageResourceBundle::refresh           </td>
          <td>(</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td><code> [virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Rereads the message resources. 
<p>
Purge any cached key/values, if applicable.<p>
The default implementation does nothing. 
<p>Reimplemented from <a class="el" href="classWt_1_1WLocalizedStrings.html#71b2ca0b40eed56ee1acba8f865e7220">Wt::WLocalizedStrings</a>.</p>

</div>
</div><p>
<a class="anchor" name="5e6c391a95229691fcae8c058c637b7b"></a><!-- doxytag: member="Wt::WMessageResourceBundle::hibernate" ref="5e6c391a95229691fcae8c058c637b7b" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void Wt::WMessageResourceBundle::hibernate           </td>
          <td>(</td>
          <td class="paramname">          </td>
          <td>&nbsp;)&nbsp;</td>
          <td><code> [virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Purges memory resources, if possible. 
<p>
This is called afer event handling, and is an opportunity to conserve memory inbetween events, by freeing memory used for cached key/value bindings, if applicable.<p>
The default implementation does nothing. 
<p>Reimplemented from <a class="el" href="classWt_1_1WLocalizedStrings.html#2ea29ba180ed9af25cf561f0df6a995d">Wt::WLocalizedStrings</a>.</p>

</div>
</div><p>
<a class="anchor" name="22878a466da85139384133f01c7fec77"></a><!-- doxytag: member="Wt::WMessageResourceBundle::resolveKey" ref="22878a466da85139384133f01c7fec77" args="(const std::string &amp;key, std::string &amp;result)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool Wt::WMessageResourceBundle::resolveKey           </td>
          <td>(</td>
          <td class="paramtype">const std::string &amp;&nbsp;</td>
          <td class="paramname"> <em>key</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">std::string &amp;&nbsp;</td>
          <td class="paramname"> <em>result</em></td><td>&nbsp;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td><td><code> [virtual]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>
Resolves a key in the current locale. 
<p>
This method is used by <a class="el" href="classWt_1_1WString.html" title="A unicode string class, with support for localization.">WString</a> to obtain the UTF8 value corresponding to a key in the current locale.<p>
Returns <code>true</code> if the key could be resolved. The value is written in <code>result</code>, encoded using UTF8.<p>
<dl class="see" compact><dt><b>See also:</b></dt><dd><a class="el" href="classWt_1_1WApplication.html#6e782f1f38a6f56e2024aab1a917a80b" title="Returns the current locale.">WApplication::locale()</a> </dd></dl>

<p>Implements <a class="el" href="classWt_1_1WLocalizedStrings.html#05666a0ae917e4fd6deafdd2f4b98ba2">Wt::WLocalizedStrings</a>.</p>

</div>
</div><p>
</div>
<hr size="1"><address style="align: right;"><small>
Generated on Fri Mar 26 17:12:07 2010 for <a href="http://www.webtoolkit.eu/wt/">Wt</a> by&nbsp;<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6</small></address>
</body>
</html>