0

I'm using dxgettext to translate a Delphi 10.4 project, but having defined the IDE to save to UTF files by default, dxgettext only extracts strings correctly from the .dfm files, from the .pas files it reads incorrectly the accents (it reads them as ANSI strings). I can verify that both files are equally coded in UTF-8.

I get strings like Hola Món instead of Hola Món.

Looks like dxgettext is hardcoded to consider all .pas files as ANSI files. If no one can help me configure dxgettext to make it read correctly those files, I guess I will have to write an small tool to copy all source files to a separate folder, transcode the .pas files to ANSI and call dxgettext from there.

PS: I have prepared a Hello World project that shows the problem.

Download sample : https://gofile.io/d/bKeZod

This is the project's only unit (it must be saved as UTF-8) :

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
  private
  public
  end;

var
  Form1: TForm1;

implementation
{$R *.dfm}

uses gnugettext;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Label1.Caption := _('Hola Món');
end;

end.

And this is the resulting default.po :

# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
# 
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2020-10-29 14:39\n"
"PO-Revision-Date: 2020-10-29 14:39\n"
"Last-Translator: Somebody <your.email@address.com>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: dxgettext 1.2.2\n"

#. Form1..Caption
#: Unit1.dfm:4
msgid "Aplicació de proves"
msgstr ""

#: Unit1.pas:28
msgid "Hola Món"
msgstr ""

The Form1.caption on the .dfm is correctly retrieved, but the string on the .pas file is read as an ANSI string.

Thank you.

Marc Guillot
  • 6,090
  • 1
  • 15
  • 42
  • 1
    Another solution is to use English as a base language of application. – zed Oct 29 '20 at 13:26
  • Would you make available for download a .dfm and .pas file for a minimal form reproducing you problem? I'll then be able to test here. – fpiette Oct 29 '20 at 13:27
  • I'm using dxGetText as well, but as @zed comment, I always make my program in English and then translate from English to other languages. French being my native language. – fpiette Oct 29 '20 at 13:28
  • @zed You are right Zed, than you, but I just got hired and I have no power to make that decision. This is not a commercial application but a very big program for the internal use of a factory, it's very unlikely that it will ever need to have an English translation so my boss will hardly approve to switch the base language. – Marc Guillot Oct 29 '20 at 14:01
  • @fpiette Thanks fpiette,I have linked a very small project showing the problem. You are right that with English as base language there wouldn't be much problems, but this is a big legacy program for the internal use of our company, an additional English translation seems very unlikely to ever be even needed, so I doubt I could convince my boss to make one as the base language (which would be a very hard task to make that switch for hundreds of forms). – Marc Guillot Oct 29 '20 at 14:05
  • 2
    I have downloaded your sample. It works perfectly here, I get "msgid "Hola Món". I have dxgettext 1.3.0 installed on my system. I suggest you upgrade dxGetText. – fpiette Oct 29 '20 at 14:24
  • @fpiette I'm using dxgettext 1.2.2. It's the last one I see available at sourceforge.net. Where did you downloaded the version 1.3.0 ?. – Marc Guillot Oct 29 '20 at 14:29
  • 1
    https://svn.code.sf.net/p/dxgettext/code – fpiette Oct 29 '20 at 14:33
  • 2
    The dxgettext installer is ancient. You are better off recompiling the tools from the sources. There have been various bugfixes and improvements to several of the tools - most of them by myself, but I never bothered to create a new installer. – dummzeuch Oct 29 '20 at 15:22
  • @dummzeuch Yes, fpiette showed me the link to download the current source code, and now it works like a charm. Thank you. – Marc Guillot Oct 30 '20 at 10:56

0 Answers0