Inno Setup - How to display localized RTF text in

2020-02-11 17:23发布

How to use this code to show the same text, with the same structure (fonts, etc) but in different languages? For example: English and Spanish in a language selector.

(The text is all that is ahead of 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;

Would a better choice be to use two .rtf files (English and Spanish) and load each one according to language of the language selector?

标签: inno-setup
1条回答
劫难
2楼-- · 2020-02-11 17:38

For the caption and description of the custom page, define custom messages in the language files, the same way as in Inno Setup - How to localize component and type names?

[CustomMessages]
ISCustomPage1_Caption=Some caption
ISCustomPage1_Description=Some description

And then use these custom messages using the CustomMessage function function in your code.

For the RTF text, the best solution is to create separate .rtf files and load an appropriate one based on the selected language.

[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

查看更多
登录 后发表回答