You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tqt3/doc/html/ntqtranslator.html

327 lines
18 KiB

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/kernel/qtranslator.cpp:216 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>TQTranslator Class</title>
<style type="text/css"><!--
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>TQTranslator Class Reference</h1>
<p>The TQTranslator class provides internationalization support for text
output.
<a href="#details">More...</a>
<p><tt>#include &lt;<a href="qtranslator-h.html">ntqtranslator.h</a>&gt;</tt>
<p>Inherits <a href="ntqobject.html">TQObject</a>.
<p><a href="qtranslator-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li class=fn><a href="#TQTranslator"><b>TQTranslator</b></a> ( TQObject&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0 )</li>
<li class=fn><a href="#~TQTranslator"><b>~TQTranslator</b></a> ()</li>
<li class=fn>TQString 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></li>
<li class=fn>virtual TQTranslatorMessage <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 = 0 ) const</li>
<li class=fn>bool <a href="#load"><b>load</b></a> ( const&nbsp;TQString&nbsp;&amp;&nbsp;filename, const&nbsp;TQString&nbsp;&amp;&nbsp;directory = TQString::null, const&nbsp;TQString&nbsp;&amp;&nbsp;search_delimiters = TQString::null, const&nbsp;TQString&nbsp;&amp;&nbsp;suffix = TQString::null )</li>
<li class=fn>bool <a href="#load-2"><b>load</b></a> ( const&nbsp;uchar&nbsp;*&nbsp;data, int&nbsp;len )</li>
<li class=fn>void <a href="#clear"><b>clear</b></a> ()</li>
<li class=fn>enum <a href="#SaveMode-enum"><b>SaveMode</b></a> { Everything, Stripped }</li>
<li class=fn>bool <a href="#save"><b>save</b></a> ( const&nbsp;TQString&nbsp;&amp;&nbsp;filename, SaveMode&nbsp;mode = Everything )</li>
<li class=fn>void <a href="#insert"><b>insert</b></a> ( const&nbsp;TQTranslatorMessage&nbsp;&amp;&nbsp;message )</li>
<li class=fn>void insert ( const&nbsp;char&nbsp;*&nbsp;context, const&nbsp;char&nbsp;*&nbsp;sourceText, const&nbsp;TQString&nbsp;&amp;&nbsp;translation ) &nbsp;<em>(obsolete)</em></li>
<li class=fn>void <a href="#remove"><b>remove</b></a> ( const&nbsp;TQTranslatorMessage&nbsp;&amp;&nbsp;message )</li>
<li class=fn>void remove ( const&nbsp;char&nbsp;*&nbsp;context, const&nbsp;char&nbsp;*&nbsp;sourceText ) &nbsp;<em>(obsolete)</em></li>
<li 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</li>
<li class=fn>void <a href="#squeeze"><b>squeeze</b></a> ( SaveMode&nbsp;mode = Everything )</li>
<li class=fn>void <a href="#unsqueeze"><b>unsqueeze</b></a> ()</li>
<li class=fn>TQValueList&lt;TQTranslatorMessage&gt; <a href="#messages"><b>messages</b></a> () const</li>
<li class=fn>bool <a href="#isEmpty"><b>isEmpty</b></a> () const</li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>
<p> The TQTranslator 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">TQTranslatorMessage</a>
objects, each of which specifies a translation from a source
language to a target language. TQTranslator provides functions to
look up translations, add new ones, remove them, load and save
them, etc.
<p> The most common use of TQTranslator is to: load a translator file
created with <a href="linguist-manual.html">TQt Linguist</a>,
install it using <a href="ntqapplication.html#installTranslator">TQApplication::installTranslator</a>(), and use it via
<a href="ntqobject.html#tr">TQObject::tr</a>(). For example:
<p> <pre>
int main( int argc, char ** argv )
{
<a href="ntqapplication.html">TQApplication</a> app( argc, argv );
TQTranslator translator( 0 );
translator.<a href="#load">load</a>( "french.qm", "." );
app.<a href="ntqapplication.html#installTranslator">installTranslator</a>( &amp;translator );
MyWidget m;
app.<a href="ntqapplication.html#setMainWidget">setMainWidget</a>( &amp;m );
m.show();
return app.<a href="ntqapplication.html#exec">exec</a>();
}
</pre>
Note that the translator must be created <em>before</em> the
application's main window.
<p> Most applications will never need to do anything else with this
class. The other functions provided by this class are useful for
applications that work on translator files.
<p> We call a translation a "messsage". For this reason, translation
files are sometimes referred to as "message files".
<p> It is possible to lookup a translation using <a href="#findMessage">findMessage</a>() (as
<a href="ntqobject.html#tr">tr</a>() and <a href="ntqapplication.html#translate">TQApplication::translate</a>() do) and <a href="#contains">contains</a>(), to insert a
new translation messsage using <a href="#insert">insert</a>(), and to remove one using
<a href="#remove">remove</a>().
<p> Translation tools often need more information than the bare source
text and translation, for example, context information to help
the translator. But end-user programs that are using translations
usually only need lookup. To cater for these different needs,
TQTranslator can use stripped translator files that use the minimum
of memory and which support little more functionality 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 <a href="ntqobject.html#tr">tr</a>().
<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 tr() 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 TQt to distinguish between
translations.
<p> Note that when TQTranslator 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">TQTranslatorMessage</a>, <a href="ntqapplication.html#installTranslator">TQApplication::installTranslator</a>(), <a href="ntqapplication.html#removeTranslator">TQApplication::removeTranslator</a>(), <a href="ntqobject.html#tr">TQObject::tr</a>(), <a href="ntqapplication.html#translate">TQApplication::translate</a>(), <a href="environment.html">Environment Classes</a>, and <a href="i18n.html">Internationalization with TQt</a>.
<hr><h2>Member Type Documentation</h2>
<h3 class=fn><a name="SaveMode-enum"></a>TQTranslator::SaveMode</h3>
<p> This enum type defines how TQTranslator writes translation
files. There are two modes:
<ul>
<li><tt>TQTranslator::Everything</tt> - files are saved with all available information
<li><tt>TQTranslator::Stripped</tt> - files are saved with just enough information for
end-user applications
</ul><p> Note that when TQTranslator 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="TQTranslator"></a>TQTranslator::TQTranslator ( <a href="ntqobject.html">TQObject</a>&nbsp;*&nbsp;parent = 0, const&nbsp;char&nbsp;*&nbsp;name = 0 )
</h3>
Constructs an empty message file object that is not connected to
any file. The object is called <em>name</em> with parent <em>parent</em>.
<h3 class=fn><a name="~TQTranslator"></a>TQTranslator::~TQTranslator ()
</h3>
Destroys the object and frees any allocated resources.
<h3 class=fn>void <a name="clear"></a>TQTranslator::clear ()
</h3>
Empties this translator of all contents.
<p> This function works with stripped translator files.
<h3 class=fn>bool <a name="contains"></a>TQTranslator::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="#findMessage">findMessage</a>().)
<h3 class=fn><a href="ntqstring.html">TQString</a> <a name="find"></a>TQTranslator::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="ntqstring.html#TQString-null">TQString::null</a> if there is none in this translator.
<h3 class=fn><a href="qtranslatormessage.html">TQTranslatorMessage</a> <a name="findMessage"></a>TQTranslator::findMessage ( const&nbsp;char&nbsp;*&nbsp;context, const&nbsp;char&nbsp;*&nbsp;sourceText, const&nbsp;char&nbsp;*&nbsp;comment = 0 ) const<tt> [virtual]</tt>
</h3> Returns the <a href="qtranslatormessage.html">TQTranslatorMessage</a> for the key
(<em>context</em>, <em>sourceText</em>, <em>comment</em>). If none is found,
also tries (<em>context</em>, <em>sourceText</em>, "").
<h3 class=fn>void <a name="insert"></a>TQTranslator::insert ( const&nbsp;<a href="qtranslatormessage.html">TQTranslatorMessage</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 appear to, but that is not dependable.
<p> <p>See also <a href="#remove">remove</a>().
<h3 class=fn>void <a name="insert-2"></a>TQTranslator::insert ( const&nbsp;char&nbsp;*&nbsp;context, const&nbsp;char&nbsp;*&nbsp;sourceText, const&nbsp;<a href="ntqstring.html">TQString</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="isEmpty"></a>TQTranslator::isEmpty () const
</h3>
Returns TRUE if this translator is empty, otherwise returns FALSE.
This function works with stripped and unstripped translation files.
<h3 class=fn>bool <a name="load"></a>TQTranslator::load ( const&nbsp;<a href="ntqstring.html">TQString</a>&nbsp;&amp;&nbsp;filename, const&nbsp;<a href="ntqstring.html">TQString</a>&nbsp;&amp;&nbsp;directory = TQString::null, const&nbsp;<a href="ntqstring.html">TQString</a>&nbsp;&amp;&nbsp;search_delimiters = TQString::null, const&nbsp;<a href="ntqstring.html">TQString</a>&nbsp;&amp;&nbsp;suffix = TQString::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. Returns TRUE if the file is loaded successfully;
otherwise returns FALSE.
<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 <em>suffix</em> is
<a href="ntqstring.html#TQString-null">TQString::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
TQString::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"). load() would then try to open the first existing
readable file from this list:
<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#x1950">i18n/main.cpp</a>.
<h3 class=fn>bool <a name="load-2"></a>TQTranslator::load ( const&nbsp;uchar&nbsp;*&nbsp;data, int&nbsp;len )
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p>
<p> Loads the .qm file data <em>data</em> of length <em>len</em> into the
translator. Returns TRUE if the data is loaded successfully;
otherwise returns FALSE.
<p> The data is not copied. The caller must be able to guarantee that <em>data</em>
will not be deleted or modified.
<h3 class=fn><a href="ntqvaluelist.html">TQValueList</a>&lt;TQTranslatorMessage&gt; <a name="messages"></a>TQTranslator::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, rather than speed.
<p> If you want to iterate over the list, you should iterate over a
copy, e.g.
<pre>
<a href="ntqvaluelist.html">TQValueList</a>&lt;TQTranslatorMessage&gt; list = myTranslator.messages();
TQValueList&lt;TQTranslatorMessage&gt;::Iterator it = list.<a href="ntqvaluelist.html#begin">begin</a>();
while ( it != list.<a href="ntqvaluelist.html#end">end</a>() ) {
process_message( *it );
++it;
}
</pre>
<h3 class=fn>void <a name="remove"></a>TQTranslator::remove ( const&nbsp;<a href="qtranslatormessage.html">TQTranslatorMessage</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>TQTranslator::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>TQTranslator::save ( const&nbsp;<a href="ntqstring.html">TQString</a>&nbsp;&amp;&nbsp;filename, <a href="ntqtranslator.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>TQTranslator::squeeze ( <a href="ntqtranslator.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>TQTranslator::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">TQt toolkit</a>.
Copyright &copy; 1995-2007
<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; 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>TQt 3.3.8</div>
</table></div></address></body>
</html>