Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inno setup i18n for custom panel

I made a custom panel for Inno-Setup and i want internationalization for this.

Can i use the *.isl files to add my translation keys or must i use the [custommessages]? And how can i access the keys in the [code] section.

Non of the inno-setup examples using the i18n.

thx Tom

like image 816
tomkpunkt Avatar asked Jul 11 '13 07:07

tomkpunkt


2 Answers

1. Can I modify the isl localization files ?

It's upon you, if you modify standard *.isl files, or create your own modified ones. For sure keep in mind, that if you modify the standard ones, they might get updated by a new version of Inno Setup you install. That might be the reason why many people suggests to only create entries in the [CustomMessages] section.

But you can of course create a separate language file which you'll merge with each Inno Setup update, or even better, like Miral suggests, specify your custom messages in your own *.isl file, and then in the MessagesFile parameter of the [Languages] section specify that file at the end of the comma separated list of files:

[Languages]
Name: "en"; MessagesFile: "compiler:Default.isl,compiler:YourEnMessages.isl"
Name: "nl"; MessagesFile: "compiler:Languages\Dutch.isl,compiler:YourNlMessages.isl"

As the reference states for the MessagesFile parameter:

When multiple files are specified, they are read in the order they are specified, thus the last message file overrides any messages in previous files.

So if you make only *.isl file(s) with only [CustomMessages] section and specify them in the script the above way, you won't break anything and you'll get the separate reusable language file(s). Structure of such custom *.isl file might look eaxctly like the [CustomMessages] section:

[CustomMessages]
SomeCustomKey=Some custom value
...

Making your own language files might be better for you if you're going to reuse those custom messages in many setups.

2. How can I access custom messages from the [Code] section ?

By using CustomMessage function. For instance this way:

...

[CustomMessages]
; the following key value pair can be moved to the *.isl file into the same
; named file section, if needed; as a downside of doing that you'll need to
; keep track of changes if you update Inno Setup itself
SomeCustomKey=Some custom value

[Code]
procedure InitializeWizard;
var
  S: string;
begin
  S := CustomMessage('SomeCustomKey');
  MsgBox(S, mbInformation, MB_OK);
end;
like image 82
TLama Avatar answered Nov 15 '22 05:11

TLama


Answer provided by @TLama is really usefull. I faced with an additional problem, which was related to use custom messages with params.

To define custom messages:

Messages may take arguments, from %1 up to %9. You can rearrange the order of the arguments (i.e. move the %2 before a %1) and also duplicate arguments if needed (i.e. "%1 ... %1 %2"). On messages with arguments, use two consecutive "%" characters to embed a single "%". "%n" creates a line break.

For example:

[CustomMessages]
...
NameAndVersion=%1 version %2
...

And then, to use it in code section, simply use FmtMessage function together with CustomMessage function:

Example:

S := FmtMessage(CustomMessage('NameAndVersion'), ['My Program', '1.0']);
// S = 'My Program version 1.0'
like image 29
Richard P. Avatar answered Nov 15 '22 05:11

Richard P.