Difference between revisions of "IDE Window: Make ResourceString"

From Lazarus wiki
Jump to navigationJump to search
(リソース文字列no作成)
 
(9 intermediate revisions by 7 users not shown)
Line 1: Line 1:
このウィザードはある文字列定数をリソース文字列に変換するのを手助けします。
+
{{IDE Window: Make ResourceString}}
  
カーソルを変換したい文字列定数もしくは選択されたその一部の上に置いてください。その上で、ツール → リソース文字列作成 を呼び出して下さい。
+
This wizard helps to convert a string constant into a resourcestring.
  
例として、文字列定数を 'Some text'とします。
+
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.
  
== 変換オプション ==
+
A string constant is for example 'Some text'.
  
=== 識別子の接頭辞 ===
+
== Conversion Options ==
  
新しい識別子が自動的に作成されます。その新しい識別子は接頭辞(prefix)から始まり、文字列定数の単語が続きます。もし同じ値のリソース文字列が既にある場合、その古い識別子が提案されます。
+
=== Identifier prefix ===
IDEはユニット毎の接頭辞を記憶するため、現在のユニットで最後に用いられた接頭辞が始めに選択されます。
 
  
=== 識別子の長さ ===
+
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.
  
これは自動的に作成された識別子の最大長です。
+
=== Identifier length ===
  
=== カスタム識別子 ===
+
This is the maximum length of the automatically created identifier.
  
自動的に作成された 識別子を用いる代わりに、ここにあなた自身が識別子を設定することができます。
+
=== Custom identifier ===
  
=== リソース文字列セクション ===
+
Instead of using an automatically created identifier, you can specify the identifier on your own here.
  
このコンボボックスはスコープ内の全てのユニットで使用できる全てのリソース文字列セクションを含んでいます。これは現在のユニットの全てのセクションに加え、用いられているユニットの宣言部にある全てのセクションを加えたものです。
+
=== Resourcestring section ===
  
=== 同じ値の文字列 ===
+
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.
  
このコンボボックスは新しいリソース文字列と同じ値を持つ全てのリソース文字列識別子を並べています。それらの一つを用いたい場合にここで選択できます。
+
=== String with same value ===
  
=== リソース文字列セクションのどこに新しい識別子を置けばよいか ===
+
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.
  
新しい識別子が作成された場合に、 リソース文字列セクションのどこにそれを置けばよいかを設定します。
+
=== Where to put the new identifier in the resourcestring section ===
  
* セクションに追加 - 新しい識別子はセクションの末尾に置かれます。
+
If a new identifier is created, this defines where it will be added in the resourcestring section.
* アルファベット順に挿入 - 識別子をアルファベット順に挿入します。
 
* 状況感知的に挿入 - 現在のコードの前後でリソース文字列識別子を探索します。もし見つけたら新しい識別子はそこに追加されます。なければセクションの末尾に置かれます。
 
  
== ソース内の文字列定数 ==
+
* Append to section - add the new identifier at the end of the section.
 +
* Insert alphabetically - insert the identifier alphabetically.
 +
* 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.
  
これは古いソースコードもしくは現在のソースコードを示しています。
+
== String constant in source ==
  
== ソースのプレビュー ==
+
This shows the old or current source code.
  
これは文字列定数がどのように再配置されるかのプレビューで、破線がその下に引かれ、そのリソース文字列がどのように見えるかを示します。
+
== Source preview ==
  
== 例 ==
+
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.
  
=== 例 1: フォームのcaptionの設定 ===
+
== Examples ==
  
resourcestringセクションがまだなければ宣言部に追加して下さい。例えば'implementation'キーワードのすぐ上のあたりに:
+
=== Example 1: Setting the caption of a form ===
  
 +
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:
 +
 +
<syntaxhighlight lang=pascal>
 
   resourcestring
 
   resourcestring
 
     rsSomeText = 'Some text';
 
     rsSomeText = 'Some text';
 +
</syntaxhighlight>
  
FormCreateイベントに次の行を追加して下さい:
+
Add in the FormCreate event the following line:
 
    
 
    
 +
<syntaxhighlight lang=pascal>
 
   Caption:='An example caption';
 
   Caption:='An example caption';
 +
</syntaxhighlight>
  
カーソルをその文字列定数の上、つまり2つの 'の間のどこかに置き、ツール → リソース文字列作成
+
Place the cursor on the string constant, i.e. somewhere between the two '.
 +
