rvActions - adding extra items for i18n

General TRichView support forum. Please post your questions here
Post Reply
derPENGUIN
Posts: 4
Joined: Mon Jun 05, 2006 2:25 am

rvActions - adding extra items for i18n

Post by derPENGUIN »

Hi,
I have to add some menu entries with localisation. I added

Code: Select all

  // TrvActionInsertDatel
  '&Datum', 'Datum einfügen|Fügt das aktuelle Datumin das Dokument ein',
in RVAL_De.pas and the equivalent in RVAL_EngUS.pas. All other languages I commented out in RVALocalize.pas. But I get no translation. What fails?
THX
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Obviously, you need some code assigning your strings to your action.
All actions from RichViewActions have Localize method. The basic implementation is

Code: Select all

procedure TrvCustomAction.Localize;
begin
  if FMessageID<>rvam_Empty then begin
    Caption := RVA_GetS(FMessageID);
    Hint    := RVA_GetS(succ(FMessageID));
  end;
end;
where FMessageID is a property identifying string (one of constansts from RVALocalize.pas)
Localize method of actions is called when you call procedure RVA_LocalizeForm.

If your action is inherited from TrvCustomAction, assign the proper value to its FMessageID.

But I recommend to use your own localization method for your actions, without modifying RichViewActions files, because it will be difficult for you to update RichViewActions otherwise.
derPENGUIN
Posts: 4
Joined: Mon Jun 05, 2006 2:25 am

Please, need example

Post by derPENGUIN »

Thanks so far. Sure, You are right, I tried now to create my own subclasses. But I'm new in that, so it fails. (I work on that great word processor, unit3 from your zip) That is, what I've done:
1. in dmActions.pas (copied to my project) inserted

Code: Select all

rvActionInsertCDate: TmyActionInsertCDate;
2. myActions.pas

Code: Select all

unit myActions;

interface
{$I RV_Defs.inc}

uses
  Windows, Messages, Classes, Graphics, SysUtils, Controls, StdCtrls,
  Printers, Dialogs, Forms, ShellApi, Clipbrd,
  {$IFDEF RICHVIEWDEF6}
  DateUtils,
  {$ENDIF}
  RichView, rvrvData, rvEdit, ActnList, RVTable,
  RVItem, RVStyle, RVTInplace, rvScroll, rvUni, PtblRV, RVERVData, RVMisc,
  {$IFDEF USERVXML}
  RichViewXML,
  {$ENDIF}
  {$IFDEF USERVHTML}
  RVHTMLImport, RVNormalize,
  {$ENDIF}
  {$IFDEF USERVADDICT3}
  ad3RichViewCmpnts,  ad3SpellBase,
  {$ENDIF}
  {$IFDEF USERVKSDEVTE}
  te_controls,
  {$ENDIF}
  {$IFDEF USEINDY}
  idhttp,
  {$ENDIF}
  {$IFDEF USEJVCL}
  JvWinDialogs,
  {$ENDIF}
  {$IFDEF USETB2K}
  TB2Item,
  {$ENDIF}
  {$IFDEF USETBX}
  TBX,
  {$ENDIF}
  CRVData, RVClasses,RVOfficeCnv, ExtDlgs, RVFuncs, Menus,
  RVALocalize, RichViewActions;

type
  TmyAction = class(TrvAction);
  TmyActionInsertCDate = class(TmyAction)

  private
    FOnInsertCDate: TRVAInsertTextEvent;
  public
    procedure ExecuteTarget(Target: TObject); override;
    procedure UpdateTarget(Target: TObject); override;
  published
    property OnInsertCDate: TRVAInsertTextEvent read FOnInsertCDate write FOnInsertCDate;
  end;


implementation

procedure TmyActionInsertCDate.ExecuteTarget(Target: TObject);
var rve: TCustomRichViewEdit;
    s: String;
begin
  if Assigned(FOnInsertCDate) then begin
    rve := GetControl(Target);
    s := FormatDateTime('d. mmmm yyyy', Now);
//    FOnInsertText(Self, rve, s); ###comple error
    rve.InsertText(s);
  end else
    Beep;
end;

procedure TmyActionInsertCDate.UpdateTarget(Target: TObject);
var rve: TCustomRichViewEdit;
begin
  if not RVA_ActionsEnabled or Disabled then begin
    Enabled := False;
    exit;
  end;
  rve := GetControl(Target).TopLevelEditor;
  Enabled := rve.RVData.PartialSelectedItem=nil;
end;
end.
3. Translation: todo

Whe I compile it, I get a message "rvActionInsertCDate must be from class TAction, should I correct it?". Clicking on "no", it compiles, but the menu entry in my app is disabled.

May be, I do it completly wrong. Can you give me please a working example?

Much thanks,
Frank
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

You need to add your unit in some package and install this package.
Otherwise you will not be able to place your action on form at designtime.
Post Reply