|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.core.QObject
com.trolltech.qt.core.QTranslator
public class QTranslator
The QTranslator
class provides internationalization support for text output. 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 Qt Linguist.
The most common use of QTranslator
is to: load a translation file, install it using QApplication::installTranslator()
, and use it via QObject::tr(). Here's the main() function from the Hello tr() example:
The following code example is written in c++.
int main(int argc, char *argv[]) { QApplication app(argc, argv); QTranslator translator; translator.load("hellotr_la"); app.installTranslator(&translator); QPushButton hello(QPushButton::tr("Hello world!")); hello.resize(100, 30); hello.show(); return app.exec(); }Note that the translator must be created before the application's widgets.
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.
It is possible to lookup a translation using translate()
(as tr() and QApplication::translate()
do). The translate()
function takes up to three parameters:
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.
QApplication::installTranslator()
, QApplication::removeTranslator()
, QObject::tr(), QApplication::translate()
, I18N Example, Hello tr() Example, Arrow Pad Example, and Troll Print Example.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9 |
Constructor Summary | |
---|---|
QTranslator()
Constructs an empty message file object with parent parent that is not connected to any file. |
|
QTranslator(QObject parent)
Constructs an empty message file object with parent parent that is not connected to any file. |
Method Summary | |
---|---|
static QTranslator |
fromNativePointer(QNativePointer nativePointer)
|
boolean |
isEmpty()
Returns true if this translator is empty, otherwise returns false. |
boolean |
load(byte[] data)
Loads the .qm file data data into the translator. |
boolean |
load(java.lang.String filename)
Loads filename + suffix (".qm" if the suffix is not specified), which may be an absolute file name or relative to directory. |
boolean |
load(java.lang.String filename,
java.lang.String directory)
Loads filename + suffix (".qm" if the suffix is not specified), which may be an absolute file name or relative to directory. |
boolean |
load(java.lang.String filename,
java.lang.String directory,
java.lang.String search_delimiters)
Loads filename + suffix (".qm" if the suffix is not specified), which may be an absolute file name or relative to directory. |
boolean |
load(java.lang.String filename,
java.lang.String directory,
java.lang.String search_delimiters,
java.lang.String suffix)
Loads filename + suffix (".qm" if the suffix is not specified), which may be an absolute file name or relative to directory. |
java.lang.String |
translate(java.lang.String context,
java.lang.String sourceText)
Returns the translation for the key (context, sourceText). |
java.lang.String |
translate(java.lang.String context,
java.lang.String sourceText,
java.lang.String comment)
Returns the translation for the key (context, sourceText, comment). |
Methods inherited from class com.trolltech.qt.core.QObject |
---|
childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, indexOfProperty, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, properties, property, removeEventFilter, setObjectName, setParent, setProperty, startTimer, timerEvent, toString, userProperty |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class java.lang.Object |
---|
clone, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Constructor Detail |
---|
public QTranslator()
public QTranslator(QObject parent)
Method Detail |
---|
public final boolean load(java.lang.String filename, java.lang.String directory, java.lang.String search_delimiters)
The previous contents of this translator object are discarded.
If the file name does not exist, other file names are tried in the following order:
_
." is the default for search_delimiters if it is an empty string) and suffix.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:
public final boolean load(java.lang.String filename, java.lang.String directory)
The previous contents of this translator object are discarded.
If the file name does not exist, other file names are tried in the following order:
_
." is the default for search_delimiters if it is an empty string) and suffix.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:
public final boolean load(java.lang.String filename)
The previous contents of this translator object are discarded.
If the file name does not exist, other file names are tried in the following order:
_
." is the default for search_delimiters if it is an empty string) and suffix.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:
public final boolean load(java.lang.String filename, java.lang.String directory, java.lang.String search_delimiters, java.lang.String suffix)
The previous contents of this translator object are discarded.
If the file name does not exist, other file names are tried in the following order:
_
." is the default for search_delimiters if it is an empty string) and suffix.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:
public boolean isEmpty()
public final java.lang.String translate(java.lang.String context, java.lang.String sourceText)
public java.lang.String translate(java.lang.String context, java.lang.String sourceText, java.lang.String comment)
public static QTranslator fromNativePointer(QNativePointer nativePointer)
public final boolean load(byte[] data)
The data is not copied. The caller must be able to guarantee that data will not be deleted or modified.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |