Inno Setup - How to display localized RTF text in custom page

前端 未结 1 1775
误落风尘
误落风尘 2020-12-18 16:05

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.

相关标签:
1条回答
  • 2020-12-18 16:55

    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;
    

    0 讨论(0)
提交回复
热议问题