Difference between revisions of "Internationalisation programmation"
Line 20: | Line 20: | ||
=== Simple controls === | === Simple controls === | ||
− | For | + | For each control of [[Gestinux_util]], the translation is defined in the langauge file : |
The section is the Form name. | The section is the Form name. |
Revision as of 13:18, 6 March 2013
Why
The common method using resource strings is a little tedious to implement. It requires development environment and programming skills to make translations available.
That's why I have used another system, with some success on a large application.
Translation are read by the software from mere inifiles and applied when forms are loaded. This is quick enough.
This way, it is possible to define or modify translations directly when running the application, without developing tools and skills.
How it works ?
Language file
There is no need to recompile anything to add a new language, only one inifile by language must be provided.
More information can be found here.
Simple controls
For each control of Gestinux_util, the translation is defined in the langauge file :
The section is the Form name. The parameter name is the component name, followed by a dot and the property name to translate. The parameter value is the translation
If the file or the parameter is not found, the design properties are used.
E.g :
[FormConnection]
LabelUsername.Caption=Username
EditUsername.Hint=Enter your username
BtnOk.caption=Connect
BtnOk.Hint=Click here to connect
MenuItemQuit.Caption=Exit
GGrid and GDbGrid
For each column, indexed by its position, we can define the title. The Columns property must be defined to allow translations (and other features).
E.g :
Grid.Employees.Name.Title=Name
Grid.Employees.Address.Title=Address
Grid.Employees.City.Title=City
Messages
Messages are identified by keywords not used for control's translations. They are stored in the form section, along with other control's translations.
Parameters are allowed. Example :
UsernameConnectError=%1:s in not a valid username, retry.
MessageDlg and ShowMessage procedures must not be used, since they don't use the same translation system.
To display a translated message, use only one of these functions member of TGForm :
- ErrorMessage ( 'UsernameConnectError', [EditUsername.Text] );
- ConfirmationMessage ( 'UsernameConnectError', [EditUsername.Text] );
- InformationMessage ( 'UsernameConnectError', [EditUsername.Text] );
Or in some special cases
- DisplayMessage
Other strings
Other parameters can be present in the ini file, for special usages. Their translations can be queried at any time by :
TranslateText( Section, Key, Default );
How to make a translation
Use the translation utility, available for Linux and for Windows, which can read a reference language file, and fill another language file, detecting missing translations.