Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2002-09

gettext

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Stefan Ziegenbalg

Hi,

is there a way to translate const strings manual, like gettext or dgettext in C?

Example:

Error(gettext('One ') + s1 + gettext(' Two ') + s2 + gettext(' Three'));

instead of:

resourcestring
   one='One ';
   two=' Two ';
   three = ' Three';

{ 1000 lines of code }

Error(one + s1 + two + s3 + three);

or even

resourcestring
   mes='One %s Two %s Three';

{ 1000 lines of code }

Error(Format(mes, [s1,s2]));

The problem are the "1000 lines of code". It is ugly to define the message text 1000 lines away from the place where it occures. And I have to keep their name in mind. :-(

Regards Stefan

----------------------------------------------

http://www.sziegenbalg.de
http://www.simage.org

Reply by email

Sebastian Günther
to Stefan Ziegenbalg
Hi, is there a way to translate const strings manual, like gettext or dgettext in C?

yes... use the gettext unit provided in the FCL.

TMOFile = class
...

   constructor Create(const AFilename: String);
   constructor Create(AStream: TStream);
   ...
   function Translate(AOrig: String): String;
end;

so just use it this way:

TranslStrings := TMOFile('test.mo');
try
   WriteLn('Translated: ', TranslStrings.Translate('Some test string'));
finally
   TranslStrings.Free;
end;

In the long term I think we'll switch to a procedural approach, so that gettext can be used within the RTL.

- Sebastian

Reply by email