Connection Manager

CnxManager

SourceForge.net Logo

dxgettext helpers


This set of files is to be used in conjunction with the excellent dxgettext and simplifies the developer's life when creating multilangual applications.

Overview

File
Defines
Comment
GTForm.pas
TGTForm = class(TForm)
This new TForm descendent introduces the RefreshTranslation procedure. When called, this procedure forces the given form (and the components it owns) to refresh itself with the strings for the currently selected language.
This is used by TGTLanguageFrame and thus you should change all your translatable forms to inherit from TGTForm rather than TForm. To do this, simply open the .pas file and replace = class(TForm) by = class(TGTForm), then recompile and everything should work.
GTLanguagesEx.pas
TLanguagesEx = class(TLanguages)
GetInstalledLanguages()

An extension of the TLanguages class (bundled with Delphi) which allows to convert LangIds to ISO names and vice-versa.
The GetInstalledLanguages() function fills a TStrings with the list of installed languages in the given folder.
This is based on code by Peter Thörnqvist.
GTLanguageList.pas
TGTLanguageList = class
The list of currently available languages. This list is used by TGTLanguageFrame to fill its combo box
GTLanguageFrame.pas
GTLanguageFrame.dfm
TGTLanguageFrame = class(TFrame)
A frame that you can drop on any form and that will let your user choose its language. All updating is done, provided all the forms are descendants of TGTForm.
Basically, you only need to use this one as it will call the others for you.
languages.po
template for the translation of languages
This is taken directly from Lars' web site as his list is far more complete.

The download links will give you access to the latest CVS version, in plain text format. If you want to download these files, right-click on the link or hold the Shift key while clicking on the link.

Note:
Lars has release a beta version of dxgettext, labeled 1.2 beta 3. This is the version these source files use because the beta seems to be fairly stable.

TGTForm

This new TForm descendent introduces the RefreshTranslation procedure. When called, this procedure forces the given form (and the components it owns) to refresh itself with the strings for the currently selected language. If you want a form in your application to be automatically translated when the selected language changes in the TGTLanguageFrame combobox, you must make it inherit from TGTForm rather than TForm. Everything else will be done automatically provided you use the language frame.

Ancestor
TForm
Properties
none
Methods
procedure RefreshTranslation
Forces the form to refresh its content to reflect the currently selected language. Will also refresh the strings of all the components it contains
constructor Create
Creates the required objects to perform automatic translation
destructor Destroy
Destroys the objects created by Create
Events
none

TLanguagesEx

An extension of the TLanguages class (bundled with Delphi) which allows to convert LangIds to ISO names and vice-versa.

Ancestor
TLanguages
Properties
IDFromFromISO639Name[const ISO639Name:string]:LCID
Returns the LCID associated with the given ISO639 name (2 letter language abreviation) or 0 if the name was not found by the system.
ISO639NameFromID[ID:LCID]:string
Returns the ISO639 name (2 letter language abreviation) associated with the given LCID or an empty string if the LCID was not found by the system.
IDFromFromISO3166Name[const ISO3166Name:string]:LCID
Returns the LCID associated with the given ISO3166 name (2 letter country abreviation) or 0 if the name was not found by the system.
ISO3166NameFromID[ID:LCID]:string
Returns the ISO3166 name (2 letter country abreviation) associated with the given LCID or an empty string if the LCID was not found by the system.
GNUGetTextName[ID:LCID]:string
Returns the name associated with this LCID as GNU gettext would expect it (fr_FR for instance)
GNUGetTextID[const Name:string]:LCID
Returns the LCID associated with this name, in GNU gettext format (fr_FR for instance)
Methods
constructor Create
Creates the required objects for the class
destructor Destroy
Destroys the objects created by Create
Events
none

GetInstalledLanguages

This method looks in the given folder for a locale subfolder and then enumerates all the availables languages in it. For a language to be considered available, it must propose the indicated domain.

Declaration
procedure GetInstalledLanguages(const BasePath,TextDomain:string;Strings:TStrings)
Parameters
BasePath
The path where to look for the locale subfolder. Usually set to ExtractFilePath(Application.ExeName)
TextDomain
The name of the domain required for a language to be considered as installed. If set to an empty string, any domain will be enough.
Strings
The String list that will be filled with the available languages. Must be created before the call.
The strings will contain the readable description of the available language as given by the system and the associated object will be the associated LCID.


TGTLanguageList

This class is the list that will be used by TGTLanguageFrame to update its content

Ancestor
TObject
Properties
Code[const name : string] : string
Returns the GNU gettext code associated with that language name (in human readable format).
If Installed is true, the name must be the one returned by the user's operating system. This means it must be localized to the OS language, not the selected language.
Codes : TStringList
Returns the list of language codes loaded in the list.
InstalledOnly : boolean
If true, the language list only contains the installed languages plus English (en) if it is not available on its own.
If false, the language list will contain a subset of all the available languages on Earth. The subset is currently set to :
Danish
da
German
de
English
en
Spanish
es
French
fr
Italian
it
Dutch
nl
Norwegian
no
Russian
ru
Swedish
sv
Name[const code : string] : string
Returns the human readable name associated with that GNU gettext code.
If Installed is true, the name will be the one returned by the user's operating system. This means it will be localized to the OS language, not the selected language.
Names : TStringList
Returns the list of language names loaded in the list.
Methods
constructor Create
Creates the required objects for the class
destructor Destroy
Destroys the objects created by Create
procedure LoadLanguages
Loads the languages, either from the list of installed languages for the application or using the default set of languages, depending on the value of InstalledOnly
Events
none

Notes:
The list of installed languages is read using DefaultInstance.GetListOfLanguages and will include embedded translations

TGTLanguageFrame

Ancestor
TFrame
Properties
Name
Returns the human readable name of the language selected in the combo box.
Code
Returns the GNU gettext code of the language selected in the combo box.
InstalledOnly (published)
If true, only the installed languages will be displayed.
If false, a subset of the worldwide available languages will be displayed. See TGTLanguageList for details
Methods
constructor Create
Updates the content of the combobox
Events
TOnGTBeforeLanguageChange = procedure (Sender : TObject; Code : string) of object;
OnGTBeforeLanguageChange : TOnGTBeforeLanguageChange
(published)
This event is triggered whenever the user has changed the currently selected language but before it is actually made the active language in the program. You may want to use this event to save the item indexes of comboboxes and lists as they will be reverted back to -1 as a result of the update process.
Note that this saving and restoration part could also be done more efficiently in an overriden RefreshTranslation() procedure of your forms. Store before calling inherited, restore after.
TOnGTLanguageChanged = procedure (Sender : TObject; Code : string) of object;
OnGTLanguageChanged : TOnGTLanguageChanged
(published)
This event is triggered whenever the user has changed the currently selected language. You may want to use this event to reaffect the item indexes of comboboxes and lists as they will be reverted back to -1 as a result of the update process.
Note that this saving and restoration part could also be done more efficiently in the RefreshTranslation() overriden procedure of your forms. Store before calling inherited, restore after.