GNU gettext for Delphi, C++ Builder and Kylix 1.2 beta
<<< Previous | Action | Next >>>

# Uses clauses

The order, with which Delphi executes the initialization sections of your units depend on the order that the units are included in your application. A typical application has a .dpr file that looks like this:

    program Project1;

    uses
      Forms,
      Unit1 in 'Unit1.pas' {Form1};

    {$R *.res}

    begin
      Application.Initialize;
      Application.CreateForm(TForm1, Form1);
      Application.Run;
    end.

Here, the initialization section of the `Forms` unit will be executed before the initialization section of the unit named `Unit1`. All units that are used by the `Forms` unit will also have their initialization section executed before the section of `Unit1`.

Not all units have an initialization section, but the `gnugettext.pas` file does. It detects the language, starts the resourcestring translation etc. Therefore, all resourcestrings, that are fetched before this intitialization section has been run, will not be translated, but all that are fetched afterwards, will. If you include the `DBClient` unit, and this unit fails to initialize because there is no `MIDAS.DLL`, then it will show an error message in English if gnugettext was later in the uses list, but it will show it in the local language if gnugettext was first.

A translated application's .dpr file could look like this:

    program Project1;

    uses
      gnugettext in 'gnugettext.pas',
      Forms,
      Unit1 in 'Unit1.pas' {Form1};

    {$R *.res}

    begin
      // Add extra domain for runtime library translations
      AddDomainForResourceString ('delphi');

      // Force program to use Danish instead of the current Windows settings
      UseLanguage ('da');

      // Put ignores on the properties that cannot be translated
      TP_GlobalIgnoreClassProperty (TMyComponent1,'property1');
      TP_GlobalIgnoreClassProperty (TMyComponent2,'property2');
      TP_GlobalIgnoreClassProperty (TMyComponent3,'property3');
      TP_GlobalIgnoreClassProperty (TMyComponent4,'property4');

      Application.Initialize;
      Application.CreateForm(TForm1, Form1);
      Application.Run;
    end.

This works very, very well for most situations, but if you want translations to start as early as possible, your .dpr file should look like this:

    program Project1;

    uses
      gnugettext in 'gnugettext.pas',
      gginitializer in 'gginitializer.pas',
      Forms,
      Unit1 in 'Unit1.pas' {Form1};

    {$R *.res}

    begin
      // Put ignores on the properties that cannot be translated
      // These just have to be placed before the first call
      // to TranslateComponents()
      TP_GlobalIgnoreClassProperty (TMyComponent1,'property1');
      TP_GlobalIgnoreClassProperty (TMyComponent2,'property2');
      TP_GlobalIgnoreClassProperty (TMyComponent3,'property3');
      TP_GlobalIgnoreClassProperty (TMyComponent4,'property4');

      Application.Initialize;
      Application.CreateForm(TForm1, Form1);
      Application.Run;
    end.

In this example, gginitializer sets all the necessary settings in `gnugettext.pas`. It could look like this:

    unit gginitializer;

    interface

    implementation

    uses
      gnugettext;

    initialization
      // Add extra domain for runtime library translations
      AddDomainForResourceString ('delphi');

      // Force program to use Danish instead of the current Windows settings
      UseLanguage ('da');

      // Do not put TP_GlobalIgnoreClass* statements here, because
      // that would require this unit to use other units than gnugettext,
      // and then all these units would have their initialization
      // section executed before this one.

    end.

In this example, the initialization section of gginitializer will be run before the initialization sections of units like `Forms` and `Unit1` are run.

<<< Previous | Home | Next >>>
Create a single language application with localized runtime library | Up | Solving ambiguities