Bugfixes and improvements to gnugettext.pas

http://blog.dummzeuch.de/category/delphi/

Samstag, Dezember 29th, 2012

Some might know that I have been using and contributing to the GnuGetText for Delphi and C++ Builder project. I just had another look into the gnugettext unit and found that it was rather difficult to understand the logic behind all these if(n)defs that refer to specific Delphi versions and older.

I have now changed the way it works by introducing conditional defines based on compiler / RTL features rather than a range of Delphi versions. These defines are set depending on the Delphi version that supports them. There are currently:

  • dx_has_Unsafe_Warnings
  • dx_has_WideStrings
  • dx_Hinstance_is_Integer
  • dx_NativeInt_is_Integer
  • dx_StringList_has_OwnsObjects
  • dx_GetStrProp_reads_unicode
  • dx_SupportsResources

Also, there was a bug because of the these difficult to read ifdefs regarding the handling of the TStringList.OwnsObjects which exists in Delphi 2009 and later. This should be fixed now as well.

And last but not least I removed a warning when compiling with Delphi XE3.

These changes are in the subversion repository on SourceForge.

Be warned: I have only superficially tested them. If you find a problem with it, please let me know.

 

Storing gnugettext translations as resources

Sonntag, April 14th, 2013

I always wondered why the assemble tool in dxgettext appends the translation files directly to the executable rather than using the existing mechanism of resources. This is no longer necessary. I have updated the gnugettext code to optionally use RCDATA resources named after the files.

So you e.g. create a translations.rc file as

LOCALE_DE_DEFAULT RCDATA ..\locale\de\LC_MESSAGES\default.mo
LOCALE_DE_DELPHI RCDATA ..\locale\de\LC_MESSAGES\delphi2007.mo
LOCALE_DE_DZLIB RCDATA ..\locale\de\LC_MESSAGES\dzlib.mo
LOCALE_EN_DEFAULT RCDATA ..\locale\en\LC_MESSAGES\default.mo
LOCALE_EN_DELPHI RCDATA ..\locale\en\LC_MESSAGES\delphi2007.mo
LOCALE_EN_DZLIB RCDATA ..\locale\en\LC_MESSAGES\dzlib.mo

Compile it using a resource compiler e.g. brcc32 to translations.res and add it to the executable.

The new code in gnugettext will automatically find and use these resources, all you have to do is add the conditional define dx_SupportsResources.

// if the conditional dx_SupportsResources is defined the .mo files
// can also be added to the executable as Windows resources
// Be warned: This has not been thoroughly tested.
// Default is turned off.
{.$define dx_SupportsResources}

You can find the updated gnugettext.pas in the dxgettext subversion repository on sourceforge.

Disclaimer: I have only cursorily tested this code. Use it at your own risk!

 

posted @ 2013-06-08 22:53  IAmAProgrammer  阅读(561)  评论(0编辑  收藏  举报