Sophie

Sophie

distrib > Mandriva > 8.2 > i586 > media > contrib > by-pkgid > 112b0974ad288f6cd55bf971ee6026a9 > files > 1980

libqt3-devel-3.0.2-2mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /tmp/qt-3.0-reggie-28534/qt-x11-free-3.0.2/src/kernel/qtranslator.cpp:213 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>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: #ffffff; color: black; }
--></style>
</head>
<body>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
 <a href="index.html">
<font color="#004faf">Home</font></a>
 | <a href="classes.html">
<font color="#004faf">All&nbsp;Classes</font></a>
 | <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
 | <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
 | <a href="groups.html">
<font color="#004faf">Grouped&nbsp;Classes</font></a>
 | <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QTranslator Class Reference</h1>

<p>The QTranslator class provides internationalization support for text
output.
<a href="#details">More...</a>
<p><tt>#include &lt;<a href="qtranslator-h.html">qtranslator.h</a>&gt;</tt>
<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="#QTranslator"><b>QTranslator</b></a> ( QObject&nbsp;*&nbsp;parent, const&nbsp;char&nbsp;*&nbsp;name = 0 )</div></li>
<li><div class=fn><a href="#~QTranslator"><b>~QTranslator</b></a> ()</div></li>
<li><div class=fn>QString find ( const&nbsp;char&nbsp;*&nbsp;context, const&nbsp;char&nbsp;*&nbsp;sourceText, const&nbsp;char&nbsp;*&nbsp;comment = 0 ) const &nbsp;<em>(obsolete)</em></div></li>
<li><div class=fn>virtual QTranslatorMessage <a href="#findMessage"><b>findMessage</b></a> ( const&nbsp;char&nbsp;*&nbsp;context, const&nbsp;char&nbsp;*&nbsp;sourceText, const&nbsp;char&nbsp;*&nbsp;comment ) const</div></li>
<li><div class=fn>bool <a href="#load"><b>load</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;filename, const&nbsp;QString&nbsp;&amp;&nbsp;directory = QString::null, const&nbsp;QString&nbsp;&amp;&nbsp;search_delimiters = QString::null, const&nbsp;QString&nbsp;&amp;&nbsp;suffix = QString::null )</div></li>
<li><div class=fn>void <a href="#clear"><b>clear</b></a> ()</div></li>
<li><div class=fn>enum <a href="#SaveMode-enum"><b>SaveMode</b></a> { Everything, Stripped }</div></li>
<li><div class=fn>bool <a href="#save"><b>save</b></a> ( const&nbsp;QString&nbsp;&amp;&nbsp;filename, SaveMode&nbsp;mode = Everything )</div></li>
<li><div class=fn>void <a href="#insert"><b>insert</b></a> ( const&nbsp;QTranslatorMessage&nbsp;&amp;&nbsp;message )</div></li>
<li><div class=fn>void insert ( const&nbsp;char&nbsp;*&nbsp;context, const&nbsp;char&nbsp;*&nbsp;sourceText, const&nbsp;QString&nbsp;&amp;&nbsp;translation ) &nbsp;<em>(obsolete)</em></div></li>
<li><div class=fn>void <a href="#remove"><b>remove</b></a> ( const&nbsp;QTranslatorMessage&nbsp;&amp;&nbsp;message )</div></li>
<li><div class=fn>void remove ( const&nbsp;char&nbsp;*&nbsp;context, const&nbsp;char&nbsp;*&nbsp;sourceText ) &nbsp;<em>(obsolete)</em></div></li>
<li><div class=fn>bool <a href="#contains"><b>contains</b></a> ( const&nbsp;char&nbsp;*&nbsp;context, const&nbsp;char&nbsp;*&nbsp;sourceText, const&nbsp;char&nbsp;*&nbsp;comment = 0 ) const</div></li>
<li><div class=fn>void <a href="#squeeze"><b>squeeze</b></a> ( SaveMode&nbsp;mode = Everything )</div></li>
<li><div class=fn>void <a href="#unsqueeze"><b>unsqueeze</b></a> ()</div></li>
<li><div class=fn>QValueList&lt;QTranslatorMessage&gt; <a href="#messages"><b>messages</b></a> () const</div></li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>
 
<p> The QTranslator class provides <a href="i18n.html#internationalization">internationalization</a> support for text
output.
<p> 


<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 them, load and save them,
etc.
<p> The most common use of QTranslator is expected to be loading a
translator file made using <a href="linguist-manual.html">Qt
  Linguist</a>, installing it using
