![]() |
Resourcer |
Note! Resourcer is currently in beta. Always make a backup from your source code before using 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.
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:
Resourcer command has several options you can use to configure how the resourcing works.
| Option | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| -res:"S" | Resource file to be used. Creates the file if does not exist. If not given resource items are inserted into original files.
|
|||||||||||||||
| -outdir:"S" | Output directory where refactored files are written. If not given the original files are modificated. | |||||||||||||||
| -prefix:"S" | Resource id prefix. When Resourcer generates a Delphi resource id it by default adds "S" prefix. If you want to use some other prefix, pass it here. |
|||||||||||||||
| -onlyascii | Use only ASCII characters in resource ids. | |||||||||||||||
| -sepwords | Separate words in resource ids with an underscore character. "This is a sample" -> SThis_Is_A_Sample. | |||||||||||||||
| -maxlength:N | Maximum resource id length in characters. Default is 30. | |||||||||||||||
| -idcase:N | Resource id case. Out sample string is "This is a sample":
|
|||||||||||||||
| -noconcat | Do not concatenate consecutive strings. 'Hello' + sLineBreak + 'World' becomes two resource strings: SHello and SWorld. If not present 'Hello' + sLineBreak + 'World' becomes one resource string: SHelloWorld. |
|||||||||||||||
| -ignores:"S" | Ignore specific strings. S is a text file that contains the ignore tags. One tag in each line. if not S is given then the built-in tags are used. If you want to localize one, add "Do localize" comment. |
|||||||||||||||
| -noi18n:"S" | Content of comment that disables resourcing of a string. Tag is case insensitive.
|
To get help about the resource command type:
SoluMake resource
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:
Resources.resx) that Resourcer just created or updated.Resources.resx into resource editor (i.e. double click the file).This will create or update Resources.Designer.cs file.
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.