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 @   IAmAProgrammer  阅读(564)  评论(0编辑  收藏  举报
(评论功能已被禁用)
编辑推荐:
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
点击右上角即可分享
微信分享提示