Then do  -> <Right click> Refactoring | Make Resource String
 +
 
 +
Set in the identifier prefix 'rs' without the '.
 +
The new automatically suggested identifier will be 'rsAnExampleCaption'.
 +
The preview shows
  
その識別子の接頭辞に'rs'を('なしで)置きます。
 
新しく自動的に提案される識別子は'rsAnExampleCaption'になります。
 
プレビューでは次のように表示されます。
 
 
     Caption:=rsAnExampleCaption;
 
     Caption:=rsAnExampleCaption;
 
   --------------------------------------------------------------------------------
 
   --------------------------------------------------------------------------------
 
   rsAnExampleCaption = 'An example caption'   
 
   rsAnExampleCaption = 'An example caption'   
  
OKをクリックしてください。
+
Click ok.
 +
 
 +
=== Example 2 : Complex string constants ===
  
=== 例 2 : 複雑な文字列定数 ===
+
When converting a complex string expression with variables and functions, the tool will use the '''Format''' function. For instance the statement:
  
変数や関数をもつ複雑な文字列式を変換する場合、このツールは'''Format'''関数を用います。例えば次の文:
+
<syntaxhighlight lang=pascal>
 
   Caption:='Left='+IntToStr(Left)+' Top='+IntToStr(Top);
 
   Caption:='Left='+IntToStr(Left)+' Top='+IntToStr(Top);
は次の文に置き換わります。
+
</syntaxhighlight>
 +
 
 +
will be replaced with
 +
 
 +
<syntaxhighlight lang=pascal>
 
   Caption:=Format(rsLeftTop, [IntToStr(Left), IntToStr(Top)]);
 
   Caption:=Format(rsLeftTop, [IntToStr(Left), IntToStr(Top)]);
そして新しいリソース文字列は
+
</syntaxhighlight>
 +
 
 +
and the new resourcestring will be
 +
 
 +
<syntaxhighlight lang=pascal>
 
   rsLeftTop = 'Left=%s Top=%s'       
 
   rsLeftTop = 'Left=%s Top=%s'       
となります。
+
</syntaxhighlight>
このFormat関数はSysUtilsユニットで定義されています。ユニットのuses節にまだSysUtilsが含まれていない場合は追加して下さい。
+
 
 +
The Format function is defined in the SysUtils unit. If your unit uses section does not already contain it, you must add it yourself.
 +
 
 +
 
 +
==See also==
 +
 
 +
* [[Getting translation strings right]]

Latest revision as of 02:30, 11 October 2021

Deutsch (de) English (en) français (fr) 日本語 (ja)

This wizard helps to convert a string constant into a resourcestring.

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.

A string constant is for example 'Some text'.

Conversion Options

Identifier prefix

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.

Identifier length

This is the maximum length of the automatically created identifier.

Custom identifier

Instead of using an automatically created identifier, you can specify the identifier on your own here.

Resourcestring section

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.

String with same value

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.

Where to put the new identifier in the resourcestring section

If a new identifier is created, this defines where it will be added in the resourcestring section.

  • Append to section - add the new identifier at the end of the section.
  • Insert alphabetically - insert the identifier alphabetically.
  • 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.

String constant in source

This shows the old or current source code.

Source preview

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.

Examples

Example 1: Setting the caption of a form

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:

 
  resourcestring
    rsSomeText = 'Some text';

Add in the FormCreate event the following line:

 
  Caption:='An example caption';

Place the cursor on the string constant, i.e. somewhere between the two '. Then do -> <Right click> Refactoring | Make Resource String

Set in the identifier prefix 'rs' without the '. The new automatically suggested identifier will be 'rsAnExampleCaption'. The preview shows

   Caption:=rsAnExampleCaption;
 --------------------------------------------------------------------------------
 rsAnExampleCaption = 'An example caption'   

Click ok.

Example 2 : Complex string constants

When converting a complex string expression with variables and functions, the tool will use the Format function. For instance the statement:

 
  Caption:='Left='+IntToStr(Left)+' Top='+IntToStr(Top);

will be replaced with

 
  Caption:=Format(rsLeftTop, [IntToStr(Left), IntToStr(Top)]);

and the new resourcestring will be

 
  rsLeftTop = 'Left=%s Top=%s'

The Format function is defined in the SysUtils unit. If your unit uses section does not already contain it, you must add it yourself.


See also