Sign in Join
Wiki copytemporary

IDE Window: Make ResourceString: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: IDE Window: Make ResourceString

OldNewLine
1+This wizard helps to convert a string constant into a resourcestring.
2+
3+Place the cursor on a string constant or select the part of the constant that should be converted. Then do <Right click> Refactoring | Make Resource String.
4+
5+A string constant is for example 'Some text'.
6+
7+## Contents
8+
9+ * 1 Conversion Options
10+ * 1.1 Identifier prefix
11+ * 1.2 Identifier length
12+ * 1.3 Custom identifier
13+ * 1.4 Resourcestring section
14+ * 1.5 String with same value
15+ * 1.6 Where to put the new identifier in the resourcestring section
16+ * 2 String constant in source
17+ * 3 Source preview
18+ * 4 Examples
19+ * 4.1 Example 1: Setting the caption of a form
20+ * 4.2 Example 2 : Complex string constants
21+ * 5 See also
22+
23+## Conversion Options
24+
25+### Identifier prefix
26+
27+You can create automatically a new identifier. The new identifier will start with the prefix, followed by the words of the string constant. If there is already a resourcestring with this value, the old identifier will be suggested. The IDE remembers the prefixes for each unit, so the last used prefix for the current unit is preselected first.
28+
29+### Identifier length
30+
31+This is the maximum length of the automatically created identifier.
32+
33+### Custom identifier
34+
35+Instead of using an automatically created identifier, you can specify the identifier on your own here.
36+
37+### Resourcestring section
38+
39+This combobox contains all available resourcestring sections of all units in scope. That means all sections of the current unit plus all sections in the interface parts of all used units.
40+
41+### String with same value
42+
43+This combobox contains all resourcestring identifiers with the same value as the new resourcestring. You can choose here, if you want to take one of them.
44+
45+### Where to put the new identifier in the resourcestring section
46+
47+If a new identifier is created, this defines where it will be added in the resourcestring section.
48+
49+ * Append to section - add the new identifier at the end of the section.
50+ * Insert alphabetically - insert the identifier alphabetically.
51+ * Insert context sensitive - search the code above and below the current code position and search for resourcestring identifiers. If it finds one, then the new identifier is added there, otherwise it is appended at the end of the section.
52+
53+## String constant in source
54+
55+This shows the old or current source code.
56+
57+## Source preview
58+
59+This is a preview, how the string constant is replaced, followed by a line of dashes and then a preview of how the resourcestring will look like.
60+
61+## Examples
62+
63+### Example 1: Setting the caption of a form
64+
65+If you do not have already a resource string section, start one in the interface part of the unit. For example right above the 'implementation' keyword:
66+```
67+resourcestring
68+ rsSomeText = 'Some text';
69+```
70+
71+Add in the FormCreate event the following line:
72+```
73+Caption:='An example caption';
74+```
75+
76+Place the cursor on the string constant, i.e. somewhere between the two '. Then do -> <Right click> Refactoring | Make Resource String
77+
78+Set in the identifier prefix 'rs' without the '. The new automatically suggested identifier will be 'rsAnExampleCaption'. The preview shows
79+```
80+Caption:=rsAnExampleCaption;
81+ --------------------------------------------------------------------------------
82+ rsAnExampleCaption = 'An example caption'
83+```
84+
85+Click ok.
86+
87+### Example 2 : Complex string constants
88+
89+When converting a complex string expression with variables and functions, the tool will use the **Format** function. For instance the statement:
90+```
91+Caption:='Left='+IntToStr(Left)+' Top='+IntToStr(Top);
92+```
93+
94+will be replaced with
95+```
96+Caption:=Format(rsLeftTop, [IntToStr(Left), IntToStr(Top)]);
97+```
98+
99+and the new resourcestring will be
100+```
101+rsLeftTop = 'Left=%s Top=%s'
102+```
103+
104+The Format function is defined in the SysUtils unit. If your unit uses section does not already contain it, you must add it yourself.
105+
106+
107+
108+## See also
109+
110+ * [[Getting translation strings right]]
111+
112+---
113+*From the Free Pascal wiki, page "IDE Window: Make ResourceString", as the Internet Archive kept it on 2025-03-16. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history