The QTranslator class provides internationalization support for text output.
.PP
An object of this class contains a set of QTranslatorMessage objects, each of which specifies a translation from a source language to a target language. QTranslator provides functions to look up translations, add new ones, remove them, load and save them, etc.
The most common use of QTranslator is to: load a translator file created with TQt Linguist, install it using QApplication::installTranslator(), and use it via TQObject::tr(). For example:
Note that the translator must be created \fIbefore\fR the application's main window.
.PP
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.
.PP
We call a translation a "messsage". For this reason, translation files are sometimes referred to as "message files".
.PP
It is possible to lookup a translation using findMessage() (as tr() and QApplication::translate() do) and contains(), to insert a new translation messsage using insert(), and to remove one using remove().
.PP
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, QTranslator can use stripped translator files that use the minimum of memory and which support little more functionality than findMessage().
.PP
Thus, load() may not load enough information to make anything more than findMessage() work. save() has an argument indicating whether to save just this minimum of information or to save everything.
.PP"
Everything" means that for each translation item the following information is kept:
.TP
The \fItranslated text\fR - the return value from tr().
.TP
The input key:
.TP
The \fIsource text\fR - usually the argument to tr().
.TP
The \fIcontext\fR - usually the class name for the tr() caller.
.TP
The \fIcomment\fR - a comment that helps disambiguate different uses of the same text in the same context.
.PP
The minimum for each item is just the information necessary for findMessage() 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.
.PP
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".
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.
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.
See also QTranslatorMessage, QApplication::installTranslator(), QApplication::removeTranslator(), TQObject::tr(), QApplication::translate(), Environment Classes, and Internationalization with Qt.
This enum type defines how QTranslator writes translation files. There are two modes:
.TP
\fCQTranslator::Everything\fR - files are saved with all available information
.TP
\fCQTranslator::Stripped\fR - files are saved with just enough information for end-user applications
.PP
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.
Returns the QTranslatorMessage for the key (\fIcontext\fR, \fIsourceText\fR, \fIcomment\fR). If none is found, also tries (\fIcontext\fR, \fIsourceText\fR, "").
Loads \fIfilename\fR, which may be an absolute file name or relative to \fIdirectory\fR. The previous contents of this translator object is discarded. Returns TRUE if the file is loaded successfully; otherwise returns FALSE.
.PP
If the full file name does not exist, other file names are tried in the following order:
For example, an application running in the fr_CA locale (French-speaking Canada) might call load("foo.fr_ca"," /opt/foolib"). load() would then try to open the first existing readable file from this list:
.PP
<ol type=1>
.TP
/opt/foolib/foo.fr_ca
.TP
/opt/foolib/foo.fr_ca.qm
.TP
/opt/foolib/foo.fr
.TP
/opt/foolib/foo.fr.qm
.TP
/opt/foolib/foo
.TP
/opt/foolib/foo.qm
.PP
See also save().
.PP
Example: i18n/main.cpp.
.SH "bool QTranslator::load ( const uchar * data, int len )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Loads the .qm file data \fIdata\fR of length \fIlen\fR into the translator. Returns TRUE if the data is loaded successfully; otherwise returns FALSE.
.PP
The data is not copied. The caller must be able to guarantee that \fIdata\fR will not be deleted or modified.
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.
.PP
If you want to iterate over the list, you should iterate over a copy, e.g.
Saves this message file to \fIfilename\fR, overwriting the previous contents of \fIfilename\fR. If \fImode\fR is Everything (the default), all the information is preserved. If \fImode\fR is Stripped, any information that is not necessary for findMessage() is stripped away.