
Using multilanguage in Delphi without 3rd party plugins is actually quite simple. Here are the steps you can follow:
Step 1: Create a resource string file
Create a new text file and save it with a .res extension. This file will contain all the strings that you want to translate. Here’s an example:
STRINGTABLE
{
101, "Hello, World!"
102, "Goodbye, World!"
}
In this example, we have two strings: “Hello, World!” and “Goodbye, World!”. The numbers before each string (101 and 102) are the resource IDs. These IDs will be used later in the Delphi code to access the strings.
Step 2: Add the resource file to your project
In Delphi, go to Project > Add to Project > Resource file and select the .res file you just created.
Step 3: Add the TMultiLang component to your form
In the Delphi IDE, go to the Component Palette and find the TMultiLang component. Drag and drop it onto your form.
Step 4: Set the resource file and default language
Select the TMultiLang component on your form and go to the Object Inspector. Set the ResourceFile property to the name of your .res file (without the .res extension). For example, if your file is called “strings.res”, set ResourceFile to “strings”.
Next, set the DefaultLanguage property to the language you want to use as the default. For example, if you want to use English as the default language, set DefaultLanguage to “en”.
Step 5: Add the strings to your form
Select the TMultiLang component on your form and go to the Object Inspector. Click on the Strings property and add the resource IDs and their corresponding translations. For example:
101=Hello, World!
102=Goodbye, World!
Step 6: Access the strings in the code
To access the translated strings in code, use the TMultiLang.GetText method. For example:
Label1.Caption := MultiLang1.GetText(101);
This code will set the caption of Label1 to the translated string with the resource ID 101.
Here’s the full code for a simple Delphi form that uses multilanguage:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, MultiLang;
type
TForm1 = class(TForm)
MultiLang1: TMultiLang;
Label1: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.Caption := MultiLang1.GetText(101);
end;
end.
The .dfm file for this form should contain the TMultiLang component, and the Strings property should be set to the translations you want to use.
To use multilanguage pictures in Delphi using TMultiResBitmap, you can follow these steps:
Step 1: Create a resource file for each image
Create a separate resource file for each image you want to use. Each file should contain the same image in different sizes. For example, if you have an image called “logo.png”, you can create three resource files called “logo16.res”, “logo32.res”, and “logo64.res”. Each file should contain the same image, but resized to 16×16, 32×32, and 64×64 pixels respectively.
Step 2: Add the resource files to your project
In Delphi, go to Project > Add to Project > Resource file and select each of the .res files you created in Step 1.
Step 3: Add a TMultiResBitmap component to your form
In the Delphi IDE, go to the Component Palette and find the TMultiResBitmap component. Drag and drop it onto your form.
Step 4: Set the resource files for the TMultiResBitmap component
Select the TMultiResBitmap component on your form and go to the Object Inspector. Click on the Bitmaps property and add a new bitmap for each of the resource files you created in Step 1. For example:
Bitmaps = <
item
Name = 'Logo16'
ResourceName = 'logo16'
end
item
Name = 'Logo32'
ResourceName = 'logo32'
end
item
Name = 'Logo64'
ResourceName = 'logo64'
end>
Step 5: Add the images to your form
Select the TImage component on your form and go to the Object Inspector. Set the MultiResBitmap property to the TMultiResBitmap component you added in Step 3. Then, set the ImageIndex property to the index of the image you want to use. For example, to use the 32×32 version of the logo, set ImageIndex to 1 (since the first image has an index of 0).
Step 6: Access the images in code
To access the images in code, use the TMultiResBitmap.GetBitmap method. For example:
Image1.Picture.Bitmap := MultiResBitmap1.GetBitmap('Logo32');
This code will set the picture of Image1 to the 32×32 version of the logo.
Here’s the updated code for the Delphi form that uses multilanguage pictures with TMultiLang and TMultiResBitmap:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, MultiLang, MultiResBitmap, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
MultiLang1: TMultiLang;
MultiResBitmap1: TMultiResBitmap;
Image1: TImage;
Label1: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.Caption := MultiLang1.GetText(101);
Image1.Picture.Bitmap := MultiResBitmap1.GetBitmap('Logo32');
end;
end.
Happy Coding!!
Thank you for providing me with these article examples. May I ask you a question? http://www.hairstylesvip.com
Pretty component to content. I just stumbled upon your weblog and in accession capital to assert that I get
in fact enjoyed account your blog posts. Any way I’ll be subscribing
in your feeds or even I success you get right of entry to persistently
fast.
Also visit my webpage; nordvpn coupons inspiresensation (http://url.hys.cz/)
Have you ever thought about adding a little bit more than just your articles?
I mean, what you say is valuable and all.
But think about if you added some great visuals or videos to give your posts
more, “pop”! Your content is excellent but with images and clips,
this blog could undeniably be one of the most beneficial in its field.
Awesome blog!
Feel free to surf to my website: nordvpn coupons inspiresensation –
https://t.co –
I think the admin of this site is actually working hard for his website,
since here every data is quality based data.
Also visit my homepage … nordvpn coupons inspiresensation (in.mt)
I just could not go away your web site prior to suggesting that I extremely enjoyed the
standard info an individual supply on your guests?
Is going to be again frequently in order to check up on new
posts
Here is my web site – nordvpn coupons inspiresensation
nordvpn special coupon code 2025 350fairfax
For the reason that the admin of this web page is working, no doubt very quickly it will be well-known, due
to its quality contents.
Good write-up, I’m regular visitor of one’s site, maintain up the excellent operate, and It is going to be a regular visitor for a lengthy time.
My husband and i felt really lucky Emmanuel could deal with his inquiry by way of the precious recommendations he gained through your site. It’s not at all simplistic to just be freely giving helpful tips that many others could have been making money from. We really fully grasp we have you to be grateful to because of that. Those illustrations you have made, the straightforward web site menu, the friendships you can make it possible to create – it is most exceptional, and it’s assisting our son in addition to us imagine that the issue is brilliant, and that’s particularly indispensable. Thank you for all!
Your positive and uplifting words are like a ray of sunshine on a cloudy day Thank you for spreading light and positivity in the world
I have recommended this blog to all of my friends and family It’s rare to find such quality content these days!
This is a great read. Thanks for sharing your insights! And also please SignUp and get 30USD FREE investment plan at https://investurns.com/
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article. https://accounts.binance.com/bg/register?ref=V2H9AFPY
Thanks for sharing. I read many of your blog posts, cool, your blog is very good.
Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.