GNU gettext for Delphi, C++ Builder and Kylix 1.2 beta
<<< Previous | Experienced programmers' topics | Next >>>

# The better alternative to resourcestring

Instead of using resourcestrings, there is a better alternative:

    ShowMessage (_('Action aborted'));

The _() is a pascal function inside gnugettext.pas, which translates the text. It returns a widestring, unlike resourcestring, which is limited to ansistring. You can use _() together with ansistrings as you like, because Delphi automatically converts widestrings to strings when needed. Another benefit of this is that you can write comments, that the translator can use to make better translations:

    // Message shown to the user after the user clicks Abort button
    ShowMessage (_('Action aborted'));

You can also write the comment in the same line:

    ShowMessage (_('Action aborted')); // Message to user when clicking Abort button

But only the // style comment is supported - you cannot use { } or (* *) comments for this purpose.

Good comments normally lead to good translations. If the translator has a copy of the source code, poedit and kbabel can both show the location in the source code to the translator. This makes sense with _(), because the translator might get a good idea, what this is about, even if the translator isn't a programmer.

In other words, there are many reasons to use _() instead of resourcestrings. If you create a new application, don't even think about resourcestrings - just go directly for the _() solution.

<<< Previous | Home | Next >>>
Text domain management | Up | Debugging