TLangSup is a Borland Object Pascal / Delphi class for internationalization / national language support.
The property Caption of a form and its subcomponents can be translated
'online', without the necessity of leaving the program. Data are stored
in a pipe '|' separated text file which you can easily give away for
Status: Freeware; modify and use it at your own risk. I'd be glad
if you left a comment in the source file about the original author, Joachim Pimiskern.
Download langsup1.0.zip (162kB)
TForm1 = class(TForm)
procedure TForm1.FormCreate(Sender: TObject);
language := TLangSup.Create('Deutsch');
language.LoadFromFile(ExtractFilePath(Application.Exename) + 'language.txt');
procedure TForm1.FormDestroy(Sender: TObject);
// Store the language file since the user
// may have changed the data.
language.SaveToFile(ExtractFilePath(Application.Exename) + 'language.txt');
procedure TForm1.ComboBox1Change(Sender: TObject);
The role of the context
TLangSup relies on the assumption that a combination of
language + context + text is unique in a project.
A context is simply a string, like language, and can be
set with the method setContext(...). It's a good idea
to set the context when a form is entered. But don't forget
to restore a prior context in the case you've one global
instance of TLangSup.
How to add a language
In the above example, when Combobox1 changes, the method SetCaptions()
is called. It tries to translate all Captions on all components.
If no translation can be found, '???' is returned. After the
language file has been saved, you can identify the unknown words
by a <<<word>>> embracement.
So adding a language is simply trying to translate a word
into this language.
Later, when nothing more is added to the language file, you can
retrieve all available languages with TLangSup.GetLanguages(...).
Adding translations from within a program
The form TFormAddLanguage (addlang.pas) allows the user to add
translations by himself. Here, an instance of this form class
is called after its public Language property is set to
self.language, the TLangSup component of the calling form.
procedure TForm1.ButtonLearnClick(Sender: TObject);
var FormAddLanguage: TFormAddLanguage;
FormAddLanguage := TFormAddLanguage.Create(nil);
FormAddLanguage.Language := self.language;