psabourin
asked on
Multilingual Application written in Delphi
I am currently writing an application in Delphi 3. I would like to make the application multilingual. The app contains several forms (and more forms to be added in the future). What is the common method of making a multilingual application? For Example: the menu item Exit <-- English
Quitter <-- French and Quitos <-- Spanish (Please note that the spanish text was simply for demonstration purposes!).
Also, note that in the future, more languages would be supported.
Thanks
Quitter <-- French and Quitos <-- Spanish (Please note that the spanish text was simply for demonstration purposes!).
Also, note that in the future, more languages would be supported.
Thanks
It usually is done by the resource file....Save the strings you'd need and then check the lanugage.....
Check this out....Here is an example....
let's say you want to support two languages...(English, Spanish)
-----English.RC--------
STRINGTABLE
BEGIN
1, "Hello"
2, "String Table"
11, "First message"
12, "Second message"
13, "Third message"
14, "Fourth message"
15, "Fifth message"
16, "Sixth message"
17, "Seventh message"
18, "Eighth message"
19, "Ninth message"
20, "Tenth message"
END
-------Spanish.RC---------
STRINGTABLE
BEGIN
1, "Ciao"
2, "Tabella Stringhe"
11, "Primo messaggio"
12, "Secondo messaggio"
13, "Terzo messaggio"
14, "Quarto messaggio"
15, "Quinto messaggio"
16, "Sesto messaggio"
17, "Settimo messaggio"
18, "Ottavo messaggio"
19, "Nono messaggio"
20, "Decimo messaggio"
END
----------Pas file(The code) to join it---------
unit StringF;
interface
uses
SysUtils, Windows, Messages, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls, Spin, ExtCtrls;
type
TForm1 = class(TForm)
ShowButton: TButton;
SpinEdit1: TSpinEdit;
Label1: TLabel;
HelloButton: TButton;
Bevel1: TBevel;
Bevel2: TBevel;
procedure HelloButtonClick(Sender: TObject);
procedure ShowButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
//The check for the languages follows.....
{$IFNDEF ITALIAN}
{$R STABLE.RES}
{$ELSE}
{$R STABLEIT.RES}
{$ENDIF}
procedure TForm1.HelloButtonClick(Se nder: TObject);
var
StrMsg: string;
begin
StrMsg := LoadStr (1);
if StrMsg <> '' then
ShowMessage (StrMsg);
end;
procedure TForm1.ShowButtonClick(Sen der: TObject);
var
StrMsg: string;
begin
StrMsg := LoadStr (10 + SpinEdit1.Value);
if StrMsg <> '' then
ShowMessage (StrMsg);
end;
procedure TForm1.FormCreate(Sender: TObject);
var
StrTitle: string;
begin
StrTitle := LoadStr (2);
if StrTitle <> '' then
begin
Caption := StrTitle;
Application.Title := StrTitle;
end;
end;
end.
------------
That's all........
YOu can create all the strings and stuff in the same RC file.....for example.......
-----The RC(This example is shows the English & Bulgarian languages)------
STRINGTABLE
BEGIN
1, "One"
2, "Two"
3, "Three"
4, "Four"
//Continue up to 9
10, "Ten"
//Here start the Bulgarian...The # continues though....1..10, and now 11..20
11, "Edno"
12, "Dve"
13, "Tri"
14, "Chetiri"
//Continue up to 19
20, "Deset"
END
------And when you load it use something similar to this--------
unit StringF;
interface
uses
SysUtils, Windows, Messages, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls, Spin, ExtCtrls;
type
TForm1 = class(TForm)
ShowButton: TButton;
SpinEdit1: TSpinEdit;
Label1: TLabel;
HelloButton: TButton;
Bevel1: TBevel;
Bevel2: TBevel;
procedure HelloButtonClick(Sender: TObject);
procedure ShowButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
Bulgarian : Boolean;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{$R STABLE.RES}
//The check for the languages follows.....
{$IFNDEF BULGARIAN}
Bulgarian := False;
{$ELSE}
Bulgarian := True;
{$ENDIF}
procedure TForm1.HelloButtonClick(Se nder: TObject);
var
StrMsg: string;
begin
if not Bulgarian then
StrMsg := LoadStr (1)
else
StrMsg := LoadStr (11);
if StrMsg <> '' then
ShowMessage (StrMsg);
end;
procedure TForm1.FormCreate(Sender: TObject);
var
StrTitle: string;
begin
if Bulgarian then
StrTitle := LoadStr (2)
else StrTitle := LoadStr(12);
if StrTitle <> '' then
begin
Caption := StrTitle;
Application.Title := StrTitle;
end;
end;
end.
------------
Hope this helps....
Check this out....Here is an example....
let's say you want to support two languages...(English, Spanish)
-----English.RC--------
STRINGTABLE
BEGIN
1, "Hello"
2, "String Table"
11, "First message"
12, "Second message"
13, "Third message"
14, "Fourth message"
15, "Fifth message"
16, "Sixth message"
17, "Seventh message"
18, "Eighth message"
19, "Ninth message"
20, "Tenth message"
END
-------Spanish.RC---------
STRINGTABLE
BEGIN
1, "Ciao"
2, "Tabella Stringhe"
11, "Primo messaggio"
12, "Secondo messaggio"
13, "Terzo messaggio"
14, "Quarto messaggio"
15, "Quinto messaggio"
16, "Sesto messaggio"
17, "Settimo messaggio"
18, "Ottavo messaggio"
19, "Nono messaggio"
20, "Decimo messaggio"
END
----------Pas file(The code) to join it---------
unit StringF;
interface
uses
SysUtils, Windows, Messages, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls, Spin, ExtCtrls;
type
TForm1 = class(TForm)
ShowButton: TButton;
SpinEdit1: TSpinEdit;
Label1: TLabel;
HelloButton: TButton;
Bevel1: TBevel;
Bevel2: TBevel;
procedure HelloButtonClick(Sender: TObject);
procedure ShowButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
//The check for the languages follows.....
{$IFNDEF ITALIAN}
{$R STABLE.RES}
{$ELSE}
{$R STABLEIT.RES}
{$ENDIF}
procedure TForm1.HelloButtonClick(Se
var
StrMsg: string;
begin
StrMsg := LoadStr (1);
if StrMsg <> '' then
ShowMessage (StrMsg);
end;
procedure TForm1.ShowButtonClick(Sen
var
StrMsg: string;
begin
StrMsg := LoadStr (10 + SpinEdit1.Value);
if StrMsg <> '' then
ShowMessage (StrMsg);
end;
procedure TForm1.FormCreate(Sender: TObject);
var
StrTitle: string;
begin
StrTitle := LoadStr (2);
if StrTitle <> '' then
begin
Caption := StrTitle;
Application.Title := StrTitle;
end;
end;
end.
------------
That's all........
YOu can create all the strings and stuff in the same RC file.....for example.......
-----The RC(This example is shows the English & Bulgarian languages)------
STRINGTABLE
BEGIN
1, "One"
2, "Two"
3, "Three"
4, "Four"
//Continue up to 9
10, "Ten"
//Here start the Bulgarian...The # continues though....1..10, and now 11..20
11, "Edno"
12, "Dve"
13, "Tri"
14, "Chetiri"
//Continue up to 19
20, "Deset"
END
------And when you load it use something similar to this--------
unit StringF;
interface
uses
SysUtils, Windows, Messages, Classes, Graphics,
Controls, Forms, Dialogs, StdCtrls, Spin, ExtCtrls;
type
TForm1 = class(TForm)
ShowButton: TButton;
SpinEdit1: TSpinEdit;
Label1: TLabel;
HelloButton: TButton;
Bevel1: TBevel;
Bevel2: TBevel;
procedure HelloButtonClick(Sender: TObject);
procedure ShowButtonClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
Bulgarian : Boolean;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
{$R STABLE.RES}
//The check for the languages follows.....
{$IFNDEF BULGARIAN}
Bulgarian := False;
{$ELSE}
Bulgarian := True;
{$ENDIF}
procedure TForm1.HelloButtonClick(Se
var
StrMsg: string;
begin
if not Bulgarian then
StrMsg := LoadStr (1)
else
StrMsg := LoadStr (11);
if StrMsg <> '' then
ShowMessage (StrMsg);
end;
procedure TForm1.FormCreate(Sender: TObject);
var
StrTitle: string;
begin
if Bulgarian then
StrTitle := LoadStr (2)
else StrTitle := LoadStr(12);
if StrTitle <> '' then
begin
Caption := StrTitle;
Application.Title := StrTitle;
end;
end;
end.
------------
Hope this helps....
Hmmm yes, that is it....
(a bit more complete than my answer)
*cough*
Tim.
(a bit more complete than my answer)
*cough*
Tim.
*grin*
Can we give Viktonet the points for all his extra work, and his better knowledge of languages?
Yours, in English only,
Tim.
Can we give Viktonet the points for all his extra work, and his better knowledge of languages?
Yours, in English only,
Tim.
Thanks Tim
ASKER
In the line: {$ifndef italian} Where does italian come from? Is this from Windows or an INI file of my program? Right now, my program has a line like this in the INI file:
[Culture]
Language = 1
where 0 = English, 1 = French and 2 = Spanish.
Thanks
[Culture]
Language = 1
where 0 = English, 1 = French and 2 = Spanish.
Thanks
Try this example......
You don't need to save the values in an INI files.... Windows has got the values of all langauges that are regsitered to your windows...
var
{$IFDEF ITALIAN}
Italian : Boolean = True;
{$ELSE}
Italian : Boolean = False;
{$ENDIF}
procedure TForm1.Button1Click(Sender : TObject);
begin
If Italian then
ShowMessage('We speak Italian language')
else
ShowMessage('We speak English language');
end;
Also try this,,,,,
Type in Windows. and when the list shows just type something like LANG_ or SUBLANG_ and you will see the names of some of the registered languages to your windows..
Regards,
Viktor Ivanov
You don't need to save the values in an INI files.... Windows has got the values of all langauges that are regsitered to your windows...
var
{$IFDEF ITALIAN}
Italian : Boolean = True;
{$ELSE}
Italian : Boolean = False;
{$ENDIF}
procedure TForm1.Button1Click(Sender
begin
If Italian then
ShowMessage('We speak Italian language')
else
ShowMessage('We speak English language');
end;
Also try this,,,,,
Type in Windows. and when the list shows just type something like LANG_ or SUBLANG_ and you will see the names of some of the registered languages to your windows..
Regards,
Viktor Ivanov
Hello psabourin
planning to accept mine or Tim's answer???
//Vik
planning to accept mine or Tim's answer???
//Vik
heh heh heh...
Tim.
Tim.
heh heh heh...
Vik.
Vik.
ASKER
Sorry, I was away from my computer for a while... I am planning on accepting Vik's answer. How do I grade Vik's answer. Right now it is only letting me accept Tim's?
Thanks
Thanks
Hey..
In order to accept my answer you need to reject Tim's answer and then I'd answer the question so you can grade it....
In order to accept my answer you need to reject Tim's answer and then I'd answer the question so you can grade it....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
{$IFDEF ENGLISH}
{$R ENGSTR.RES}
{$ENDIF}
{$IFDEF SPANISH}
{$R SPASTR.RES}
{$ENDIF}
.etc...
So long as all of the strings have the same resurce ID number, then it is just a case of copying each string to its related resource at run time...
Dont forget however, that if you wish to add languages such as Kanji (Japanese), then any character level string parsing that you perform (where you increment a pChar), must use the CharNext (or AnsiNext for 16 bit) functions as defined in the Windows API, as some characters are 2 bytes long...
Hope this is the answer you were looking for...
Tim.
PS: Alas, Delphi does not include a resource editor, so you will have to use one that is included with another application such as BP7 for 16 bit, or MSDEV4 for 32 bit...