📄 qtranslator.3qt
字号:
'\" t.TH QTranslator 3qt "5 August 2004" "Trolltech AS" \" -*- nroff -*-.\" Copyright 1992-2001 Trolltech AS. All rights reserved. See the.\" license file included in the distribution for a complete license.\" statement..\".ad l.nh.SH NAMEQTranslator \- Internationalization support for text output.br.PP\fC#include <qtranslator.h>\fR.PPInherits QObject..PP.SS "Public Members".in +1c.ti -1c.BI "\fBQTranslator\fR ( QObject * " "parent" ", const char * " "name" " = 0 ) ".br.ti -1c.BI "\fB~QTranslator\fR () ".br.ti -1c.BI "QString \fBfind\fR ( const char *, const char *, const char * ) const".br.ti -1c.BI "virtual QString find ( const char *, const char * ) const \fI(obsolete)\fR".br.ti -1c.BI "QTranslatorMessage \fBfindMessage\fR ( const char *, const char *, const char * ) const".br.ti -1c.BI "bool \fBload\fR ( const QString & " "filename" ", const QString & directory = QString::null, const QString & search_delimiters = QString::null, const QString & suffix = QString::null ) ".br.ti -1c.BI "enum \fBSaveMode\fR { Everything, Stripped }".br.ti -1c.BI "bool \fBsave\fR ( const QString & " "filename" ", SaveMode " "mode" " = Everything ) ".br.ti -1c.BI "void \fBclear\fR () ".br.ti -1c.BI "void \fBinsert\fR ( const QTranslatorMessage & ) ".br.ti -1c.BI "void insert ( const char *, const char *, const QString & ) \fI(obsolete)\fR".br.ti -1c.BI "void \fBremove\fR ( const QTranslatorMessage & ) ".br.ti -1c.BI "void remove ( const char *, const char * ) \fI(obsolete)\fR".br.ti -1c.BI "bool \fBcontains\fR ( const char *, const char *, const char * ) const".br.ti -1c.BI "bool contains ( const char *, const char * ) const \fI(obsolete)\fR".br.ti -1c.BI "void \fBsqueeze\fR ( SaveMode ) ".br.ti -1c.BI "void \fBsqueeze\fR () ".br.ti -1c.BI "void \fBunsqueeze\fR () ".br.ti -1c.BI "QValueList<QTranslatorMessage> \fBmessages\fR () const".br.in -1c.SH DESCRIPTIONThe QTranslator class provides internationalization support for text output..PPAn 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, load and save them, etc..PPThe most common use of QTranslator is expected to be loading a translator file, installing it using QApplication::installTranslator(), and using it via QObject::tr(), like this:.PP.nf.br int main( int argc, char ** argv ).br {.br QApplication app( argc, argv );.br.br QTranslator translator( 0 );.br translator.load( "trfile.qm", "." );.br app.installTranslator( &translator );.br.br MyWidget m;.br app.setMainWidget( &m );.br m.show();.br.br return app.exec();.br }.fi.PPMost 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..PPIt is possible to do lookup using findMessage() (as tr() and QApplication::translate() do) and contains(), insert a new translation message using insert() and removing them using remove()..PPSince 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()..PPThus, 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 everything..PPEverything means that for each translation item the following information is kept: .TPThe \fItranslated text\fR - the return value from tr()..TPThe input key: .TPThe \fIsource text\fR - the argument to tr(), normally..TPThe \fIcontext\fR - usually the class name for the tr() caller..TPThe \fIcomment\fR - a comment which helps disambiguate different uses of the same text in the same context..PPThe 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..PPFor 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"..PPBut 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..PPNote 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..PPSee also QTranslatorMessage, QApplication::installTranslator(), QApplication::removeTranslator(), QObject::tr() and QApplication::translate()..PPExamples:.(li18n/main.cpp.)l.SS "Member Type Documentation".SH "QTranslator::SaveMode"This enum type defines how QTranslator can write translation files. There are two modes:.TP\fCEverything\fR - files are saved with all contents.TP\fCStripped\fR - files are saved with just what's needed for end-users.PPNote 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..SH MEMBER FUNCTION DOCUMENTATION.SH "QTranslator::QTranslator ( QObject * parent, const char * name = 0 )"Constructs an empty message file, not connected to any file..SH "QTranslator::~QTranslator ()"Destructs the object and frees any allocated resources..SH "void QTranslator::clear ()"Empties this translator of all contents..PPThis function works with stripped translator files..SH "bool QTranslator::contains ( const char * context, const char * sourceText, const char * comment ) const"Returns TRUE if this message file contains a message with the key ( \fIcontext, sourceText, comment\fR ), and FALSE if it does not..PPThis function works with stripped translator files..PP(This is is a one-liner that calls find().)..SH "bool QTranslator::contains ( const char * context, const char * sourceText ) const"\fBThis function is obsolete.\fR 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..PPThis is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PPThis version of the function assumes that the comment is ""..SH "QString QTranslator::find ( const char * context, const char * sourceText, const char * comment ) const"Returns the translation for the key ( \fIcontext, sourceText, comment\fR ), or QString::null if there is none in this translator..PPThis function works with stripped translator files..PPSee also findMessage..SH "QString QTranslator::find ( const char * context, const char * sourceText ) const \fC[virtual]\fR"\fBThis function is obsolete.\fR 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..PPThis is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PPReturns the translation for the key ( \fIcontext, sourceText,\fR "" ), or QString::null if there is none in this translator..SH "QTranslatorMessage QTranslator::findMessage ( const char * context, const char * sourceText, const char * comment ) const"Returns the QTranslatorMessage for the key ( \fIcontext, sourceText, comment\fR )..SH "void QTranslator::insert ( const QTranslatorMessage & message )"Inserts \fImessage\fR into this message file..PPThis function does \fInot\fR work with stripped translator files. It may seem to, but that is not dependable..PPSee also remove()..SH "void QTranslator::insert ( const char * context, const char * sourceText, const QString & translation )"\fBThis function is obsolete.\fR 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..PPThis is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..SH "bool QTranslator::load ( const QString & filename, const QString & directory = QString::null, const QString & search_delimiters = QString::null, const QString & suffix = QString::null )"Loads \fIfilename,\fR which may be an absolute file name or relative to \fIdirectory.\fR If the full filename does not exist, other filenames are tried in the following order:.IP 1Filename with \fIsuffix\fR appended (".qm" if suffix is QString::null).IP 2Filename with text after a character in \fIsearch_delimiters\fR stripped ("_." is the default for \fIsearch_delimiters\fR if it is QString::null).IP 3Filename stripped and \fIsuffix\fR appended..IP 4Filename stripped further, etc..PPFor 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:.IP 1/opt/foolib/foo.fr_ca.IP 2/opt/foolib/foo.fr_ca.qm.IP 3/opt/foolib/foo.fr.IP 4/opt/foolib/foo.fr.qm.IP 5/opt/foolib/foo.IP 6/opt/foolib/foo.qm.PPSee also save()..SH "QValueList<QTranslatorMessage> QTranslator::messages () const"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..SH "void QTranslator::remove ( const QTranslatorMessage & message )"Removes \fImessage\fR from this translator..PPThis function works with stripped translator files..PPSee also insert()..SH "void QTranslator::remove ( const char * context, const char * sourceText )"\fBThis function is obsolete.\fR 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..PPThis is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PPRemoves the translation associated to the key ( \fIcontext, sourceText,\fR" " ) from this translator..SH "bool QTranslator::save ( const QString & filename, SaveMode mode = Everything )"Saves this message file to \fIfilename,\fR overwriting the previous contents of \fIfilename.\fR If \fImode\fR is \fCEverything\fR (this is the default), all the information is preserved. If \fImode\fR is \fCStripped,\fR all information that is not necessary for findMessage() is stripped away..PPSee also load()..SH "void QTranslator::squeeze ( SaveMode mode )"Converts this message file to the compact format used to store message files on disk..PPYou should never need to call this directly; save() and other functions call it as necessary..PPSee also save() and unsqueeze()..SH "void QTranslator::squeeze ()"This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts..PPThis function calls squeeze( Everything ). It is provided for compatibility; in Qt 3.0 it will be replaced by a default argument..SH "void QTranslator::unsqueeze ()"Converts this message file into an easily modifiable data structure, less compact than the format used in the files..PPYou should never need to call this function; it is called by insert() and friends as necessary..PPSee also squeeze()..SH "SEE ALSO".BR http://doc.trolltech.com/qtranslator.html.BR http://www.trolltech.com/faq/tech.html.SH COPYRIGHTCopyright 1992-2001 Trolltech AS, http://www.trolltech.com. See thelicense file included in the distribution for a complete licensestatement..SH AUTHORGenerated automatically from the source code..SH BUGSIf you find a bug in Qt, please report it as described in.BR http://doc.trolltech.com/bughowto.html .Good bug reports make our job much simpler. Thank you..PIn case of content or formattting problems with this manual page, pleasereport them to.BR qt-bugs@trolltech.com .Please include the name of the manual page (qtranslator.3qt) and the Qtversion (2.3.8).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -