Inno Setup - 如何在自定义页面中显示本地化RTF文本

时间:2016-12-14 22:25:47

标签: inno-setup

如何使用此代码显示相同的文本,具有相同的结构(字体等),但使用不同的语言?例如:语言选择器中的英语和西班牙语。

(文字就在RTFText :=之前)

var
  ISCustomPage1: TWizardPage;
  RichEditViewer1: TRichEditViewer;

procedure initializewizard;
begin
  { Creates custom wizard page }
  ISCustomPage1 := CreateCustomPage(wpWelcome, 'ISCustomPage1_Caption', 'ISCustomPage1_Description');

  { RichEditViewer1 }
  RichEditViewer1 := TRichEditViewer.Create(WizardForm);
  with RichEditViewer1 do
  begin
    Parent := ISCustomPage1.Surface;
    Left := ScaleX(0);
    Top := ScaleY(0);
    Width := ScaleX(417);
    Height := ScaleY(241);
    ReadOnly := True;
    RTFText := '{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset204{\*\fname Times New Roman;}Times New Roman CYR;}{\f1\fnil\fcharset0 Times New Roman;}{\f2\fnil\fcharset0 Tahoma;}{\f3\fnil\fcharset0 @BatangChe;}}' + #13#10 +
         '{\colortbl ;\red0\green0\blue128;\red0\green0\blue255;}' + #13#10 +
         '\viewkind4\uc1\pard\cf1\lang1034\ul\b\f0\fs36 C\f1 o\f0 mo usar este c\f1\''f3\f0 digo para mostrar el mismo texto, con la misma estructura (fuentes, etc) pero en diferentes idiomas?\par' + #13#10 +
         '\cf0\ulnone\b0\f2\fs24\par' + #13#10 +
         '\par' + #13#10 +
         '\cf2\b\f3\fs20 Por ejemplo: ingl\''e9s y espa\''f1ol en un selector de idiomas.\par' + #13#10 +
         '}' + #13#10 +
         '';
  end;

  RichEditViewer1.TabOrder := 0;
end;

更好的选择是使用两个.rtf文件(英语和西班牙语)并根据语言选择器的语言加载每个文件?

1 个答案:

答案 0 :(得分:2)

有关自定义页面的标题和说明,请在语言文件中定义custom messages,方法与Inno Setup - How to localize component and type names?

相同
[CustomMessages]
ISCustomPage1_Caption=Some caption
ISCustomPage1_Description=Some description

然后使用代码中的CustomMessage function函数使用这些自定义消息。

对于RTF文本,最佳解决方案是创建单独的.rtf文件,并根据所选语言加载适当的文件。

[Languages]
Name: "eng"; MessagesFile: "Idiomas\English.isl"
Name: "spa"; MessagesFile: "Idiomas\Spanish.isl"

[Files]
Source: "eng.rtf"; Flags: dontcopy
Source: "spa.rtf"; Flags: dontcopy

[Code]

var
  ISCustomPage1: TWizardPage;
  RichEditViewer1: TRichEditViewer;

procedure InitializeWizard;
var
  RtfName: string;
  Rtf: AnsiString;
begin
  { Creates custom wizard page }
  ISCustomPage1 :=
    CreateCustomPage(
      wpWelcome, CustomMessage('ISCustomPage1_Caption'),
      CustomMessage('ISCustomPage1_Description'));

  { RichEditViewer1 }
  RichEditViewer1 := TRichEditViewer.Create(WizardForm);
  with RichEditViewer1 do
  begin
    Parent := ISCustomPage1.Surface;
    Left := ScaleX(0);
    Top := ScaleY(0);
    Width := ScaleX(417);
    Height := ScaleY(241);
    ReadOnly := True;
    ScrollBars := ssVertical;

    RtfName := ActiveLanguage + '.rtf';
    ExtractTemporaryFile(RtfName);
    if LoadStringFromFile(ExpandConstant('{tmp}\' + RtfName), Rtf) then
    begin
      UseRichEdit := True;
      RTFText  := Rtf;
    end;
  end;
end;

English

Spanish