0

我正在使用 dxgettext 来翻译 Delphi 10.4 项目,但是已经定义了默认情况下保存到 UTF 文件的 IDE,dxgettext 仅从 .dfm 文件中正确提取字符串,从 .pas 文件中正确提取重音符号(它读取它们作为 ANSI 字符串)。我可以验证这两个文件都以 UTF-8 编码。

我得到字符串Hola Món而不是Hola Món.

看起来 dxgettext 被硬编码为将所有 .pas 文件视为 ANSI 文件。如果没有人可以帮助我配置 dxgettext 以使其正确读取这些文件,我想我将不得不编写一个小工具来将所有源文件复制到一个单独的文件夹,将 .pas 文件转码为 ANSI 并从那里调用 dxgettext。

PS:我准备了一个显示问题的Hello World项目。

下载示例:https ://gofile.io/d/bKeZod

这是项目的唯一单位(必须保存为 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.

这是生成的 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 ""

.dfm 上的 Form1.caption 被正确检索,但 .pas 文件上的字符串被读取为 ANSI 字符串。

谢谢你。

4

0 回答 0