delphilocalizationdevexpressresourcestring

How to localize (override resourcestring) the constant of Delphi DevExpres Cx component?


I am using TcxDBImgage from DevExpress ExpressEditors Library 6.45 (it is for Delphi 2009) and this image component as built-in popup menu component with menu items 'Load', 'Save', etc.

I am developing my application for non-English language and I would like to override the captions of those menu items.

I checked the DevExpress Delphi code to see, how those captions are loaded and the code is:

  procedure RefreshCaptions;
  begin
    with FEditPopupMenu do
    begin
      Items[0].Caption := cxGetResourceString(@cxSMenuItemCaptionCut);
      Items[1].Caption := cxGetResourceString(@cxSMenuItemCaptionCopy);
      Items[2].Caption := cxGetResourceString(@cxSMenuItemCaptionPaste);
      Items[3].Caption := cxGetResourceString(@cxSMenuItemCaptionDelete);
      Items[5].Caption := cxGetResourceString(@cxSMenuItemCaptionLoad);
      Items[6].Caption := cxGetResourceString(@cxSMenuItemCaptionSave);
    end;
  end;

function cxGetResourceString(AResString: TcxResourceStringID): string;
var
  AIndex: Integer;
begin
  AIndex := GetResOriginalStringIndex(AResString);
  if AIndex <> -1 then
    Result := FResStrings[AIndex]
  else
    Result := LoadResString(AResString);
end;  

and the dcr file (Delphi compiler generated file) contains constants:

#define cxEditConsts_cxSMenuItemCaptionCut 64713
#define cxEditConsts_cxSMenuItemCaptionCopy 64714
#define cxEditConsts_cxSMenuItemCaptionPaste 64715
#define cxEditConsts_cxSMenuItemCaptionDelete 64716
#define cxEditConsts_cxSMenuItemCaptionLoad 64717
#define cxEditConsts_cxSMenuItemCaptionSave 64718

    cxEditConsts_cxSMenuItemCaptionCut, "Cu&t"
    cxEditConsts_cxSMenuItemCaptionCopy,    "&Copy"
    cxEditConsts_cxSMenuItemCaptionPaste,   "&Paste"
    cxEditConsts_cxSMenuItemCaptionDelete,  "&Delete"
    cxEditConsts_cxSMenuItemCaptionLoad,    "&Load..."
    cxEditConsts_cxSMenuItemCaptionSave,    "Save &As..."

So, this should be customizable in some way. May question is - how can I override those constants in the Delphi code of my project, that uses TcxDBImage component?

Should I redefine resourcestrings in some way? Should I create *.res file with the the STRINGS table? I checked res files both of my project and of the DevExpress components (e.g. using Visual Studio as editor of res files) and they contain Icon and Version only, no string table.

I am aware of the documentation https://docs.devexpress.com/VCL/154039/ExpressCrossPlatformLibrary/how-to/localize-an-application and https://docs.devexpress.com/VCL/154011/ExpressCrossPlatformLibrary/concepts/localizer-editor-ui, but I have no Localizer editor and I am not sure whether the recent documentation can be applied to the my version of DevExpress components.


Solution

  • Create a unit as below and include it in uses clause somewhere in the project. Of course, you can change resource strings in other units in the same way.

    unit MxDxLocalization;
    
    interface
    implementation
    
    uses
      dxCore, cxClasses, cxEditConsts; // cxGridStrs, cxGridPopupMenuConsts, cxFilterConsts, ...
    
    initialization
      // replace ... with the desired caption
      // cxEditConsts:
      cxSetResourceString(@cxSMenuItemCaptionCut,    '...');
      cxSetResourceString(@cxSMenuItemCaptionCopy,   '...');
      cxSetResourceString(@cxSMenuItemCaptionPaste,  '...');
      cxSetResourceString(@cxSMenuItemCaptionDelete, '...');
      cxSetResourceString(@cxSMenuItemCaptionLoad,   '...');
      cxSetResourceString(@cxSMenuItemCaptionSave,   '...');
      // ...
    
    end.