<a href="qapplication.html#installTranslator">QApplication::installTranslator</a>(), and using it via <a href="qobject.html#tr">QObject::tr</a>(),
like this:
<p> <pre>
  int main( int argc, char ** argv )
  {
      <a href="qapplication.html">QApplication</a> app( argc, argv );

      QTranslator translator( 0 );
      translator.<a href="#load">load</a>( "french.qm", "." );
      app.<a href="qapplication.html#installTranslator">installTranslator</a>( &amp;translator );

      MyWidget m;
      app.<a href="qapplication.html#setMainWidget">setMainWidget</a>( &amp;m );
      m.show();

      return app.<a href="qapplication.html#exec">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="#findMessage">findMessage</a>() (as <a href="qobject.html#tr">tr</a>() and
<a href="qapplication.html#translate">QApplication::translate</a>() do) and <a href="#contains">contains</a>(), insert a new
translation message using <a href="#insert">insert</a>(), and remove it using <a href="#remove">remove</a>().
<p> Because 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="#load">load</a>() may not load enough information to make anything more
than findMessage() work.  <a href="#save">save</a>() has an argument indicating whether
to save just this minimum of information or to save everything.
<p> "Everything" means that for each translation item the following
information is kept:
<p> <ul>
<li> The <em>translated text</em> - the return value from tr().
<li> The input key:
<ul>
<li> The <em>source text</em> - usually the argument to tr().
<li> The <em>context</em> - usually the class name for the <a href="qobject.html#tr">tr</a>() caller.
<li> The <em>comment</em> - a comment that helps disambiguate different uses
of the same text in the same context.
</ul>
</ul>
<p> The minimum for each item is just the information necessary for
<a href="#findMessage">findMessage</a>() to return the right text.  This may include the source,
context and comment, but usually it 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 this 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 enables 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> <p>See also <a href="qtranslatormessage.html">QTranslatorMessage</a>, <a href="qapplication.html#installTranslator">QApplication::installTranslator</a>(), <a href="qapplication.html#removeTranslator">QApplication::removeTranslator</a>(), <a href="qobject.html#tr">QObject::tr</a>(), <a href="qapplication.html#translate">QApplication::translate</a>(), <a href="environment.html">Environment Classes</a> and <a href="i18n.html">Internationalization with Qt</a>.

<hr><h2>Member Type Documentation</h2>
<h3 class=fn><a name="SaveMode-enum"></a>QTranslator::SaveMode</h3> 
This enum type defines how QTranslator can write translation files.
There are two modes:
<ul>
<li><tt>QTranslator::Everything</tt> - files are saved with all contents
<li><tt>QTranslator::Stripped</tt> - 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="QTranslator"></a>QTranslator::QTranslator ( <a href="qobject.html">QObject</a>&nbsp;*&nbsp;parent, const&nbsp;char&nbsp;*&nbsp;name = 0 )
</h3>
Constructs an empty message file object that is not connected to
any file. The object has parent <em>parent</em> and name <em>name</em>.

<h3 class=fn><a name="~QTranslator"></a>QTranslator::~QTranslator ()
</h3>  Destroys the object and frees any allocated resources.

<h3 class=fn>void <a name="clear"></a>QTranslator::clear ()
</h3>  Empties this translator of all contents.
<p> This function works with stripped translator files.

<h3 class=fn>bool <a name="contains"></a>QTranslator::contains ( const&nbsp;char&nbsp;*&nbsp;context, const&nbsp;char&nbsp;*&nbsp;sourceText, const&nbsp;char&nbsp;*&nbsp;comment = 0 ) const
</h3>  Returns TRUE if this message file contains a message with the key
(<em>context</em>, <em>sourceText</em>, <em>comment</em>); otherwise returns FALSE.
<p> This function works with stripped translator files.
<p> (This is is a one-liner that calls <a href="#find">find</a>().)

<h3 class=fn><a href="qstring.html">QString</a> <a name="find"></a>QTranslator::find ( const&nbsp;char&nbsp;*&nbsp;context, const&nbsp;char&nbsp;*&nbsp;sourceText, const&nbsp;char&nbsp;*&nbsp;comment = 0 ) const
</h3>

<b>This function is obsolete.</b> It is provided to keep old source working. We strongly advise against using it in new code.
<p> Please use <a href="#findMessage">findMessage</a>() instead.
<p> Returns the translation for the key (<em>context</em>, <em>sourceText</em>,
<em>comment</em>) or <a href="qstring.html#QString-null">QString::null</a> if there is none in this translator.

<h3 class=fn><a href="qtranslatormessage.html">QTranslatorMessage</a> <a name="findMessage"></a>QTranslator::findMessage ( const&nbsp;char&nbsp;*&nbsp;context, const&nbsp;char&nbsp;*&nbsp;sourceText, const&nbsp;char&nbsp;*&nbsp;comment ) const<tt> [virtual]</tt>
</h3>  Returns the <a href="qtranslatormessage.html">QTranslatorMessage</a> for the key
(<em>context</em>, <em>sourceText</em>, <em>comment</em>).

<h3 class=fn>void <a name="insert"></a>QTranslator::insert ( const&nbsp;<a href="qtranslatormessage.html">QTranslatorMessage</a>&nbsp;&amp;&nbsp;message )
</h3>  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> <p>See also <a href="#remove">remove</a>().

<h3 class=fn>void <a name="insert-2"></a>QTranslator::insert ( const&nbsp;char&nbsp;*&nbsp;context, const&nbsp;char&nbsp;*&nbsp;sourceText, const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;translation )
</h3>

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> <b>This function is obsolete.</b> It is provided to keep old source working. We strongly advise against using it in new code.
<p> 
<h3 class=fn>bool <a name="load"></a>QTranslator::load ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;filename, const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;directory = QString::null, const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;search_delimiters = QString::null, const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;suffix = QString::null )
</h3>  Loads <em>filename</em>, which may be an absolute file name or relative
to <em>directory</em>.  The previous contents of this translator object is
discarded.
<p> If the full file name does not exist, other file names
are tried in the following order:
<p> <ol type=1>
<li> File name with <em>suffix</em> appended (".qm" if the suffix is <a href="qstring.html#QString-null">QString::null</a>).
<li> File name 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> File name stripped and <em>suffix</em> appended.
<li> File name stripped further, etc.
</ol>
<p> For example, an application running in the fr_CA locale
(French-speaking Canada) might call <a href="#load">load</a>("foo.fr_ca", "/opt/foolib"),
which would then try to open these files:
<p> <ol type=1>
<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> <p>See also <a href="#save">save</a>().

