6
6
td.postheader { font-family: sans-serif }
7
7
tr.address { font-family: sans-serif }
8
8
body { background: #ffffff; color: black; }
9
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">  </td><td class="postheader" valign="center"><a href="../pyqt4ref.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QTranslator Class Reference<br /><sup><sup>[<a href="qtcore.html">QtCore</a> module]</sup></sup></h1><p>The QTranslator class provides internationalization support for text output. <a href="#details">More...</a></p>
10
<p>Inherits <a href="qobject.html">QObject</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qtranslator.html#QTranslator">__init__</a></b> (<i>self</i>, QObject <i>parent</i> = None)</li><li><div class="fn" />bool <b><a href="qtranslator.html#isEmpty">isEmpty</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qtranslator.html#load">load</a></b> (<i>self</i>, QString <i>fileName</i>, QString <i>directory</i> = QString(), QString <i>searchDelimiters</i> = QString(), QString <i>suffix</i> = QString())</li><li><div class="fn" />bool <b><a href="qtranslator.html#loadFromData">loadFromData</a></b> (<i>self</i>, str)</li><li><div class="fn" />QString <b><a href="qtranslator.html#translate">translate</a></b> (<i>self</i>, str, str, str <i>disambiguation</i> = None)</li><li><div class="fn" />QString <b><a href="qtranslator.html#translate-2">translate</a></b> (<i>self</i>, str, str, str, int)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QTranslator class provides internationalization support for text output.</p>
11
<p>An object of this class contains a set of translations from a source language to a target language. QTranslator provides functions to look up translations in a translation file. Translation files are created using <a href="linguist-manual.html#qt-linguist">Qt Linguist</a>.</p>
12
<p>The most common use of QTranslator is to: load a translation file, install it using <a href="qcoreapplication.html#installTranslator">QApplication.installTranslator</a>(), and use it via <a href="qobject.html#tr">QObject.tr</a>(). Here's the <tt>main()</tt> function from the <a href="linguist-hellotr.html">Hello tr()</a> example:</p>
13
<pre> int main(int argc, char *argv[])
9
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">  </td><td class="postheader" valign="center"><a href="../pyqt4ref.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QTranslator Class Reference<br /><sup><sup>[<a href="qtcore.html">QtCore</a> module]</sup></sup></h1><p>The QTranslator class provides internationalization support for
10
text output. <a href="#details">More...</a></p>
12
<p>Inherits <a href="qobject.html">QObject</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qtranslator.html#QTranslator">__init__</a></b> (<i>self</i>, QObject <i>parent</i> = None)</li><li><div class="fn" />bool <b><a href="qtranslator.html#isEmpty">isEmpty</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qtranslator.html#load">load</a></b> (<i>self</i>, QString <i>fileName</i>, QString <i>directory</i> = QString(), QString <i>searchDelimiters</i> = QString(), QString <i>suffix</i> = QString())</li><li><div class="fn" />bool <b><a href="qtranslator.html#loadFromData">loadFromData</a></b> (<i>self</i>, str)</li><li><div class="fn" />QString <b><a href="qtranslator.html#translate">translate</a></b> (<i>self</i>, str, str, str <i>disambiguation</i> = None)</li><li><div class="fn" />QString <b><a href="qtranslator.html#translate-2">translate</a></b> (<i>self</i>, str, str, str, int)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QTranslator class provides internationalization support for
14
<p>An object of this class contains a set of translations from a
15
source language to a target language. QTranslator provides
16
functions to look up translations in a translation file.
17
Translation files are created using <a href="linguist-manual.html#qt-linguist">Qt Linguist</a>.</p>
18
<p>The most common use of QTranslator is to: load a translation
19
file, install it using <a href="qcoreapplication.html#installTranslator">QApplication.installTranslator</a>(),
20
and use it via <a href="qobject.html#tr">QObject.tr</a>(). Here's
21
the <tt>main()</tt> function from the <a href="linguist-hellotr.html">Hello tr()</a> example:</p>
22
<pre class="highlightedCode brush: cpp">
23
int main(int argc, char *argv[])
15
25
QApplication app(argc, argv);
27
<p>Note that the translator must be created <i>before</i> the application's widgets.</p>
28
<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>
29
<a name="looking-up-translations" />
38
<p>Note that the translator must be created <i>before</i> the
39
application's widgets.</p>
40
<p>Most applications will never need to do anything else with this
41
class. The other functions provided by this class are useful for
42
applications that work on translator files.</p>
43
<a id="looking-up-translations" name="looking-up-translations" />
30
44
<h3>Looking up Translations</h3>
31
<p>It is possible to look up a translation using <a href="qtranslator.html#translate">translate</a>() (as <a href="qobject.html#tr">tr</a>() and <a href="qcoreapplication.html#translate">QApplication.translate</a>() do). The <a href="qtranslator.html#translate">translate</a>() function takes up to three parameters:</p>
45
<p>It is possible to look up a translation using <a href="qtranslator.html#translate">translate</a>() (as <a href="qobject.html#tr">tr</a>() and <a href="qcoreapplication.html#translate">QApplication.translate</a>()
46
do). The <a href="qtranslator.html#translate">translate</a>()
47
function takes up to three parameters:</p>
33
49
<li>The <i>context</i> - usually the class name for the <a href="qobject.html#tr">tr</a>() caller.</li>
34
50
<li>The <i>source text</i> - usually the argument to <a href="qobject.html#tr">tr</a>().</li>
35
<li>The <i>disambiguation</i> - an optional string that helps disambiguate different uses of the same text in the same context.</li>
51
<li>The <i>disambiguation</i> - an optional string that helps
52
disambiguate different uses of the same text in the same
37
<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>
38
<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 disambiguations such as "two-sided printing" for one and "binding" for the other. The disambiguation enables the translator to choose the appropriate gender for the Spanish version, and enables Qt to distinguish between translations.</p>
39
<a name="using-multiple-translations" />
55
<p>For example, the "Cancel" in a dialog might have "Anuluj" when
56
the program runs in Polish (in this case the source text would be
57
"Cancel"). The context would (normally) be the dialog's class name;
58
there would normally be no comment, and the translated text would
60
<p>But it's not always so simple. The Spanish version of a printer
61
dialog with settings for two-sided printing and binding would
62
probably require both "Activado" and "Activada" as translations for
63
"Enabled". In this case the source text would be "Enabled" in both
64
cases, and the context would be the dialog's class name, but the
65
two items would have disambiguations such as "two-sided printing"
66
for one and "binding" for the other. The disambiguation enables the
67
translator to choose the appropriate gender for the Spanish
68
version, and enables Qt to distinguish between translations.</p>
69
<a id="using-multiple-translations" name="using-multiple-translations" />
40
70
<h3>Using Multiple Translations</h3>
41
<p>Multiple translation files can be installed in an application. Translations are searched for in the reverse order in which they were installed, so the most recently installed translation file is searched for translations first and the earliest translation file is searched last. The search stops as soon as a translation containing a matching string is found.</p>
42
<p>This mechanism makes it possible for a specific translation to be "selected" or given priority over the others; simply uninstall the translator from the application by passing it to the <a href="qcoreapplication.html#removeTranslator">QApplication.removeTranslator</a>() function and reinstall it with <a href="qcoreapplication.html#installTranslator">QApplication.installTranslator</a>(). It will then be the first translation to be searched for matching strings.</p>
43
<p>See also <a href="qcoreapplication.html#installTranslator">QApplication.installTranslator</a>(), <a href="qcoreapplication.html#removeTranslator">QApplication.removeTranslator</a>(), <a href="qobject.html#tr">QObject.tr</a>(), <a href="qcoreapplication.html#translate">QApplication.translate</a>(), <a href="tools-i18n.html">I18N Example</a>, <a href="linguist-hellotr.html">Hello tr</a>() Example, <a href="linguist-arrowpad.html">Arrow Pad Example</a>, and <a href="linguist-trollprint.html">Troll Print Example</a>.</p>
44
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QTranslator" />QTranslator.__init__ (<i>self</i>, <a href="qobject.html">QObject</a> <i>parent</i> = None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs an empty message file object with parent <i>parent</i> that is not connected to any file.</p>
45
<a name="//apple_ref/cpp/instm/QTranslator/~QTranslator" />
46
<h3 class="fn"><a name="isEmpty" />bool QTranslator.isEmpty (<i>self</i>)</h3><p>Returns true if this translator is empty, otherwise returns false. This function works with stripped and unstripped translation files.</p>
47
<a name="//apple_ref/cpp/instm/QTranslator/load" />
48
<h3 class="fn"><a name="load" />bool QTranslator.load (<i>self</i>, QString <i>fileName</i>, QString <i>directory</i> = QString(), QString <i>searchDelimiters</i> = QString(), QString <i>suffix</i> = QString())</h3><p>Loads <i>filename</i> + <i>suffix</i> (".qm" if the <i>suffix</i> is not specified), which may be an absolute file name or relative to <i>directory</i>. Returns true if the translation is successfully loaded; otherwise returns false.</p>
49
<p>The previous contents of this translator object are discarded.</p>
50
<p>If the file name does not exist, other file names are tried in the following order:</p>
71
<p>Multiple translation files can be installed in an application.
72
Translations are searched for in the reverse order in which they
73
were installed, so the most recently installed translation file is
74
searched for translations first and the earliest translation file
75
is searched last. The search stops as soon as a translation
76
containing a matching string is found.</p>
77
<p>This mechanism makes it possible for a specific translation to
78
be "selected" or given priority over the others; simply uninstall
79
the translator from the application by passing it to the <a href="qcoreapplication.html#removeTranslator">QApplication.removeTranslator</a>()
80
function and reinstall it with <a href="qcoreapplication.html#installTranslator">QApplication.installTranslator</a>().
81
It will then be the first translation to be searched for matching
83
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QTranslator" />QTranslator.__init__ (<i>self</i>, <a href="qobject.html">QObject</a> <i>parent</i> = None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs an empty message file object with parent
84
<i>parent</i> that is not connected to any file.</p>
87
<h3 class="fn"><a name="isEmpty" />bool QTranslator.isEmpty (<i>self</i>)</h3><p>Returns true if this translator is empty, otherwise returns
88
false. This function works with stripped and unstripped translation
92
<h3 class="fn"><a name="load" />bool QTranslator.load (<i>self</i>, QString <i>fileName</i>, QString <i>directory</i> = QString(), QString <i>searchDelimiters</i> = QString(), QString <i>suffix</i> = QString())</h3><p>Loads <i>filename</i> + <i>suffix</i> (".qm" if the
93
<i>suffix</i> is not specified), which may be an absolute file name
94
or relative to <i>directory</i>. Returns true if the translation is
95
successfully loaded; otherwise returns false.</p>
96
<p>The previous contents of this translator object are
98
<p>If the file name does not exist, other file names are tried in
99
the following order:</p>
52
101
<li>File name without <i>suffix</i> appended.</li>
53
<li>File name with text after a character in <i>search_delimiters</i> stripped ("<a href="examples-overview.html">_</a>." is the default for <i>search_delimiters</i> if it is an empty string) and <i>suffix</i>.</li>
102
<li>File name with text after a character in
103
<i>search_delimiters</i> stripped ("<a href="index.html">_</a>." is
104
the default for <i>search_delimiters</i> if it is an empty string)
105
and <i>suffix</i>.</li>
54
106
<li>File name stripped without <i>suffix</i> appended.</li>
55
107
<li>File name stripped further, etc.</li>
57
<p>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:</p>
109
<p>For example, an application running in the fr_CA locale
110
(French-speaking Canada) might call load("foo.fr_ca",
111
"/opt/foolib"). load() would then try to open the first existing
112
readable file from this list:</p>
59
114
<li><tt>/opt/foolib/foo.fr_ca.qm</tt></li>
60
115
<li><tt>/opt/foolib/foo.fr_ca</tt></li>
63
118
<li><tt>/opt/foolib/foo.qm</tt></li>
64
119
<li><tt>/opt/foolib/foo</tt></li>
66
<h3 class="fn"><a name="loadFromData" />bool QTranslator.loadFromData (<i>self</i>, str)</h3><h3 class="fn"><a name="translate" />QString QTranslator.translate (<i>self</i>, str, str, str <i>disambiguation</i> = None)</h3><p>Returns the translation for the key (<i>context</i>, <i>sourceText</i>, <i>disambiguation</i>). If none is found, also tries (<i>context</i>, <i>sourceText</i>, ""). If that still fails, returns an empty string.</p>
67
<p>If you need to programatically insert translations in to a <a href="qtranslator.html">QTranslator</a>, this function can be reimplemented.</p>
123
<h3 class="fn"><a name="loadFromData" />bool QTranslator.loadFromData (<i>self</i>, str)</h3><h3 class="fn"><a name="translate" />QString QTranslator.translate (<i>self</i>, str, str, str <i>disambiguation</i> = None)</h3><p>Returns the translation for the key (<i>context</i>,
124
<i>sourceText</i>, <i>disambiguation</i>). If none is found, also
125
tries (<i>context</i>, <i>sourceText</i>, ""). If that still fails,
126
returns an empty string.</p>
127
<p>If you need to programatically insert translations in to a
128
<a href="qtranslator.html">QTranslator</a>, this function can be
68
130
<p>See also <a href="qtranslator.html#load">load</a>().</p>
69
133
<h3 class="fn"><a name="translate-2" />QString QTranslator.translate (<i>self</i>, str, str, str, int)</h3><p>This function overloads <a href="qtranslator.html#translate">translate</a>().</p>
70
<p>Returns the translation for the key (<i>context</i>, <i>sourceText</i>, <i>disambiguation</i>). If none is found, also tries (<i>context</i>, <i>sourceText</i>, ""). If that still fails, returns an empty string.</p>
71
<p>If <i>n</i> is not -1, it is used to choose an appropriate form for the translation (e.g. "%n file found" vs. "%n files found").</p>
134
<p>Returns the translation for the key (<i>context</i>,
135
<i>sourceText</i>, <i>disambiguation</i>). If none is found, also
136
tries (<i>context</i>, <i>sourceText</i>, ""). If that still fails,
137
returns an empty string.</p>
138
<p>If <i>n</i> is not -1, it is used to choose an appropriate form
139
for the translation (e.g. "%n file found" vs. "%n files
72
141
<p>See also <a href="qtranslator.html#load">load</a>().</p>
73
<p /><address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.7.7 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2010</td><td align="right" width="25%">Qt 4.6.3</td></tr></table></div></address></body></html>
b'\\ No newline at end of file'
142
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.8.1 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2010</td><td align="right" width="25%">Qt 4.7.0</td></tr></table></div></address></body></html>
b'\\ No newline at end of file'