Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Translating to antoher language... 1

Status
Not open for further replies.

Tilen

Programmer
Apr 2, 2005
75
SI
Hi

I need to translate my program into another language.
And I have decided to do it like this:

I have a file lang.txt which is structred as first line English text and second line is another language:

Options
Opicions

This works OK.

First I started with function that searches for string and returns string from next line:

Label1.Caption:=GetTranslation('Options');

Now I would like to change this to a procedure where I would pass a control and it procedure would change it's 'Caption' property. Something like:

TranslateControl(Label1);

and procedure would be:

procedure TranslateControl(Control:TObject);
begin
TObject(Control).Caption:=GetTranslation(TObject(Control).Caption);

end;

This doesn't work...

Any suggestions how can I do this?

There are Labels, Buttons and CheckBoxes to translate, so they all have Caption property.

I could use

TButton(Control).Caption:=GetTranslation(TButton(Control).Caption);
or
TLable(Control).Caption:=GetTranslation(TLabel(Control).Caption);

But how can I identify what kind of control is it?

thanx


end;
 
instead of TObject, use TControl, like this :

procedure TranslateControl(Control:TControl);


-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Thanx

this works now:


If (Sender is TButton) then
_Caption:=TButton(Sender).Caption
Else
If (Sender is TLabel) then
_Caption:=TLabel(Sender).Caption;

for i:=0 to LangTransText.Count-1 do
If LangTransText=_Caption then
Begin
Translated_Text:=LangTransText[i+1];
Break;
End;

If (Sender is TButton) Then
TButton(Sender).Caption:=Translated_Text
Else
If (Sender is TLabel) Then
TLabel(Sender).Caption:=Translated_Text;
 
What about the Language facility In Delphi, The GUI allows different versions of your project 'forms' and 'controls' with the text in different languages. There is an editor to allow you to enter the language texts, for each different version of your controls.
It does mean that you end up with separate executables for each language but is that a problem?
I have only played around with this myself maybe other members have (bad?) experience of it?


Steve: Delphi a feersum engin indeed.
 
I didn't try it, since my ystem works OK, so far.
I will see at the end of the day, but for now it works.

My system allows language changes while running program, I guess with two separate executables this is not an option.

And if original translator makes a mistake, users need to wait for me to change and release updated software, while in my case, they just change included file and there it is.

I'm sure it must have its advantages, but I want to have it as easy as possible to use and maintain.


 
normally you create a resource dll for this task.

one dll for each language, load the appropriate dll for the selected langauge and do a dynamic rescource lookup for the captions.

here's a quick hack to set the caption of ANY control :

Code:
type TCaptionControl = class(TControl)
     published
      property Caption;
     end;

implementation

...

procedure setcaption(Control : TControl);
begin
 TCaptionControl(Control).Caption:='test';
end;

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
But I assume you would want to translate more than just a Caption property?, as Comboboxes have Items and Text, Edit boxes with predefined values have a Text property, MenuItems and Panels are even a little more difficult :-( Then most also have a Hint propery of some kind you would also translated as well... The crappy translation of Delphi itself I never even considered as an option because of (as said) the crappy way it 'needs' to work. A resource-DLL solution would definately hinder a home-made translation into a local dialect, such as f.e. Basque :-? but could be a good solution for a commercial or closed translation.
Once, years ago a found a component on some freeware site. I'm not sure anymore but Torry.net should have it I assume. I modified it to enable support for JRSoftware's ToolBar'97, and some other controls I used to use often, as they didn't react properly on TControl(SomeControl).Caption (etc.) I can't make this available, as I don't know the original state of the sourcefiles, _and_ it was partly (most) developed during work-time, and the employer doesn't allow for (free) distribution.
Other similar components are readily available (and free) on Torry, so have fun!

HTH
TonHu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top