Board index » delphi » multi-language application

multi-language application

Hi!

I am making a multi-language application. Until now I have been creating
stringtable resources, compiling them and adding them to the code. But
now I would like the feature that it would be possible to change the
language file without recompiling the program.

I would make a text file with such entries:

Label1.Caption := 'Enter data';
Edit1.Text := 'name';
...

I don't know how to 'run' this text file in runtime so that the edit and
label fields would change their properties.

Any help is highly appreciated!

Thanks,

Miha.

 

Re:multi-language application


In comp.lang.pascal.delphi.misc, on 03 Jul 2002, Blank Page
announced:

Quote
> ...But now I would like the feature
> that it would be possible to change the language file
> without recompiling the program.

If you make your text file have just the text you wish to
display:

Enter data
name

then you could assign the appropriate string to label1.caption or
Edit1.text as required.  that way you can use 'Enter data'
*whenever* you need that phrase - even if you don't need it more
than once *now* it allows you to expand further later.  It also
means that you don't run into trouble if you rename label1 for
instance.  Or if you did something like:

ENTER: Enter Data
NAME: Name
PROCESS: Process request

then you could read in the first word, or up to the ':' or
however you format the file - that is the 'name' of the phrase
and the rest of the line is the 'phrase' which will be different
in different languages.  That way if you change the phrases
around or sort the file in a different way then you will still
have the 'meaning' of each line and you can search for the
approprate string 'ENTER' for instance to use as needed - that
would make the program a bit slower, possibly just to startup.  
It depends on what you are doing and how big your file will be as
to if that is worthwhile in terms of time taken and ease of
use...

That's just my (quick and inexperienced) thoughts as to what you
might do.

Regards

OgO
--
My Freeware: http://qjc.cjb.net/freeware.html
My Win9x Cursors: http://qjc.cjb.net/cursors.html
ICQ: 12889482 - AIM/Yahoo: quentisl - MSN: quent...@mail.com
I left my Glasses in my email - you better take them out!

Re:multi-language application


You can use my freeware TSMLanguage component
http://www.scalabium.com/smcmtbl.htm

See short instruction for this component:
*****************************************************
So how to use SMLanguage.

there everything is clear and I'll give a step-by-step instructions:
1. just drop a component on form (wich you want to localize and which
contain some your other components, of course).
2. after that define the ResourceFile property - it's a name of file which
will store all strings. For example, c:\myapp.lng
3. select this TSMLanguage component in design-time
4. press a right mouse button and from popup menu select the "Generate
properties List". In this moment will be filled the SMLanguage.Properties
property - this is a list of properties which you want to localize
When a list is generated, you can edit it as you want - to remove some
propeties or add.
5. when Properties is defined, select the "Generate language file" item from
popup menu
6. automatically will be created a file (see ResourceFile property above)
with parsed strings from your components
7. this file is a usual ini-file with strings. Just translate any string
there on same language (french or german, for example)
8. after that in run-time when you want to change a language (from main
menu, for example), just call SMLanguage.LoadResources method with file name
as parameter and automatically all translated strings will be loaded.

No any additional programming for you.

Also in this lng-file you can store some your custom messages (automatically
will be parsed properties of components only). If you need it, just create
the "[Custom]"-section in your lng-file and use
SMLanguage.TranslateUserMessage method which will return the loaded string.

Sample of file
**********************
[Translations]
Form1.Caption = Form1=Form1.Caption = Form1
Form1.Label1.Caption = Label1=Form1.Label1.Caption = WEB
Form1.Label1.Hint ==Form1.Label1.Hint = Click on label to view a site online
Form1.Button1.Caption = Button1=Form1.Button1.Caption = View
Form1.Button1.Hint ==Form1.Button1.Hint =Navigate to url

[Custom]
strWarning = Are you sure that you want to ovverride a file?
strOpen = Select a full file name
**********************
*****************************************************

Of course, this component is not good for large applications but from other
hand it could be useful for small and middle systems. You'll deploy your
exe-file with a few lng-files and your user can select desired on-fly. Just
as a simple plug-in...

--
With best regards, Mike Shkolnik
E-Mail: mshkol...@scalabium.com
WEB: http://www.scalabium.com

Blank Page <nos...@nospam.com> ??? a
????:3D22CAED.6040...@nospam.com...

Quote
> Hi!

> I am making a multi-language application. Until now I have been creating
> stringtable resources, compiling them and adding them to the code. But
> now I would like the feature that it would be possible to change the
> language file without recompiling the program.

> I would make a text file with such entries:

> Label1.Caption := 'Enter data';
> Edit1.Text := 'name';
> ...

> I don't know how to 'run' this text file in runtime so that the edit and
> label fields would change their properties.

> Any help is highly appreciated!

> Thanks,

> Miha.

Other Threads