summaryrefslogtreecommitdiffstats
path: root/doc/man/man3/tqtranslator.3qt
blob: 9b1aec2477a62cecb8e2f8c9394230cdea100da2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
'\" t
.TH QTranslator 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*-
.\" Copyright 1992-2007 Trolltech ASA.  All rights reserved.  See the
.\" license file included in the distribution for a complete license
.\" statement.
.\"
.ad l
.nh
.SH NAME
QTranslator \- 
.SH SYNOPSIS
\fC#include <ntqtranslator.h>\fR
.PP
Inherits QObject.
.PP
.SS "Public Members"
.in +1c
.ti -1c
.BI "\fBQTranslator\fR ( QObject * parent = 0, const char * name = 0 )"
.br
.ti -1c
.BI "\fB~QTranslator\fR ()"
.br
.ti -1c
.BI "QString find ( const char * context, const char * sourceText, const char * comment = 0 ) const  \fI(obsolete)\fR"
.br
.ti -1c
.BI "virtual QTranslatorMessage \fBfindMessage\fR ( const char * context, const char * sourceText, const char * comment = 0 ) 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 "bool \fBload\fR ( const uchar * data, int len )"
.br
.ti -1c
.BI "void \fBclear\fR ()"
.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 \fBinsert\fR ( const QTranslatorMessage & message )"
.br
.ti -1c
.BI "void insert ( const char * context, const char * sourceText, const QString & translation )  \fI(obsolete)\fR"
.br
.ti -1c
.BI "void \fBremove\fR ( const QTranslatorMessage & message )"
.br
.ti -1c
.BI "void remove ( const char * context, const char * sourceText )  \fI(obsolete)\fR"
.br
.ti -1c
.BI "bool \fBcontains\fR ( const char * context, const char * sourceText, const char * comment = 0 ) const"
.br
.ti -1c
.BI "void \fBsqueeze\fR ( SaveMode mode = Everything )"
.br
.ti -1c
.BI "void \fBunsqueeze\fR ()"
.br
.ti -1c
.BI "QValueList<QTranslatorMessage> \fBmessages\fR () const"
.br
.ti -1c
.BI "bool \fBisEmpty\fR () const"
.br
.in -1c
.SH DESCRIPTION
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.
.PP
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 QObject::tr(). For example:
.PP
.nf
.br
    int main( int argc, char ** argv )
.br
    {
.br
        QApplication app( argc, argv );
.br
.br
        QTranslator translator( 0 );
.br
        translator.load( "french.qm", "." );
.br
        app.installTranslator( &translator );
.br
.br
        MyWidget m;
.br
        app.setMainWidget( &m );
.br
        m.show();
.br
.br
        return app.exec();
.br
    }
