Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |
The QTranslator class provides internationalization support for text output. More...
#include <qtranslator.h>
Inherits QObject.
The QTranslator class provides internationalization support for text output.
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 such translations, add new ones, remove them, load and save them, etc.
The most common use of QTranslator is expected to be loading a translator file made using Qt Linguist, installing it using QApplication::installTranslator(), and using it via QObject::tr(), like this:
int main( int argc, char ** argv ) { QApplication app( argc, argv ); QTranslator translator( 0 ); translator.load( "french.qm", "." ); app.installTranslator( &translator ); MyWidget m; app.setMainWidget( &m ); m.show(); return app.exec(); }
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.
It is possible to do lookup using findMessage() (as tr() and QApplication::translate() do) and contains(), insert a new translation message using insert(), and remove it using remove().
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().
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.
"Everything" means that for each translation item the following information is kept:
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.
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 Qt 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(), QObject::tr(), QApplication::translate(), Environment Classes and Internationalization with Qt.
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.
This function works with stripped translator files.
This function works with stripped translator files.
(This is is a one-liner that calls find().)
Please use findMessage() instead.
Returns the translation for the key (context, sourceText, comment) or QString::null if there is none in this translator.
This function does not work with stripped translator files. It may seem to, but that is not dependable.
See also remove().
This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.
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"), which would then try to open these files:
See also save().
Example: i18n/main.cpp.
Note that if you want to iterate over the list, you should iterate over a copy, e.g.
QValueList<QTranslatorMessage> list = myTranslator.messages(); QValueList<QTranslatorMessage>::Iterator it = list.begin(); while( it != list.end() ) { myProcessing( *it ); ++it; }
This function works with stripped translator files.
See also insert().
This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.
Removes the translation associated to the key (context, sourceText, "") from this translator.
See also load().
You should never need to call this directly; save() and other functions call it as necessary. mode is for internal use.
See also save() and unsqueeze().
You should never need to call this function; it is called by insert() and friends as necessary.
See also squeeze().
This file is part of the Qt toolkit. Copyright © 1995-2002 Trolltech. All Rights Reserved.
Copyright © 2002 Trolltech | Trademarks | Qt version 3.0.4
|