#7 Embed translations as resources

open-remind
None
4
2005-05-06
2004-03-30
G.J. Doornink
No

I have created a patch that adds the possibility to load
the translations from a resource embedded into the
executable or dll. This patch requires that a resource
(.rc) file like the fololowing is compiled into the
executable or dll.

index Locale
{
"default.mo|en\0",
"locale\\nl\\LC_MESSAGES\\default.mo|nl\0\0"
}
en Locale "default.mo"
nl Locale "locale\nl\LC_MESSAGES\default.mo"

The first part of the resource file describes an index
section that indicates which actual resource entry
contains the .mo file data.
The second part of the resource file links the actual .mo
files into the application.

This patch would solve feature request 803808.

Discussion

  • Logged In: YES
    user_id=116253

    I like the code, but the patch generates an exception when
    you're just running the sample application, at the line

    ms:=TResourceStream.Create(HInstance, 'INDEX', 'LOCALE');

    We need to find a way to determine, if the resource exists,
    before executing that line of code, otherwise the Delphi IDE
    will stop at that line.

     
    • priority: 5 --> 4
    • assigned_to: nobody --> dybdahl
    • status: open --> open-postponed
     
  • G.J. Doornink
    G.J. Doornink
    2004-09-29

    Logged In: YES
    user_id=1852

    In order to prevent the exception when the resource is not
    present just change the following code from:

    { First try 'embedded' resources }
    try
    ms:=TResourceStream.Create
    (HInstance, 'INDEX', 'LOCALE');

    to:

    { First try 'embedded' resources }
    if (FindResource(HInstance, PChar('INDEX'), PChar
    ('LOCALE')) <> 0) then
    try
    ms:=TResourceStream.Create
    (HInstance, 'INDEX', 'LOCALE');

    I haven't tested it, but it should work since it is the same
    check TResourceStream uses when raising the exception

     
    • status: open-postponed --> open-remind
     
  • Logged In: YES
    user_id=116253

    Did you upgrade this to a newer version of gnugettext.pas?
    In that case I would love to receive a copy of your newest
    version with a specification of which version you based your
    version on.

     
  • G.J. Doornink
    G.J. Doornink
    2005-06-07

    gnugettext.pas svn revision 106 patch

     
    Attachments
  • G.J. Doornink
    G.J. Doornink
    2005-06-07

    Logged In: YES
    user_id=1852

    I've created a patch against revision 106 of
    svn://svn.berlios.de/dxgettext/trunk/dxgettext/sample/gnugettext.pas