Soluling home   Document home

Soluling Resourcer

Resourcer

Resourcer is Soluling's command line application's resource command that resources source code files. This means finding hardcoded strings from your source code files and replacing them with resource strings. Unlike Soluling's scan and build, resourcing modifies your source code. It reads a single source code file (e.g. .pas or .cs), or all the project's (e.g. .dpr or .csproj) source code files to find hard coded strings. If found and they are not marked to be skipped, Resourcer refactors that part to use a properly internationalized syntax, and adds the string to the resource block or resource file. To get help about the resource command type:

SoluMake resource

Note! SoluMake is installed and enabled if you have a Soluling edition that supports it, such as Enterprise edition or Build automation edition.

Resourcer works on the following source code types:

Note! Resourcer is currently in beta. Always make a backup from your source code before using Resourcer.

C#

C# source code (.cs) and project (.cssproj) files.

Resourcer extracts hard coded string (excludes those marked with Do not localize comment), adds them to the resx file, and finally refactors the source code to use the resource items instead of the hard coded strings.

Form.cs before Form.cs and Resources.resx after
namespace WinFormsApp
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }
    
    private void Form1_Load(object sender, EventArgs e)
    {
      label1.Text = "This is a sample";
      label2.Text = "John";  // Do not localize
      label3.Text = "First line" + "\n\r" +  "Second line";
    }
  }
}
namespace WinFormsApp
{
  public partial class Form1 : Form
  {
    public Form1()
    {
      InitializeComponent();
    }
    
    private void Form1_Load(object sender, EventArgs e)
    {
      label1.Text = Resources.ThisIsASample;
      label2.Text = "John";  // Do not localize
      label3.Text = Resources.FirstLineSecondLine;
    }
  }
}
 
<?xml version="1.0" encoding="utf-8"?>
<root>
   <resheader name="resmimetype">text/microsoft-resx</resheader>
   <resheader name="version">2.0</resheader>
   <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</resheader>
   <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</resheader>
   <data name="ThisIsASample" xml:space="preserve">
     <value>This is a sample</value>
   </data>
   <data name="FirstLineSecondLine" xml:space="preserve">
     <value>First line
Second line</value>
   </data>
</root>    

Use SoluMake's resource command to run Resourcer.

SoluMake resource WinFormsApp.csproj -res:Resources.resx

The above command resources all .cs files in WinFormsApp.csproj project and stores the resource strings in Resources.resx. If Resources.resx does not exist, Resourcer creates it. If it exists, Resourcer updates it.

After you have run the command do the following steps:

  1. Open you project to Visual Studio.
  2. Locate the resource file (e.g. Resources.resx) that Resourcer just created or updated.
  3. Open Resources.resx into resource editor (i.e. double click the file).
  4. Change the Access Modifier from Custom to Internal or Public.

This will create or update Resources.Designer.cs file.

Delphi

Delphi source code (.pas) and project (.dpr) files.

Resourcer extracts hard coded string (excludes those marked with Do not localize comment), adds them to the resourcestring block, and finally refactors the source code to use the resource strings instead of the hard coded strings.

Unit1.pas before Unit1.pas after
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
  Label1.Caption := 'This is a sample';
  Label2.Caption := 'John'; // Do not localize
  Label3.Caption := 'First line' + sLineBreak + 'Second line';
end;
end.
 
implementation
// Following lines were added by SoluResourcer
resourcestring
  SThisIsASample = 'This is a sample';
  SFirstLineSecondLine = 'First line'#13#10'Second line';
// End
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
  Label1.Caption := SThisIsASample;
  Label2.Caption := 'John'; // Do not localize
  Label3.Caption := SFirstLineSecondLine;
end;
end.

Use SoluMake's resource command to run Resourcer.

SoluMake resource Project1.dpr

The above command resources all .pas files in Project1.dpr project.