From ea318d1431c89e647598c510c4245c6571aa5f46 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Thu, 26 Jan 2012 23:32:43 -0600 Subject: Update to latest tqt3 automated conversion --- doc/html/linguist-manual-4.html | 142 ++++++++++++++++++++-------------------- 1 file changed, 71 insertions(+), 71 deletions(-) (limited to 'doc/html/linguist-manual-4.html') diff --git a/doc/html/linguist-manual-4.html b/doc/html/linguist-manual-4.html index 5be94e04b..7407656bb 100644 --- a/doc/html/linguist-manual-4.html +++ b/doc/html/linguist-manual-4.html @@ -52,25 +52,25 @@ body { background: #ffffff; color: black; }

Loading Translations

    int main( int argc, char **argv )
     {
-        TQApplication app( argc, argv );
+        TQApplication app( argc, argv );
 

This is how a simple main() function of a TQt application begins.

    int main( int argc, char **argv )
     {
-        TQApplication app( argc, argv );
+        TQApplication app( argc, argv );
 
-        TQTranslator translator( 0 );
-        translator.load( "tt1_la", "." );
-        app.installTranslator( &translator );
+        TQTranslator translator( 0 );
+        translator.load( "tt1_la", "." );
+        app.installTranslator( &translator );
 

For a translation-aware application a translator object is created, a translation is loaded and the translator object installed into the application.

    int main( int argc, char **argv )
     {
-        TQApplication app( argc, argv );
+        TQApplication app( argc, argv );
 
-        TQTranslator translator( 0 );
-        translator.load( TQString("tt2_") + TQTextCodec::locale(), "." );
-        app.installTranslator( &translator );
+        TQTranslator translator( 0 );
+        translator.load( TQString("tt2_") + TQTextCodec::locale(), "." );
+        app.installTranslator( &translator );
 

In production applications a more flexible approach, for example, loading translations according to locale, might be more appropriate. If the .ts files are all named according to a convention such as appname_locale, e.g. tt2_fr, tt2_de etc, then the code above will load the current locale's translation at runtime.

If there is no translation file for the current locale the application will fall back to using the original source text.

@@ -83,8 +83,8 @@ body { background: #ffffff; color: black; }
     button = new TQPushButton( tr("&Quit"), this);
 
-

All TQObject subclasses that use the Q_OBJECT macro implement the tr() function.

-

Although the tr() call is normally made directly since it is usually called as a member function of a TQObject subclass, in other cases an explicit class name can be supplied, for example:

+

All TQObject subclasses that use the Q_OBJECT macro implement the tr() function.

+

Although the tr() call is normally made directly since it is usually called as a member function of a TQObject subclass, in other cases an explicit class name can be supplied, for example:

     TQPushButton::tr("&Quit")
 
@@ -102,8 +102,8 @@ body { background: #ffffff; color: black; } rbh = new TQRadioButton( tr("Enabled", "Hue frame"), this );

Ctrl key accelerators are also translatable:

-
        file->insertItem( tr("E&xit"), qApp, SLOT(quit()),
-                          tr("Ctrl+Q", "Quit") );
+
        file->insertItem( tr("E&xit"), qApp, SLOT(quit()),
+                          tr("Ctrl+Q", "Quit") );
 

It is strongly recommended that the two argument form of tr() is used for Ctrl key accelerators. The second argument is the only clue the translator has as to the function performed by the accelerator.

Helping The Translator With Navigation Information

@@ -172,7 +172,7 @@ body { background: #ffffff; color: black; } }

Tutorials

-

Three tutorials are presented. The first demonstrates the creation of a TQTranslator object. It also shows the simplest use of the tr() function to mark user-visible source text for translation. The second tutorial explains how to make the application load the translation file applicable to the current locale. It also shows the use of the two-argument form of tr() which provides additional information to the translator. The third tutorial explains how identical source texts can be distinguished even when they occur in the same context. This tutorial also discusses how the translation tools help minimize the translator's work when an application is upgraded.

+

Three tutorials are presented. The first demonstrates the creation of a TQTranslator object. It also shows the simplest use of the tr() function to mark user-visible source text for translation. The second tutorial explains how to make the application load the translation file applicable to the current locale. It also shows the use of the two-argument form of tr() which provides additional information to the translator. The third tutorial explains how identical source texts can be distinguished even when they occur in the same context. This tutorial also discusses how the translation tools help minimize the translator's work when an application is upgraded.

Tutorial 1: Loading and Using Translations

@@ -189,45 +189,45 @@ TRANSLATIONS = tt1_la.ts ** ****************************************************************/ -#include <qapplication.h> -#include <qpushbutton.h> -#include <qtranslator.h> +#include <ntqapplication.h> +#include <ntqpushbutton.h> +#include <ntqtranslator.h> int main( int argc, char **argv ) { - TQApplication app( argc, argv ); + TQApplication app( argc, argv ); - TQTranslator translator( 0 ); - translator.load( "tt1_la", "." ); - app.installTranslator( &translator ); + TQTranslator translator( 0 ); + translator.load( "tt1_la", "." ); + app.installTranslator( &translator ); - TQPushButton hello( TQPushButton::tr("Hello world!"), 0 ); + TQPushButton hello( TQPushButton::tr("Hello world!"), 0 ); - app.setMainWidget( &hello ); - hello.show(); - return app.exec(); + app.setMainWidget( &hello ); + hello.show(); + return app.exec(); }

main.cpp

This example is a reworking of the "hello-world" example from Tutorial #1, with a Latin translation. The Tutorial 1 Screenshot, English version, above, shows the English version.

Line by Line Walk-through
-
    #include <qtranslator.h>
+
    #include <ntqtranslator.h>
 
-

This line includes the definition of the TQTranslator class. Objects of this class provide translations for user-visible text.

-
        TQTranslator translator( 0 );
+ 

This line includes the definition of the TQTranslator class. Objects of this class provide translations for user-visible text.

+
        TQTranslator translator( 0 );
 
-

Creates a TQTranslator object without a parent.

-
        translator.load( "tt1_la", "." );
+ 

Creates a TQTranslator object without a parent.

+
        translator.load( "tt1_la", "." );
 

Tries to load a file called tt1_la.qm (the .qm file extension is implicit) that contains Latin translations for the source texts used in the program. No error will occur if the file is not found.

-
        app.installTranslator( &translator );
+
        app.installTranslator( &translator );
 

Adds the translations from tt1_la.qm to the pool of translations used by the program.

-
        TQPushButton hello( TQPushButton::tr("Hello world!"), 0 );
+
        TQPushButton hello( TQPushButton::tr("Hello world!"), 0 );
 

Creates a push button that displays "Hello world!". If tt1_la.qm was found and contains a translation for "Hello world!", the translation appears; if not, the source text appears.

-

All classes that inherit TQObject have a tr() function. Inside a member function of a TQObject class, we simply write tr("Hello world!") instead of TQPushButton::tr("Hello world!") or TQObject::tr("Hello world!").

+

All classes that inherit TQObject have a tr() function. Inside a member function of a TQObject class, we simply write tr("Hello world!") instead of TQPushButton::tr("Hello world!") or TQObject::tr("Hello world!").

Running the Application in English

Since we haven't made the translation file tt1_la.qm, the source text is shown when we run the application:

@@ -298,7 +298,7 @@ TRANSLATIONS = tt2_fr.ts \

This example is a slightly more involved and introduces a key TQt Linguist concept: "contexts".

  • arrowpad.h contains the definition of ArrowPad, a custom widget;

  • arrowpad.cpp contains the implementation of ArrowPad;

    -
  • mainwindow.h contains the definition of MainWindow, a subclass of TQMainWindow

    +
  • mainwindow.h contains the definition of MainWindow, a subclass of TQMainWindow

  • mainwindow.cpp contains the implementation of MainWindow;

  • main.cpp contains main().

We will use two translations, French and Dutch, although there is no effective limit on the number of possible translations that can be used with an application. The relevant lines of tt2.pro are

@@ -312,8 +312,8 @@ TRANSLATIONS = tt2_fr.ts \

Run lupdate; it should produce two identical message files tt2_fr.ts and tt2_nl.ts. These files will contain all the source texts marked for translation with tr() calls and their contexts.

Line by Line Walk-through
-

In arrowpad.h we define the ArrowPad subclass which is a subclass of TQWidget. In the Tutorial 2 Screenshot, English version, above, the central widget with the four buttons is an ArrowPad.

-
    class ArrowPad : public TQGrid
+

In arrowpad.h we define the ArrowPad subclass which is a subclass of TQWidget. In the Tutorial 2 Screenshot, English version, above, the central widget with the four buttons is an ArrowPad.

+
    class ArrowPad : public TQGrid
 

When lupdate is run it not only extracts the source texts but it also groups them into contexts. A context is the name of the class in which the source text appears. Thus, in this example, "ArrowPad" is a context: it is the context of the texts in the ArrowPad class. The Q_OBJECT macro defines tr(x) in ArrowPad like this

@@ -321,13 +321,13 @@ TRANSLATIONS    = tt2_fr.ts \
 

Knowing which class each source text appears in enables TQt Linguist to group texts that are logically related together, e.g. all the text in a dialog will have the context of the dialog's class name and will be shown together. This provides useful information for the translator since the context in which text appears may influence how it should be translated. For some translations keyboard accelerators may need to be changed and having all the source texts in a particular context (class) grouped together makes it easier for the translator to perform any accelerator changes without introducing conflicts.

In arrowpad.cpp we implement the ArrowPad class.

-
        (void) new TQPushButton( tr("&Up"), this );
+
        (void) new TQPushButton( tr("&Up"), this );
 

We call ArrowPad::tr() for each button's label since the labels are user-visible text.

Tutorial 2 Screenshot, English version

-
    class MainWindow : public TQMainWindow
+
    class MainWindow : public TQMainWindow
     {
         Q_OBJECT
 
@@ -336,16 +336,16 @@ TRANSLATIONS = tt2_fr.ts \
        ArrowPad *ap = new ArrowPad( this, "arrow pad" );
 

We also call MainWindow::tr() twice, once for the menu item and once for the accelerator.

-
        file->insertItem( tr("E&xit"), qApp, SLOT(quit()),
-                          tr("Ctrl+Q", "Quit") );
+
        file->insertItem( tr("E&xit"), qApp, SLOT(quit()),
+                          tr("Ctrl+Q", "Quit") );
 

Note the use of tr() to support different keys in other languages. "Ctrl+Q" is a good choice for Quit in English, but a Dutch translator might want to use "Ctrl+A" (for Afsluiten) and a German translator "Strg+E" (for Beenden). When using tr() for Ctrl key accelerators, the two argument form should be used with the second argument describing the function that the accelerator performs.

Our main() function is defined in main.cpp as usual.

-
        TQTranslator translator( 0 );
-        translator.load( TQString("tt2_") + TQTextCodec::locale(), "." );
-        app.installTranslator( &translator );
+
        TQTranslator translator( 0 );
+        translator.load( TQString("tt2_") + TQTextCodec::locale(), "." );
+        app.installTranslator( &translator );
 
-

We choose which translation to use according to the current locale. TQTextCodec::locale() can be influenced by setting the LANG environment variable, for example. Notice that the use of a naming convention that incorporates the locale for .qm message files, (and .ts files), makes it easy to implement choosing the translation file according to locale.

+

We choose which translation to use according to the current locale. TQTextCodec::locale() can be influenced by setting the LANG environment variable, for example. Notice that the use of a naming convention that incorporates the locale for .qm message files, (and .ts files), makes it easy to implement choosing the translation file according to locale.

If there is no .qm message file for the locale chosen the original source text will be used and no error raised.

Translating to French and Dutch

We'll begin by translating the example application into French. Start TQt Linguist with tt2_fr.ts. You should get the seven source texts ("&Up", "&Left", etc.) grouped in two contexts ("ArrowPad" and "MainWindow").

@@ -424,48 +424,48 @@ TRANSLATIONS = tt3_pt.ts
  • tt3_pt.ts is the Portuguese message file.

    Line by Line Walk-through

    The PrintPanel is defined in printpanel.h.

    -
        class PrintPanel : public TQVBox
    +
        class PrintPanel : public TQVBox
         {
             Q_OBJECT
     
    -

    PrintPanel is a TQWidget. It needs the Q_OBJECT macro for tr() to work properly.

    +

    PrintPanel is a TQWidget. It needs the Q_OBJECT macro for tr() to work properly.

    The implementation file is printpanel.cpp.

        /*
    -        TQLabel *lab = new TQLabel( tr("<b>TROLL PRINT</b>"), this );
    -        lab->setAlignment( AlignCenter );
    +        TQLabel *lab = new TQLabel( tr("<b>TROLL PRINT</b>"), this );
    +        lab->setAlignment( AlignCenter );
         */
     

    Some of the code is commented out in Troll Print 1.0; you will uncomment it later, for Troll Print 1.1.

    -
            TQHButtonGroup *twoSided = new TQHButtonGroup( this );
    -        twoSided->setTitle( tr("2-sided") );
    -        but = new TQRadioButton( tr("Enabled"), twoSided );
    -        but = new TQRadioButton( tr("Disabled"), twoSided );
    -        but->toggle();
    -        TQHButtonGroup *colors = new TQHButtonGroup( this );
    -        colors->setTitle( tr("Colors") );
    -        but = new TQRadioButton( tr("Enabled"), colors );
    -        but = new TQRadioButton( tr("Disabled"), colors );
    -        but->toggle();
    +
            TQHButtonGroup *twoSided = new TQHButtonGroup( this );
    +        twoSided->setTitle( tr("2-sided") );
    +        but = new TQRadioButton( tr("Enabled"), twoSided );
    +        but = new TQRadioButton( tr("Disabled"), twoSided );
    +        but->toggle();
    +        TQHButtonGroup *colors = new TQHButtonGroup( this );
    +        colors->setTitle( tr("Colors") );
    +        but = new TQRadioButton( tr("Enabled"), colors );
    +        but = new TQRadioButton( tr("Disabled"), colors );
    +        but->toggle();
     

    Notice the two occurrences of tr("Enabled") and of tr("Disabled") in PrintPanel. Since both "Enabled"s and "Disabled"s appear in the same context TQt Linguist will only display one occurrence of each and will use the same translations for the duplicates that it doesn't display. Whilst this is a useful timesaver, in some languages, such as Portuguese, the second occurrence requires a separate translation. We will see how TQt Linguist can be made to display all the occurrences for separate translation shortly.

    The header file for MainWindow, mainwindow.h, contains no surprises. In the implementation, mainwindow.cpp, we have some user-visible source texts that must be marked for translation.

    -
            setCaption( tr("Troll Print 1.0") );
    +
            setCaption( tr("Troll Print 1.0") );
     

    We must translate the window's caption.

    -
            file->insertItem( tr("E&xit"), qApp, SLOT(quit()),
    -                          tr("Ctrl+Q", "Quit") );
    -        TQPopupMenu *help = new TQPopupMenu( this );
    -        help->insertItem( tr("&About"), this, SLOT(about()), Key_F1 );
    -        help->insertItem( tr("About &TQt"), this, SLOT(aboutTQt()) );
    +
            file->insertItem( tr("E&xit"), qApp, SLOT(quit()),
    +                          tr("Ctrl+Q", "Quit") );
    +        TQPopupMenu *help = new TQPopupMenu( this );
    +        help->insertItem( tr("&About"), this, SLOT(about()), Key_F1 );
    +        help->insertItem( tr("About &TQt"), this, SLOT(aboutTQt()) );
     
    -        menuBar()->insertItem( tr("&File"), file );
    -        menuBar()->insertSeparator();
    -        menuBar()->insertItem( tr("&Help"), help );
    +        menuBar()->insertItem( tr("&File"), file );
    +        menuBar()->insertSeparator();
    +        menuBar()->insertItem( tr("&Help"), help );
     

    We also need to translate the menu items. Note that the two argument form of tr() is used for the keyboard accelerator, "Ctrl+Q", since the second argument is the only clue the translator has to indicate what function that accelerator will perform.

    -
            TQTranslator translator( 0 );
    -        translator.load( TQString("tt3_") + TQTextCodec::locale(), "." );
    -        app.installTranslator( &translator );
    +
            TQTranslator translator( 0 );
    +        translator.load( TQString("tt3_") + TQTextCodec::locale(), "." );
    +        app.installTranslator( &translator );
     

    The main() function in main.cpp is the same as the one in Tutorial 2. In particular it chooses a translation file based on the current locale.

    Running Troll Print 1.0 in English and in Portuguese
    @@ -518,7 +518,7 @@ TRANSLATIONS = tt3_pt.ts
    Troll Print 1.1

    We'll now prepare release 1.1 of Troll Print. Start your favorite text editor and follow these steps:

    -
    • Uncomment the two lines that create a TQLabel with the text "<b>TROLL PRINT</b>" in printpanel.cpp.

      +
      • Uncomment the two lines that create a TQLabel with the text "<b>TROLL PRINT</b>" in printpanel.cpp.

      • Word-tidying: Replace "2-sided" by "Two-sided" in printpanel.cpp.

      • Replace "1.0" with "1.1" everywhere it occurs in mainwindow.cpp.

      • Update the copyright year to 1999-2000 in mainwindow.cpp.

        -- cgit v1.2.1