<p>Example: <a href="i18n-example.html#x1381">i18n/main.cpp</a>.
<h3 class=fn><a href="qvaluelist.html">QValueList</a>&lt;QTranslatorMessage&gt; <a name="messages"></a>QTranslator::messages () const
</h3>  Returns a list of the messages in the translator.  This function is
rather slow; because it is seldom called, it's optimized for simplicity and
small size, not speed.
<p> Note that if you want to iterate over the list, you should
iterate over a copy, e.g.
<pre>
    <a href="qvaluelist.html">QValueList</a>&lt;QTranslatorMessage&gt; list = myTranslator.messages();
    QValueList&lt;QTranslatorMessage&gt;::Iterator it = list.<a href="qvaluelist.html#begin">begin</a>();
    while( it != list.<a href="qvaluelist.html#end">end</a>() ) {
        myProcessing( *it );
        ++it;
    }
    </pre>
 

<h3 class=fn>void <a name="remove"></a>QTranslator::remove ( const&nbsp;<a href="qtranslatormessage.html">QTranslatorMessage</a>&nbsp;&amp;&nbsp;message )
</h3>  Removes <em>message</em> from this translator.
<p> This function works with stripped translator files.
<p> <p>See also <a href="#insert">insert</a>().

<h3 class=fn>void <a name="remove-2"></a>QTranslator::remove ( const&nbsp;char&nbsp;*&nbsp;context, const&nbsp;char&nbsp;*&nbsp;sourceText )
</h3>

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> <b>This function is obsolete.</b> It is provided to keep old source working. We strongly advise against using it in new code.
<p> Removes the translation associated to the key (<em>context</em>, <em>sourceText</em>,
"") from this translator.

<h3 class=fn>bool <a name="save"></a>QTranslator::save ( const&nbsp;<a href="qstring.html">QString</a>&nbsp;&amp;&nbsp;filename, <a href="qtranslator.html#SaveMode-enum">SaveMode</a>&nbsp;mode = Everything )
</h3>  Saves this message file to <em>filename</em>, overwriting the previous
contents of <em>filename</em>.  If <em>mode</em> is <a href="#SaveMode-enum">Everything</a> (the
default), all the information is preserved.  If <em>mode</em> is <a href="#SaveMode-enum">Stripped</a>,
any information that is not necessary for <a href="#findMessage">findMessage</a>() is stripped
away.
<p> <p>See also <a href="#load">load</a>().

<h3 class=fn>void <a name="squeeze"></a>QTranslator::squeeze ( <a href="qtranslator.html#SaveMode-enum">SaveMode</a>&nbsp;mode = Everything )
</h3> 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="#save">save</a>() and other functions call
it as necessary. <em>mode</em> is for internal use.
<p> <p>See also <a href="#save">save</a>() and <a href="#unsqueeze">unsqueeze</a>().

<h3 class=fn>void <a name="unsqueeze"></a>QTranslator::unsqueeze ()
</h3>  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="#insert">insert</a>() and
friends as necessary.
<p> <p>See also <a href="#squeeze">squeeze</a>().

<!-- eof -->
<hr><p>
This file is part of the <a href="index.html">Qt toolkit</a>.
Copyright &copy; 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 &copy; 2001 
<a href="http://www.trolltech.com">Trolltech</a><td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a>
<td align=right><div align=right>Qt version 3.0.2</div>
</table></div></address></body>
</html>