.br
.fi
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".
.PP
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.
.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.
.PP
See also QTranslatorMessage, QApplication::installTranslator(), QApplication::removeTranslator(), QObject::tr(), QApplication::translate(), Environment Classes, and Internationalization with Qt.
.SS "Member Type Documentation"
.SH "QTranslator::SaveMode"
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.
.SH MEMBER FUNCTION DOCUMENTATION
.SH "QTranslator::QTranslator ( QObject * parent = 0, const char * name = 0 )"
Constructs an empty message file object that is not connected to any file. The object is called \fIname\fR with parent \fIparent\fR.
.SH "QTranslator::~QTranslator ()"
Destroys the object and frees any allocated resources.
.SH "void QTranslator::clear ()"
Empties this translator of all contents.
.PP
This function works with stripped translator files.
.SH "bool QTranslator::contains ( const char * context, const char * sourceText, const char * comment = 0 ) const"
Returns TRUE if this message file contains a message with the key (\fIcontext\fR, \fIsourceText\fR, \fIcomment\fR); otherwise returns FALSE.
.PP
This function works with stripped translator files.
.PP
(This is is a one-liner that calls findMessage().)
.SH "QString QTranslator::find ( const char * context, const char * sourceText, const char * comment = 0 ) const"
\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code.
.PP
Please use findMessage() instead.
.PP
Returns the translation for the key (\fIcontext\fR, \fIsourceText\fR, \fIcomment\fR) or QString::null if there is none in this translator.
.SH "QTranslatorMessage QTranslator::findMessage ( const char * context, const char * sourceText, const char * comment = 0 ) const\fC [virtual]\fR"
Returns the QTranslatorMessage for the key (\fIcontext\fR, \fIsourceText\fR, \fIcomment\fR). If none is found, also tries (\fIcontext\fR, \fIsourceText\fR, "").
.SH "void QTranslator::insert ( const QTranslatorMessage & message )"
Inserts \fImessage\fR into this message file.
.PP
This function does \fInot\fR work with stripped translator files. It may appear to, but that is not dependable.
.PP
See also remove().
.SH "void QTranslator::insert ( const char * context, const char * sourceText, const QString & translation )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code.
.SH "bool QTranslator::isEmpty () const"
Returns TRUE if this translator is empty, otherwise returns FALSE. This function works with stripped and unstripped translation files.
.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. 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:
.PP
<ol type=1>
.TP
File name with \fIsuffix\fR appended (".qm" if the \fIsuffix\fR is QString::null).
.TP
File name with text after a character in \fIsearch_delimiters\fR stripped ("_." is the default for \fIsearch_delimiters\fR if it is QString::null).
.TP
File name stripped and \fIsuffix\fR appended.
.TP
File name stripped further, etc.
.PP
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.
.SH "QValueList<QTranslatorMessage> QTranslator::messages () const"
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.
.PP
.nf
.br
    QValueList<QTranslatorMessage> list = myTranslator.messages();
.br
    QValueList<QTranslatorMessage>::Iterator it = list.begin();
.br
    while ( it != list.end() ) {
.br
        process_message( *it );
.br
        ++it;
.br
    }
.br
.fi
.SH "void QTranslator::remove ( const QTranslatorMessage & message )"
Removes \fImessage\fR from this translator.
.PP
This function works with stripped translator files.
.PP
See also insert().
.SH "void QTranslator::remove ( const char * context, const char * sourceText )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code.
.PP
Removes the translation associated to the key (\fIcontext\fR, \fIsourceText\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 Everything (the default), all the information is preserved. If \fImode\fR is Stripped, any information that is not necessary for findMessage() is stripped away.
.PP
See also load().
.SH "void QTranslator::squeeze ( SaveMode mode = Everything )"
Converts this message file to the compact format used to store message files on disk.
.PP
You should never need to call this directly; save() and other functions call it as necessary. \fImode\fR is for internal use.
.PP
See also save() and unsqueeze().
.SH "void QTranslator::unsqueeze ()"
Converts this message file into an easily modifiable data structure, less compact than the format used in the files.
.PP
You should never need to call this function; it is called by insert() and friends as necessary.
.PP
See also squeeze().

.SH "SEE ALSO"
.BR http://doc.trolltech.com/ntqtranslator.html
.BR http://www.trolltech.com/faq/tech.html
.SH COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com.  See the
license file included in the distribution for a complete license
statement.
.SH AUTHOR
Generated automatically from the source code.
.SH BUGS
If you find a bug in Qt, please report it as described in
.BR http://doc.trolltech.com/bughowto.html .
Good bug reports help us to help you. Thank you.
.P
The definitive TQt documentation is provided in HTML format; it is
located at $TQTDIR/doc/html and can be read using TQt Assistant or with
a web browser. This man page is provided as a convenience for those
users who prefer man pages, although this format is not officially
supported by Trolltech. 
.P
If you find errors in this manual page, please report them to
.BR qt-bugs@trolltech.com .
Please include the name of the manual page (tqtranslator.3qt) and the Qt
version (3.3.8).