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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Qt Toolkit - QTranslator Class</title><style type="text/css"><!--
h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }body { background: white; color: black; }
--></style>
</head><body bgcolor="#ffffff">
<table width="100%">
<tr><td><a href="index.html">
<img width="100" height="100" src="qtlogo.png"
alt="Home" border="0"><img width="100"
height="100" src="face.png" alt="Home" border="0">
</a><td valign=top><div align=right><img src="dochead.png" width="472" height="27"><br>
<a href="classes.html"><b>Classes</b></a>
-<a href="annotated.html">Annotated</a>
- <a href="hierarchy.html">Tree</a>
-<a href="functions.html">Functions</a>
-<a href="index.html">Home</a>
-<a href="topicals.html"><b>Structure</b></a>
</div>
</table>
<h1 align=center>QTranslator Class Reference</h1><br clear="all">
<p>
The QTranslator class provides internationalization support for text output.
<a href="#details">More...</a>
<p>
<code>#include <<a href="qtranslator-h.html">qtranslator.h</a>></code>
<p>
Inherits <a href="qobject.html">QObject</a>.
<p><a href="qtranslator-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li><div class="fn"><a href="#36b48a"><b>QTranslator</b></a>(QObject*parent, constchar*name=0)</div>
<li><div class="fn"><a href="#a5a2cc"><b>~QTranslator</b></a>()</div>
<li><div class="fn">QString<a href="#b21ef6"><b>find</b></a>(constchar*, constchar*, constchar*)const</div>
<li><div class="fn">virtualQStringfind(constchar*, constchar*)const<em>(obsolete)</em></div>
<li><div class="fn">QTranslatorMessage<a href="#df8fd0"><b>findMessage</b></a>(constchar*, constchar*, constchar*)const</div>
<li><div class="fn">bool<a href="#4053d1"><b>load</b></a>(constQString&filename, constQString&directory=QString::null, constQString&search_delimiters=QString::null, constQString&suffix=QString::null)</div>
<li><div class="fn">enum<a href="#SaveMode"><b>SaveMode</b></a>{Everything, Stripped}</div>
<li><div class="fn">bool<a href="#8e3915"><b>save</b></a>(constQString&filename, SaveModemode=Everything)</div>
<li><div class="fn">void<a href="#66f0cb"><b>clear</b></a>()</div>
<li><div class="fn">void<a href="#6bd9cb"><b>insert</b></a>(constQTranslatorMessage&)</div>
<li><div class="fn">voidinsert(constchar*, constchar*, constQString&)<em>(obsolete)</em></div>
<li><div class="fn">void<a href="#f3ff87"><b>remove</b></a>(constQTranslatorMessage&)</div>
<li><div class="fn">voidremove(constchar*, constchar*)<em>(obsolete)</em></div>
<li><div class="fn">bool<a href="#bc65d3"><b>contains</b></a>(constchar*, constchar*, constchar*)const</div>
<li><div class="fn">boolcontains(constchar*, constchar*)const<em>(obsolete)</em></div>
<li><div class="fn">void<a href="#2eb4c1"><b>squeeze</b></a>(SaveMode)</div>
<li><div class="fn">void<a href="#16832e"><b>squeeze</b></a>()</div>
<li><div class="fn">void<a href="#544f17"><b>unsqueeze</b></a>()</div>
<li><div class="fn">QValueList<QTranslatorMessage><a href="#478747"><b>messages</b></a>()const</div>
</ul>
<hr><h2><a name="details"></a>Detailed Description</h2>
The QTranslator class provides internationalization support for text output.
<p>
An object of this class contains a set of <a href="qtranslatormessage.html">QTranslatorMessage</a>
objects, each of which specifies a translation from a source
language to a target language. QTranslator provides functions to
look up such translations, add new ones, remove, load and save them,
etc.
<p>The most common use of QTranslator is expected to be loading a
translator file, installing it using
<a href="qapplication.html#e8df5e">QApplication::installTranslator</a>(), and using it via <a href="qobject.html#2418a9">QObject::tr</a>(),
like this:
<p><pre> int main( int argc, char ** argv )
{
<a href="qapplication.html">QApplication</a> app( argc, argv );
<a href="qtranslator.html">QTranslator</a> translator( 0 );
translator.<a href="#4053d1">load</a>( "trfile.qm", "." );
app.<a href="qapplication.html#e8df5e">installTranslator</a>( &translator );
MyWidget m;
app.<a href="qapplication.html#7ad759">setMainWidget</a>( &m );
m.show();
return app.<a href="qapplication.html#84c7bf">exec</a>();
}
</pre>
<p>Most applications will never need to do anything else with this
class. However, applications that work on translator files need the
other functions in this class.
<p>It is possible to do lookup using <a href="#df8fd0">findMessage</a>() (as <a href="qobject.html#2418a9">tr</a>() and
<a href="qapplication.html#35f6de">QApplication::translate</a>() do) and <a href="#bc65d3">contains</a>(), insert a new
translation message using <a href="#6bd9cb">insert</a>() and removing them using <a href="#f3ff87">remove</a>().
<p>Since end-user programs and translation tools have rather different
requirements, QTranslator can use stripped translator files in a way
that uses a minimum of memory and provides very little functionality
other than findMessage().
<p>Thus, <a href="#4053d1">load</a>() may not load enough information to make anything more
than findMessage() work. <a href="#8e3915">save</a>() has an argument indicating whether
to save just this minimum of information, or everything.
<p>Everything means that for each translation item the following information
is kept: <ul>
<li> The <em>translated text</em> - the return value from tr().
<li> The input key: <ul>
<li> The <em>source text</em> - the argument to tr(), normally.
<li> The <em>context</em> - usually the class name for the tr() caller.
<li> The <em>comment</em> - a comment which helps disambiguate different uses
of the same text in the same context.
</ul>
</ul>
<p>The minimum is, for each item, just the information that is
necessary for findMessage() to return the right text. This may
include the source, context and comment, but usually is just a
hash value and the translated text.
<p>For example, the "Cancel" in a dialog might have "Anuluj" when the
program runs in Polish, in which case the source text would be
"Cancel", the context would (normally) be the dialog's class name,
there would normally be no comment, and the translated text would be
"Anuluj".
<p>But it's not always so simple: The Spanish version of a printer
dialog with settings for two-sided printing and binding would
probably require both "Activado" and "Activada" as translations for
"Enabled". In this case, the source text would be "Enabled" in both
cases and the context would be the dialog's class name, but the two
items would have disambiguating comments such as "two-sided
printing" for one and "binding" for the other. The comment enables
the translator to choose the appropriate gender for the Spanish
version, and Qt to distinguish between translations.
<p>Note that when QTranslator loads a stripped file, most functions do
not work. The functions that do work with stripped files are
explicitly documented as such.
<p>See also <a href="qtranslatormessage.html">QTranslatorMessage</a>, <a href="qapplication.html#e8df5e">QApplication::installTranslator</a>(), <a href="qapplication.html#8e6099">QApplication::removeTranslator</a>(), <a href="qobject.html#2418a9">QObject::tr</a>() and <a href="qapplication.html#35f6de">QApplication::translate</a>().
<p>Examples:
<a href="i18n-main-cpp.html#QTranslator">i18n/main.cpp</a>
<hr><h2>Member Type Documentation</h2>
<h3 class="fn"><a name="SaveMode">QTranslator::SaveMode</a></h3>
This enum type defines how QTranslator can write translation files.
There are two modes:
<p><ul>
<li> <code>Everything</code> - files are saved with all contents
<li> <code>Stripped</code> - files are saved with just what's needed for end-users
</ul>
<p>Note that when QTranslator loads a stripped file, most functions do
not work. The functions that do work with stripped files are
explicitly documented as such.
<hr><h2>Member Function Documentation</h2>
<h3 class="fn"><a name="36b48a"></a>QTranslator::QTranslator(<a href="qobject.html">QObject</a>*parent, constchar*name=0)</h3>
<p>Constructs an empty message file, not connected to any file.
<h3 class="fn"><a name="a5a2cc"></a>QTranslator::~QTranslator()</h3>
<p>Destructs the object and frees any allocated resources.
<h3 class="fn">void<a name="66f0cb"></a>QTranslator::clear()</h3>
<p>Empties this translator of all contents.
<p>This function works with stripped translator files.
<h3 class="fn">bool<a name="bc65d3"></a>QTranslator::contains(constchar*context, constchar*sourceText, constchar*comment)const</h3>
<p>Returns TRUE if this message file contains a message with the key
( <em>context, sourceText, comment</em> ), and FALSE if it does not.
<p>This function works with stripped translator files.
<p>(This is is a one-liner that calls <a href="#b21ef6">find</a>().).
<h3 class="fn">bool<a name="57de28"></a>QTranslator::contains(constchar*context, constchar*sourceText)const</h3>
<p><b>This function is obsolete.</b> It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.<p>This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
<p>This version of the function assumes that the comment is "".
<h3 class="fn"><a href="qstring.html">QString</a><a name="b21ef6"></a>QTranslator::find(constchar*context, constchar*sourceText, constchar*comment)const</h3>
<p>Returns the translation for the key ( <em>context, sourceText, comment</em> ), or QString::null if there is none in this translator.
<p>This function works with stripped translator files.
<p>See also findMessage.
<h3 class="fn"><a href="qstring.html">QString</a><a name="2f8c7f"></a>QTranslator::find(constchar*context, constchar*sourceText)const <code>[virtual]</code></h3>
<p><b>This function is obsolete.</b> It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.<p>This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
<p>Returns the translation for the key ( <em>context, sourceText,</em> "" ), or
QString::null if there is none in this translator.
<h3 class="fn"><a href="qtranslatormessage.html">QTranslatorMessage</a><a name="df8fd0"></a>QTranslator::findMessage(constchar*context, constchar*sourceText, constchar*comment)const</h3>
<p>Returns the <a href="qtranslatormessage.html">QTranslatorMessage</a> for the key
( <em>context, sourceText, comment</em> ).
<h3 class="fn">void<a name="6bd9cb"></a>QTranslator::insert(const<a href="qtranslatormessage.html">QTranslatorMessage</a>&message)</h3>
<p>Inserts <em>message</em> into this message file.
<p>This function does <em>not</em> work with stripped translator files. It
may seem to, but that is not dependable.
<p>See also <a href="#f3ff87">remove</a>().
<h3 class="fn">void<a name="901619"></a>QTranslator::insert(constchar*context, constchar*sourceText, const<a href="qstring.html">QString</a>&translation)</h3>
<p><b>This function is obsolete.</b> It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.<p>This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
<h3 class="fn">bool<a name="4053d1"></a>QTranslator::load(const<a href="qstring.html">QString</a>&filename, const<a href="qstring.html">QString</a>&directory=QString::null, const<a href="qstring.html">QString</a>&search_delimiters=QString::null, const<a href="qstring.html">QString</a>&suffix=QString::null)</h3>
<p>Loads <em>filename,</em> which may be an absolute file name or relative
to <em>directory.</em> If the full filename does not exist, other filenames
are tried in the following order:
<p><ol>
<li>Filename with <em>suffix</em> appended (".qm" if suffix is QString::null)
<li>Filename with text after a character in <em>search_delimiters</em> stripped
("_." is the default for <em>search_delimiters</em> if it is QString::null)
<li>Filename stripped and <em>suffix</em> appended.
<li>Filename stripped further, etc.
</ol>
<p>For example, an application running in the fr_CA locale
(Frech-speaking Canada) might call load("foo.fr_ca", "/opt/foolib"),
which would then try to open these files:
<p><ol>
<li>/opt/foolib/foo.fr_ca
<li>/opt/foolib/foo.fr_ca.qm
<li>/opt/foolib/foo.fr
<li>/opt/foolib/foo.fr.qm
<li>/opt/foolib/foo
<li>/opt/foolib/foo.qm
</ol>
<p>See also <a href="#8e3915">save</a>().
<h3 class="fn"><a href="qvaluelist.html">QValueList</a><<a href="qtranslatormessage.html">QTranslatorMessage</a>><a name="478747"></a>QTranslator::messages()const</h3>
<p>Returns a list of the messages in the translator. This function is
somewhat slow; since it's seldom called it's optimized for simplicity and
small size, not speed.
<h3 class="fn">void<a name="f3ff87"></a>QTranslator::remove(const<a href="qtranslatormessage.html">QTranslatorMessage</a>&message)</h3>
<p>Removes <em>message</em> from this translator.
<p>This function works with stripped translator files.
<p>See also <a href="#6bd9cb">insert</a>().
<h3 class="fn">void<a name="ab9994"></a>QTranslator::remove(constchar*context, constchar*sourceText)</h3>
<p><b>This function is obsolete.</b> It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.<p>This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
<p>Removes the translation associated to the key ( <em>context, sourceText,</em>
"" ) from this translator.
<h3 class="fn">bool<a name="8e3915"></a>QTranslator::save(const<a href="qstring.html">QString</a>&filename, <a href="qtranslator.html#SaveMode">SaveMode</a>mode=Everything)</h3>
<p>Saves this message file to <em>filename,</em> overwriting the previous
contents of <em>filename.</em> If <em>mode</em> is <code>Everything</code> (this is the
default), all the information is preserved. If <em>mode</em> is <code>Stripped,</code>
all information that is not necessary for <a href="#df8fd0">findMessage</a>() is stripped
away.
<p>See also <a href="#4053d1">load</a>().
<h3 class="fn">void<a name="2eb4c1"></a>QTranslator::squeeze(<a href="qtranslator.html#SaveMode">SaveMode</a>mode)</h3>
<p>Converts this message file to the compact format used to store
message files on disk.
<p>You should never need to call this directly; <a href="#8e3915">save</a>() and other functions call
it as necessary.
<p>See also <a href="#8e3915">save</a>() and <a href="#544f17">unsqueeze</a>().
<h3 class="fn">void<a name="16832e"></a>QTranslator::squeeze()</h3>
<p>This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
<p>This function calls <a href="#2eb4c1">squeeze</a>( Everything ). It is provided for compatibility;
in Qt 3.0 it will be replaced by a default argument.
<h3 class="fn">void<a name="544f17"></a>QTranslator::unsqueeze()</h3>
<p>Converts this message file into an easily modifiable data structure, less
compact than the format used in the files.
<p>You should never need to call this function; it is called by <a href="#6bd9cb">insert</a>() and
friends as necessary.
<p>See also <a href="#2eb4c1">squeeze</a>().
<hr><p>
Search the documentation, FAQ, qt-interest archive and more (uses
<a href="http://www.trolltech.com">www.trolltech.com</a>):<br>
<form method=post action="http://www.trolltech.com/search.cgi">
<input type=hidden name="version" value="2.3.2"><nobr>
<input size="50" name="search"><input type=submit value="Search">
</nobr></form><hr><p>
This file is part of the <a href="index.html">Qt toolkit</a>,
copyright © 1995-2001
<a href="http://www.trolltech.com">Trolltech</a>, all rights reserved.<p><address><hr><div align="center">
<table width="100%" cellspacing="0" border="0"><tr>
<td>Copyright 2001 Trolltech<td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a>
<td align="right"><div align="right">Qt version 2.3.2</div>
</table></div></address></body></html>
|