Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2007-09

Resourcestring questions

2 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Adriaan van Os

FPCs resourcestring feature is a great way to localize applications, yet I have the following questions.

1. The tutorial at
<http://wiki.lazarus.freepascal.org/Translations_/_i18n_/_localizations_for_programs> gives the following example

  resourcestring
    Caption1 = 'Some text';
    HelloWorld1 = 'Hello World';
  Label1.Caption := HelloWorld1;

Wouldn't it be simpler if resourcestrings could be defined and used directly by the form ? That would save a lot of code of the form Labelxx.Caption := yyy. Of course, this implies a "reload form strings" method to reload form strings when the current language changes.

(my apologies if this is a Lazarus question, it seems related to the compiler also)

2. Previously, when using a "GetStringFromResource" routine, I could write something like

	for n:=1 to 100 do ComboAdd( GetStringFromResource( kComboItemOffs + n))

This doesn't seem to be possible with resourcestring lists, because they use string constants, rather then numbers. Unless, of course, we extend the compiler to optionally attach a number or a number-constant to resourcestring entries rather than a string constant. Plus a standard function that converts the number into a string. This facilitates converting current applications (that still use resource IDs) also. Any comments ?

Regards,

Adriaan van Os

Michael Van Canneyt
to Adriaan van Os
Adriaan van Os wrote 20 lines
FPCs resourcestring feature is a great way to localize applications, yet I have the following questions. 1. The tutorial at <http://wiki.lazarus.freepascal.org/Translations_/_i18n_/_localizations_for_programs> gives the following example resourcestring Caption1 = 'Some text'; HelloWorld1 = 'Hello World'; Label1.Caption := HelloWorld1; Wouldn't it be simpler if resourcestrings could be defined and used directly by the form ? That would save a lot of code of the form Labelxx.Caption := yyy. Of course, this implies a "reload form strings" method to reload form strings when the current language changes. (my apologies if this is a Lazarus question, it seems related to the compiler also)

There is a hook for this, but the question is how to identify the string you need.

Show quoted text 13 lines
2. Previously, when using a "GetStringFromResource" routine, I could write something like for n:=1 to 100 do ComboAdd( GetStringFromResource( kComboItemOffs + n)) This doesn't seem to be possible with resourcestring lists, because they use string constants, rather then numbers. Unless, of course, we extend the compiler to optionally attach a number or a number-constant to resourcestring entries rather than a string constant. Plus a standard function that converts the number into a string. This facilitates converting current applications (that still use resource IDs) also. Any comments ?

No applications use resource ID's at the moment.

Changing this is not so easy; Allocating a resource ID per string is not an easy algorithm, since you don't know in advance which strings will be included in your application, and which ones are not.

Michael.